]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.7.7-201302112308.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.7.7-201302112308.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 39f170a..5d22cce 100644
255 --- a/Makefile
256 +++ b/Makefile
257 @@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
258
259 HOSTCC = gcc
260 HOSTCXX = g++
261 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
262 -HOSTCXXFLAGS = -O2
263 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
264 +HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
265 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
266
267 # Decide whether to build built-in, modular, or both.
268 # Normally, just do built-in.
269 @@ -414,8 +415,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
270 # Rules shared between *config targets and build targets
271
272 # Basic helpers built in scripts/
273 -PHONY += scripts_basic
274 -scripts_basic:
275 +PHONY += scripts_basic gcc-plugins
276 +scripts_basic: gcc-plugins
277 $(Q)$(MAKE) $(build)=scripts/basic
278 $(Q)rm -f .tmp_quiet_recordmcount
279
280 @@ -575,6 +576,60 @@ else
281 KBUILD_CFLAGS += -O2
282 endif
283
284 +ifndef DISABLE_PAX_PLUGINS
285 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
286 +ifneq ($(PLUGINCC),)
287 +ifndef DISABLE_PAX_CONSTIFY_PLUGIN
288 +ifndef CONFIG_UML
289 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
290 +endif
291 +endif
292 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
293 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
294 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
295 +endif
296 +ifdef CONFIG_KALLOCSTAT_PLUGIN
297 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
298 +endif
299 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
300 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
301 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
302 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
303 +endif
304 +ifdef CONFIG_CHECKER_PLUGIN
305 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
306 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
307 +endif
308 +endif
309 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
310 +ifdef CONFIG_PAX_SIZE_OVERFLOW
311 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
312 +endif
313 +ifdef CONFIG_PAX_LATENT_ENTROPY
314 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
315 +endif
316 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
317 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
318 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS)
319 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
320 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
321 +ifeq ($(KBUILD_EXTMOD),)
322 +gcc-plugins:
323 + $(Q)$(MAKE) $(build)=tools/gcc
324 +else
325 +gcc-plugins: ;
326 +endif
327 +else
328 +gcc-plugins:
329 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
330 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
331 +else
332 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
333 +endif
334 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
335 +endif
336 +endif
337 +
338 include $(srctree)/arch/$(SRCARCH)/Makefile
339
340 ifdef CONFIG_READABLE_ASM
341 @@ -731,7 +786,7 @@ export mod_sign_cmd
342
343
344 ifeq ($(KBUILD_EXTMOD),)
345 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
346 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
347
348 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
349 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
350 @@ -778,6 +833,8 @@ endif
351
352 # The actual objects are generated when descending,
353 # make sure no implicit rule kicks in
354 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
355 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
356 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
357
358 # Handle descending into subdirectories listed in $(vmlinux-dirs)
359 @@ -787,7 +844,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
360 # Error messages still appears in the original language
361
362 PHONY += $(vmlinux-dirs)
363 -$(vmlinux-dirs): prepare scripts
364 +$(vmlinux-dirs): gcc-plugins prepare scripts
365 $(Q)$(MAKE) $(build)=$@
366
367 # Store (new) KERNELRELASE string in include/config/kernel.release
368 @@ -831,6 +888,7 @@ prepare0: archprepare FORCE
369 $(Q)$(MAKE) $(build)=.
370
371 # All the preparing..
372 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
373 prepare: prepare0
374
375 # Generate some files
376 @@ -938,6 +996,8 @@ all: modules
377 # using awk while concatenating to the final file.
378
379 PHONY += modules
380 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
381 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
382 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
383 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
384 @$(kecho) ' Building modules, stage 2.';
385 @@ -953,7 +1013,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
386
387 # Target to prepare building external modules
388 PHONY += modules_prepare
389 -modules_prepare: prepare scripts
390 +modules_prepare: gcc-plugins prepare scripts
391
392 # Target to install modules
393 PHONY += modules_install
394 @@ -1013,7 +1073,7 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
395 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
396 signing_key.priv signing_key.x509 x509.genkey \
397 extra_certificates signing_key.x509.keyid \
398 - signing_key.x509.signer
399 + signing_key.x509.signer tools/gcc/size_overflow_hash.h
400
401 # clean - Delete most, but leave enough to build external modules
402 #
403 @@ -1053,6 +1113,7 @@ distclean: mrproper
404 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
405 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
406 -o -name '.*.rej' \
407 + -o -name '.*.rej' -o -name '*.so' \
408 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
409 -type f -print | xargs rm -f
410
411 @@ -1213,6 +1274,8 @@ PHONY += $(module-dirs) modules
412 $(module-dirs): crmodverdir $(objtree)/Module.symvers
413 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
414
415 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
416 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
417 modules: $(module-dirs)
418 @$(kecho) ' Building modules, stage 2.';
419 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
420 @@ -1349,17 +1412,21 @@ else
421 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
422 endif
423
424 -%.s: %.c prepare scripts FORCE
425 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
426 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
427 +%.s: %.c gcc-plugins prepare scripts FORCE
428 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
429 %.i: %.c prepare scripts FORCE
430 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
431 -%.o: %.c prepare scripts FORCE
432 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
433 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
434 +%.o: %.c gcc-plugins prepare scripts FORCE
435 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
436 %.lst: %.c prepare scripts FORCE
437 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
438 -%.s: %.S prepare scripts FORCE
439 +%.s: %.S gcc-plugins prepare scripts FORCE
440 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
441 -%.o: %.S prepare scripts FORCE
442 +%.o: %.S gcc-plugins prepare scripts FORCE
443 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
444 %.symtypes: %.c prepare scripts FORCE
445 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
446 @@ -1369,11 +1436,15 @@ endif
447 $(cmd_crmodverdir)
448 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
449 $(build)=$(build-dir)
450 -%/: prepare scripts FORCE
451 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
452 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
453 +%/: gcc-plugins prepare scripts FORCE
454 $(cmd_crmodverdir)
455 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
456 $(build)=$(build-dir)
457 -%.ko: prepare scripts FORCE
458 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
459 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
460 +%.ko: gcc-plugins prepare scripts FORCE
461 $(cmd_crmodverdir)
462 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
463 $(build)=$(build-dir) $(@:.ko=.o)
464 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
465 index c2cbe4f..f7264b4 100644
466 --- a/arch/alpha/include/asm/atomic.h
467 +++ b/arch/alpha/include/asm/atomic.h
468 @@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
469 #define atomic_dec(v) atomic_sub(1,(v))
470 #define atomic64_dec(v) atomic64_sub(1,(v))
471
472 +#define atomic64_read_unchecked(v) atomic64_read(v)
473 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
474 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
475 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
476 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
477 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
478 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
479 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
480 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
481 +
482 #define smp_mb__before_atomic_dec() smp_mb()
483 #define smp_mb__after_atomic_dec() smp_mb()
484 #define smp_mb__before_atomic_inc() smp_mb()
485 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
486 index ad368a9..fbe0f25 100644
487 --- a/arch/alpha/include/asm/cache.h
488 +++ b/arch/alpha/include/asm/cache.h
489 @@ -4,19 +4,19 @@
490 #ifndef __ARCH_ALPHA_CACHE_H
491 #define __ARCH_ALPHA_CACHE_H
492
493 +#include <linux/const.h>
494
495 /* Bytes per L1 (data) cache line. */
496 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
497 -# define L1_CACHE_BYTES 64
498 # define L1_CACHE_SHIFT 6
499 #else
500 /* Both EV4 and EV5 are write-through, read-allocate,
501 direct-mapped, physical.
502 */
503 -# define L1_CACHE_BYTES 32
504 # define L1_CACHE_SHIFT 5
505 #endif
506
507 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
508 #define SMP_CACHE_BYTES L1_CACHE_BYTES
509
510 #endif
511 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
512 index 968d999..d36b2df 100644
513 --- a/arch/alpha/include/asm/elf.h
514 +++ b/arch/alpha/include/asm/elf.h
515 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
516
517 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
518
519 +#ifdef CONFIG_PAX_ASLR
520 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
521 +
522 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
523 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
524 +#endif
525 +
526 /* $0 is set by ld.so to a pointer to a function which might be
527 registered using atexit. This provides a mean for the dynamic
528 linker to call DT_FINI functions for shared libraries that have
529 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
530 index bc2a0da..8ad11ee 100644
531 --- a/arch/alpha/include/asm/pgalloc.h
532 +++ b/arch/alpha/include/asm/pgalloc.h
533 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
534 pgd_set(pgd, pmd);
535 }
536
537 +static inline void
538 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
539 +{
540 + pgd_populate(mm, pgd, pmd);
541 +}
542 +
543 extern pgd_t *pgd_alloc(struct mm_struct *mm);
544
545 static inline void
546 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
547 index 81a4342..348b927 100644
548 --- a/arch/alpha/include/asm/pgtable.h
549 +++ b/arch/alpha/include/asm/pgtable.h
550 @@ -102,6 +102,17 @@ struct vm_area_struct;
551 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
552 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
553 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
554 +
555 +#ifdef CONFIG_PAX_PAGEEXEC
556 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
557 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
558 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
559 +#else
560 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
561 +# define PAGE_COPY_NOEXEC PAGE_COPY
562 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
563 +#endif
564 +
565 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
566
567 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
568 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
569 index 2fd00b7..cfd5069 100644
570 --- a/arch/alpha/kernel/module.c
571 +++ b/arch/alpha/kernel/module.c
572 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
573
574 /* The small sections were sorted to the end of the segment.
575 The following should definitely cover them. */
576 - gp = (u64)me->module_core + me->core_size - 0x8000;
577 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
578 got = sechdrs[me->arch.gotsecindex].sh_addr;
579
580 for (i = 0; i < n; i++) {
581 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
582 index 14db93e..47bed62 100644
583 --- a/arch/alpha/kernel/osf_sys.c
584 +++ b/arch/alpha/kernel/osf_sys.c
585 @@ -1295,16 +1295,16 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
586 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
587
588 static unsigned long
589 -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
590 - unsigned long limit)
591 +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
592 + unsigned long limit, unsigned long flags)
593 {
594 struct vm_area_struct *vma = find_vma(current->mm, addr);
595 -
596 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
597 while (1) {
598 /* At this point: (!vma || addr < vma->vm_end). */
599 if (limit - len < addr)
600 return -ENOMEM;
601 - if (!vma || addr + len <= vma->vm_start)
602 + if (check_heap_stack_gap(vma, addr, len, offset))
603 return addr;
604 addr = vma->vm_end;
605 vma = vma->vm_next;
606 @@ -1340,20 +1340,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
607 merely specific addresses, but regions of memory -- perhaps
608 this feature should be incorporated into all ports? */
609
610 +#ifdef CONFIG_PAX_RANDMMAP
611 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
612 +#endif
613 +
614 if (addr) {
615 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
616 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
617 if (addr != (unsigned long) -ENOMEM)
618 return addr;
619 }
620
621 /* Next, try allocating at TASK_UNMAPPED_BASE. */
622 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
623 - len, limit);
624 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
625 +
626 if (addr != (unsigned long) -ENOMEM)
627 return addr;
628
629 /* Finally, try allocating in low memory. */
630 - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
631 + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
632
633 return addr;
634 }
635 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
636 index 0c4132d..88f0d53 100644
637 --- a/arch/alpha/mm/fault.c
638 +++ b/arch/alpha/mm/fault.c
639 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
640 __reload_thread(pcb);
641 }
642
643 +#ifdef CONFIG_PAX_PAGEEXEC
644 +/*
645 + * PaX: decide what to do with offenders (regs->pc = fault address)
646 + *
647 + * returns 1 when task should be killed
648 + * 2 when patched PLT trampoline was detected
649 + * 3 when unpatched PLT trampoline was detected
650 + */
651 +static int pax_handle_fetch_fault(struct pt_regs *regs)
652 +{
653 +
654 +#ifdef CONFIG_PAX_EMUPLT
655 + int err;
656 +
657 + do { /* PaX: patched PLT emulation #1 */
658 + unsigned int ldah, ldq, jmp;
659 +
660 + err = get_user(ldah, (unsigned int *)regs->pc);
661 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
662 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
663 +
664 + if (err)
665 + break;
666 +
667 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
668 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
669 + jmp == 0x6BFB0000U)
670 + {
671 + unsigned long r27, addr;
672 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
673 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
674 +
675 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
676 + err = get_user(r27, (unsigned long *)addr);
677 + if (err)
678 + break;
679 +
680 + regs->r27 = r27;
681 + regs->pc = r27;
682 + return 2;
683 + }
684 + } while (0);
685 +
686 + do { /* PaX: patched PLT emulation #2 */
687 + unsigned int ldah, lda, br;
688 +
689 + err = get_user(ldah, (unsigned int *)regs->pc);
690 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
691 + err |= get_user(br, (unsigned int *)(regs->pc+8));
692 +
693 + if (err)
694 + break;
695 +
696 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
697 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
698 + (br & 0xFFE00000U) == 0xC3E00000U)
699 + {
700 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
701 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
702 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
703 +
704 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
705 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
706 + return 2;
707 + }
708 + } while (0);
709 +
710 + do { /* PaX: unpatched PLT emulation */
711 + unsigned int br;
712 +
713 + err = get_user(br, (unsigned int *)regs->pc);
714 +
715 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
716 + unsigned int br2, ldq, nop, jmp;
717 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
718 +
719 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
720 + err = get_user(br2, (unsigned int *)addr);
721 + err |= get_user(ldq, (unsigned int *)(addr+4));
722 + err |= get_user(nop, (unsigned int *)(addr+8));
723 + err |= get_user(jmp, (unsigned int *)(addr+12));
724 + err |= get_user(resolver, (unsigned long *)(addr+16));
725 +
726 + if (err)
727 + break;
728 +
729 + if (br2 == 0xC3600000U &&
730 + ldq == 0xA77B000CU &&
731 + nop == 0x47FF041FU &&
732 + jmp == 0x6B7B0000U)
733 + {
734 + regs->r28 = regs->pc+4;
735 + regs->r27 = addr+16;
736 + regs->pc = resolver;
737 + return 3;
738 + }
739 + }
740 + } while (0);
741 +#endif
742 +
743 + return 1;
744 +}
745 +
746 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
747 +{
748 + unsigned long i;
749 +
750 + printk(KERN_ERR "PAX: bytes at PC: ");
751 + for (i = 0; i < 5; i++) {
752 + unsigned int c;
753 + if (get_user(c, (unsigned int *)pc+i))
754 + printk(KERN_CONT "???????? ");
755 + else
756 + printk(KERN_CONT "%08x ", c);
757 + }
758 + printk("\n");
759 +}
760 +#endif
761
762 /*
763 * This routine handles page faults. It determines the address,
764 @@ -133,8 +251,29 @@ retry:
765 good_area:
766 si_code = SEGV_ACCERR;
767 if (cause < 0) {
768 - if (!(vma->vm_flags & VM_EXEC))
769 + if (!(vma->vm_flags & VM_EXEC)) {
770 +
771 +#ifdef CONFIG_PAX_PAGEEXEC
772 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
773 + goto bad_area;
774 +
775 + up_read(&mm->mmap_sem);
776 + switch (pax_handle_fetch_fault(regs)) {
777 +
778 +#ifdef CONFIG_PAX_EMUPLT
779 + case 2:
780 + case 3:
781 + return;
782 +#endif
783 +
784 + }
785 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
786 + do_group_exit(SIGKILL);
787 +#else
788 goto bad_area;
789 +#endif
790 +
791 + }
792 } else if (!cause) {
793 /* Allow reads even for write-only mappings */
794 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
795 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
796 index c79f61f..9ac0642 100644
797 --- a/arch/arm/include/asm/atomic.h
798 +++ b/arch/arm/include/asm/atomic.h
799 @@ -17,17 +17,35 @@
800 #include <asm/barrier.h>
801 #include <asm/cmpxchg.h>
802
803 +#ifdef CONFIG_GENERIC_ATOMIC64
804 +#include <asm-generic/atomic64.h>
805 +#endif
806 +
807 #define ATOMIC_INIT(i) { (i) }
808
809 #ifdef __KERNEL__
810
811 +#define _ASM_EXTABLE(from, to) \
812 +" .pushsection __ex_table,\"a\"\n"\
813 +" .align 3\n" \
814 +" .long " #from ", " #to"\n" \
815 +" .popsection"
816 +
817 /*
818 * On ARM, ordinary assignment (str instruction) doesn't clear the local
819 * strex/ldrex monitor on some implementations. The reason we can use it for
820 * atomic_set() is the clrex or dummy strex done on every exception return.
821 */
822 #define atomic_read(v) (*(volatile int *)&(v)->counter)
823 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
824 +{
825 + return v->counter;
826 +}
827 #define atomic_set(v,i) (((v)->counter) = (i))
828 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
829 +{
830 + v->counter = i;
831 +}
832
833 #if __LINUX_ARM_ARCH__ >= 6
834
835 @@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
836 int result;
837
838 __asm__ __volatile__("@ atomic_add\n"
839 +"1: ldrex %1, [%3]\n"
840 +" adds %0, %1, %4\n"
841 +
842 +#ifdef CONFIG_PAX_REFCOUNT
843 +" bvc 3f\n"
844 +"2: bkpt 0xf103\n"
845 +"3:\n"
846 +#endif
847 +
848 +" strex %1, %0, [%3]\n"
849 +" teq %1, #0\n"
850 +" bne 1b"
851 +
852 +#ifdef CONFIG_PAX_REFCOUNT
853 +"\n4:\n"
854 + _ASM_EXTABLE(2b, 4b)
855 +#endif
856 +
857 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
858 + : "r" (&v->counter), "Ir" (i)
859 + : "cc");
860 +}
861 +
862 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
863 +{
864 + unsigned long tmp;
865 + int result;
866 +
867 + __asm__ __volatile__("@ atomic_add_unchecked\n"
868 "1: ldrex %0, [%3]\n"
869 " add %0, %0, %4\n"
870 " strex %1, %0, [%3]\n"
871 @@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
872 smp_mb();
873
874 __asm__ __volatile__("@ atomic_add_return\n"
875 +"1: ldrex %1, [%3]\n"
876 +" adds %0, %1, %4\n"
877 +
878 +#ifdef CONFIG_PAX_REFCOUNT
879 +" bvc 3f\n"
880 +" mov %0, %1\n"
881 +"2: bkpt 0xf103\n"
882 +"3:\n"
883 +#endif
884 +
885 +" strex %1, %0, [%3]\n"
886 +" teq %1, #0\n"
887 +" bne 1b"
888 +
889 +#ifdef CONFIG_PAX_REFCOUNT
890 +"\n4:\n"
891 + _ASM_EXTABLE(2b, 4b)
892 +#endif
893 +
894 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
895 + : "r" (&v->counter), "Ir" (i)
896 + : "cc");
897 +
898 + smp_mb();
899 +
900 + return result;
901 +}
902 +
903 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
904 +{
905 + unsigned long tmp;
906 + int result;
907 +
908 + smp_mb();
909 +
910 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
911 "1: ldrex %0, [%3]\n"
912 " add %0, %0, %4\n"
913 " strex %1, %0, [%3]\n"
914 @@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
915 int result;
916
917 __asm__ __volatile__("@ atomic_sub\n"
918 +"1: ldrex %1, [%3]\n"
919 +" subs %0, %1, %4\n"
920 +
921 +#ifdef CONFIG_PAX_REFCOUNT
922 +" bvc 3f\n"
923 +"2: bkpt 0xf103\n"
924 +"3:\n"
925 +#endif
926 +
927 +" strex %1, %0, [%3]\n"
928 +" teq %1, #0\n"
929 +" bne 1b"
930 +
931 +#ifdef CONFIG_PAX_REFCOUNT
932 +"\n4:\n"
933 + _ASM_EXTABLE(2b, 4b)
934 +#endif
935 +
936 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
937 + : "r" (&v->counter), "Ir" (i)
938 + : "cc");
939 +}
940 +
941 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
942 +{
943 + unsigned long tmp;
944 + int result;
945 +
946 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
947 "1: ldrex %0, [%3]\n"
948 " sub %0, %0, %4\n"
949 " strex %1, %0, [%3]\n"
950 @@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
951 smp_mb();
952
953 __asm__ __volatile__("@ atomic_sub_return\n"
954 -"1: ldrex %0, [%3]\n"
955 -" sub %0, %0, %4\n"
956 +"1: ldrex %1, [%3]\n"
957 +" subs %0, %1, %4\n"
958 +
959 +#ifdef CONFIG_PAX_REFCOUNT
960 +" bvc 3f\n"
961 +" mov %0, %1\n"
962 +"2: bkpt 0xf103\n"
963 +"3:\n"
964 +#endif
965 +
966 " strex %1, %0, [%3]\n"
967 " teq %1, #0\n"
968 " bne 1b"
969 +
970 +#ifdef CONFIG_PAX_REFCOUNT
971 +"\n4:\n"
972 + _ASM_EXTABLE(2b, 4b)
973 +#endif
974 +
975 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
976 : "r" (&v->counter), "Ir" (i)
977 : "cc");
978 @@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
979 return oldval;
980 }
981
982 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
983 +{
984 + unsigned long oldval, res;
985 +
986 + smp_mb();
987 +
988 + do {
989 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
990 + "ldrex %1, [%3]\n"
991 + "mov %0, #0\n"
992 + "teq %1, %4\n"
993 + "strexeq %0, %5, [%3]\n"
994 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
995 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
996 + : "cc");
997 + } while (res);
998 +
999 + smp_mb();
1000 +
1001 + return oldval;
1002 +}
1003 +
1004 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1005 {
1006 unsigned long tmp, tmp2;
1007 @@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1008
1009 return val;
1010 }
1011 +
1012 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1013 +{
1014 + return atomic_add_return(i, v);
1015 +}
1016 +
1017 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1018 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1019 +{
1020 + (void) atomic_add_return(i, v);
1021 +}
1022
1023 static inline int atomic_sub_return(int i, atomic_t *v)
1024 {
1025 @@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1026 return val;
1027 }
1028 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1029 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1030 +{
1031 + (void) atomic_sub_return(i, v);
1032 +}
1033
1034 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1035 {
1036 @@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1037 return ret;
1038 }
1039
1040 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1041 +{
1042 + return atomic_cmpxchg(v, old, new);
1043 +}
1044 +
1045 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1046 {
1047 unsigned long flags;
1048 @@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1049 #endif /* __LINUX_ARM_ARCH__ */
1050
1051 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1052 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1053 +{
1054 + return xchg(&v->counter, new);
1055 +}
1056
1057 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1058 {
1059 @@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1060 }
1061
1062 #define atomic_inc(v) atomic_add(1, v)
1063 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1064 +{
1065 + atomic_add_unchecked(1, v);
1066 +}
1067 #define atomic_dec(v) atomic_sub(1, v)
1068 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1069 +{
1070 + atomic_sub_unchecked(1, v);
1071 +}
1072
1073 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1074 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1075 +{
1076 + return atomic_add_return_unchecked(1, v) == 0;
1077 +}
1078 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1079 #define atomic_inc_return(v) (atomic_add_return(1, v))
1080 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1081 +{
1082 + return atomic_add_return_unchecked(1, v);
1083 +}
1084 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1085 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1086
1087 @@ -241,6 +428,14 @@ typedef struct {
1088 u64 __aligned(8) counter;
1089 } atomic64_t;
1090
1091 +#ifdef CONFIG_PAX_REFCOUNT
1092 +typedef struct {
1093 + u64 __aligned(8) counter;
1094 +} atomic64_unchecked_t;
1095 +#else
1096 +typedef atomic64_t atomic64_unchecked_t;
1097 +#endif
1098 +
1099 #define ATOMIC64_INIT(i) { (i) }
1100
1101 static inline u64 atomic64_read(const atomic64_t *v)
1102 @@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1103 return result;
1104 }
1105
1106 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1107 +{
1108 + u64 result;
1109 +
1110 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1111 +" ldrexd %0, %H0, [%1]"
1112 + : "=&r" (result)
1113 + : "r" (&v->counter), "Qo" (v->counter)
1114 + );
1115 +
1116 + return result;
1117 +}
1118 +
1119 static inline void atomic64_set(atomic64_t *v, u64 i)
1120 {
1121 u64 tmp;
1122 @@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1123 : "cc");
1124 }
1125
1126 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1127 +{
1128 + u64 tmp;
1129 +
1130 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1131 +"1: ldrexd %0, %H0, [%2]\n"
1132 +" strexd %0, %3, %H3, [%2]\n"
1133 +" teq %0, #0\n"
1134 +" bne 1b"
1135 + : "=&r" (tmp), "=Qo" (v->counter)
1136 + : "r" (&v->counter), "r" (i)
1137 + : "cc");
1138 +}
1139 +
1140 static inline void atomic64_add(u64 i, atomic64_t *v)
1141 {
1142 u64 result;
1143 @@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1144 __asm__ __volatile__("@ atomic64_add\n"
1145 "1: ldrexd %0, %H0, [%3]\n"
1146 " adds %0, %0, %4\n"
1147 +" adcs %H0, %H0, %H4\n"
1148 +
1149 +#ifdef CONFIG_PAX_REFCOUNT
1150 +" bvc 3f\n"
1151 +"2: bkpt 0xf103\n"
1152 +"3:\n"
1153 +#endif
1154 +
1155 +" strexd %1, %0, %H0, [%3]\n"
1156 +" teq %1, #0\n"
1157 +" bne 1b"
1158 +
1159 +#ifdef CONFIG_PAX_REFCOUNT
1160 +"\n4:\n"
1161 + _ASM_EXTABLE(2b, 4b)
1162 +#endif
1163 +
1164 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1165 + : "r" (&v->counter), "r" (i)
1166 + : "cc");
1167 +}
1168 +
1169 +static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1170 +{
1171 + u64 result;
1172 + unsigned long tmp;
1173 +
1174 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1175 +"1: ldrexd %0, %H0, [%3]\n"
1176 +" adds %0, %0, %4\n"
1177 " adc %H0, %H0, %H4\n"
1178 " strexd %1, %0, %H0, [%3]\n"
1179 " teq %1, #0\n"
1180 @@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1181
1182 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1183 {
1184 - u64 result;
1185 - unsigned long tmp;
1186 + u64 result, tmp;
1187
1188 smp_mb();
1189
1190 __asm__ __volatile__("@ atomic64_add_return\n"
1191 +"1: ldrexd %1, %H1, [%3]\n"
1192 +" adds %0, %1, %4\n"
1193 +" adcs %H0, %H1, %H4\n"
1194 +
1195 +#ifdef CONFIG_PAX_REFCOUNT
1196 +" bvc 3f\n"
1197 +" mov %0, %1\n"
1198 +" mov %H0, %H1\n"
1199 +"2: bkpt 0xf103\n"
1200 +"3:\n"
1201 +#endif
1202 +
1203 +" strexd %1, %0, %H0, [%3]\n"
1204 +" teq %1, #0\n"
1205 +" bne 1b"
1206 +
1207 +#ifdef CONFIG_PAX_REFCOUNT
1208 +"\n4:\n"
1209 + _ASM_EXTABLE(2b, 4b)
1210 +#endif
1211 +
1212 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1213 + : "r" (&v->counter), "r" (i)
1214 + : "cc");
1215 +
1216 + smp_mb();
1217 +
1218 + return result;
1219 +}
1220 +
1221 +static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1222 +{
1223 + u64 result;
1224 + unsigned long tmp;
1225 +
1226 + smp_mb();
1227 +
1228 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1229 "1: ldrexd %0, %H0, [%3]\n"
1230 " adds %0, %0, %4\n"
1231 " adc %H0, %H0, %H4\n"
1232 @@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1233 __asm__ __volatile__("@ atomic64_sub\n"
1234 "1: ldrexd %0, %H0, [%3]\n"
1235 " subs %0, %0, %4\n"
1236 +" sbcs %H0, %H0, %H4\n"
1237 +
1238 +#ifdef CONFIG_PAX_REFCOUNT
1239 +" bvc 3f\n"
1240 +"2: bkpt 0xf103\n"
1241 +"3:\n"
1242 +#endif
1243 +
1244 +" strexd %1, %0, %H0, [%3]\n"
1245 +" teq %1, #0\n"
1246 +" bne 1b"
1247 +
1248 +#ifdef CONFIG_PAX_REFCOUNT
1249 +"\n4:\n"
1250 + _ASM_EXTABLE(2b, 4b)
1251 +#endif
1252 +
1253 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1254 + : "r" (&v->counter), "r" (i)
1255 + : "cc");
1256 +}
1257 +
1258 +static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1259 +{
1260 + u64 result;
1261 + unsigned long tmp;
1262 +
1263 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1264 +"1: ldrexd %0, %H0, [%3]\n"
1265 +" subs %0, %0, %4\n"
1266 " sbc %H0, %H0, %H4\n"
1267 " strexd %1, %0, %H0, [%3]\n"
1268 " teq %1, #0\n"
1269 @@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1270
1271 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1272 {
1273 - u64 result;
1274 - unsigned long tmp;
1275 + u64 result, tmp;
1276
1277 smp_mb();
1278
1279 __asm__ __volatile__("@ atomic64_sub_return\n"
1280 -"1: ldrexd %0, %H0, [%3]\n"
1281 -" subs %0, %0, %4\n"
1282 -" sbc %H0, %H0, %H4\n"
1283 +"1: ldrexd %1, %H1, [%3]\n"
1284 +" subs %0, %1, %4\n"
1285 +" sbcs %H0, %H1, %H4\n"
1286 +
1287 +#ifdef CONFIG_PAX_REFCOUNT
1288 +" bvc 3f\n"
1289 +" mov %0, %1\n"
1290 +" mov %H0, %H1\n"
1291 +"2: bkpt 0xf103\n"
1292 +"3:\n"
1293 +#endif
1294 +
1295 " strexd %1, %0, %H0, [%3]\n"
1296 " teq %1, #0\n"
1297 " bne 1b"
1298 +
1299 +#ifdef CONFIG_PAX_REFCOUNT
1300 +"\n4:\n"
1301 + _ASM_EXTABLE(2b, 4b)
1302 +#endif
1303 +
1304 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1305 : "r" (&v->counter), "r" (i)
1306 : "cc");
1307 @@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1308 return oldval;
1309 }
1310
1311 +static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1312 +{
1313 + u64 oldval;
1314 + unsigned long res;
1315 +
1316 + smp_mb();
1317 +
1318 + do {
1319 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1320 + "ldrexd %1, %H1, [%3]\n"
1321 + "mov %0, #0\n"
1322 + "teq %1, %4\n"
1323 + "teqeq %H1, %H4\n"
1324 + "strexdeq %0, %5, %H5, [%3]"
1325 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1326 + : "r" (&ptr->counter), "r" (old), "r" (new)
1327 + : "cc");
1328 + } while (res);
1329 +
1330 + smp_mb();
1331 +
1332 + return oldval;
1333 +}
1334 +
1335 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1336 {
1337 u64 result;
1338 @@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1339
1340 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1341 {
1342 - u64 result;
1343 - unsigned long tmp;
1344 + u64 result, tmp;
1345
1346 smp_mb();
1347
1348 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1349 -"1: ldrexd %0, %H0, [%3]\n"
1350 -" subs %0, %0, #1\n"
1351 -" sbc %H0, %H0, #0\n"
1352 +"1: ldrexd %1, %H1, [%3]\n"
1353 +" subs %0, %1, #1\n"
1354 +" sbcs %H0, %H1, #0\n"
1355 +
1356 +#ifdef CONFIG_PAX_REFCOUNT
1357 +" bvc 3f\n"
1358 +" mov %0, %1\n"
1359 +" mov %H0, %H1\n"
1360 +"2: bkpt 0xf103\n"
1361 +"3:\n"
1362 +#endif
1363 +
1364 " teq %H0, #0\n"
1365 -" bmi 2f\n"
1366 +" bmi 4f\n"
1367 " strexd %1, %0, %H0, [%3]\n"
1368 " teq %1, #0\n"
1369 " bne 1b\n"
1370 -"2:"
1371 +"4:\n"
1372 +
1373 +#ifdef CONFIG_PAX_REFCOUNT
1374 + _ASM_EXTABLE(2b, 4b)
1375 +#endif
1376 +
1377 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1378 : "r" (&v->counter)
1379 : "cc");
1380 @@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1381 " teq %0, %5\n"
1382 " teqeq %H0, %H5\n"
1383 " moveq %1, #0\n"
1384 -" beq 2f\n"
1385 +" beq 4f\n"
1386 " adds %0, %0, %6\n"
1387 -" adc %H0, %H0, %H6\n"
1388 +" adcs %H0, %H0, %H6\n"
1389 +
1390 +#ifdef CONFIG_PAX_REFCOUNT
1391 +" bvc 3f\n"
1392 +"2: bkpt 0xf103\n"
1393 +"3:\n"
1394 +#endif
1395 +
1396 " strexd %2, %0, %H0, [%4]\n"
1397 " teq %2, #0\n"
1398 " bne 1b\n"
1399 -"2:"
1400 +"4:\n"
1401 +
1402 +#ifdef CONFIG_PAX_REFCOUNT
1403 + _ASM_EXTABLE(2b, 4b)
1404 +#endif
1405 +
1406 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1407 : "r" (&v->counter), "r" (u), "r" (a)
1408 : "cc");
1409 @@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1410
1411 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1412 #define atomic64_inc(v) atomic64_add(1LL, (v))
1413 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1414 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1415 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1416 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1417 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1418 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1419 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1420 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1421 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1422 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1423 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1424 index 75fe66b..ba3dee4 100644
1425 --- a/arch/arm/include/asm/cache.h
1426 +++ b/arch/arm/include/asm/cache.h
1427 @@ -4,8 +4,10 @@
1428 #ifndef __ASMARM_CACHE_H
1429 #define __ASMARM_CACHE_H
1430
1431 +#include <linux/const.h>
1432 +
1433 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1434 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1435 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1436
1437 /*
1438 * Memory returned by kmalloc() may be used for DMA, so we must make
1439 @@ -24,5 +26,6 @@
1440 #endif
1441
1442 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1443 +#define __read_only __attribute__ ((__section__(".data..read_only")))
1444
1445 #endif
1446 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1447 index e1489c5..d418304 100644
1448 --- a/arch/arm/include/asm/cacheflush.h
1449 +++ b/arch/arm/include/asm/cacheflush.h
1450 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1451 void (*dma_unmap_area)(const void *, size_t, int);
1452
1453 void (*dma_flush_range)(const void *, const void *);
1454 -};
1455 +} __no_const;
1456
1457 /*
1458 * Select the calling method
1459 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1460 index 7eb18c1..e38b6d2 100644
1461 --- a/arch/arm/include/asm/cmpxchg.h
1462 +++ b/arch/arm/include/asm/cmpxchg.h
1463 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1464
1465 #define xchg(ptr,x) \
1466 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1467 +#define xchg_unchecked(ptr,x) \
1468 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1469
1470 #include <asm-generic/cmpxchg-local.h>
1471
1472 diff --git a/arch/arm/include/asm/delay.h b/arch/arm/include/asm/delay.h
1473 index ab98fdd..6b19938 100644
1474 --- a/arch/arm/include/asm/delay.h
1475 +++ b/arch/arm/include/asm/delay.h
1476 @@ -24,9 +24,9 @@ extern struct arm_delay_ops {
1477 void (*delay)(unsigned long);
1478 void (*const_udelay)(unsigned long);
1479 void (*udelay)(unsigned long);
1480 -} arm_delay_ops;
1481 +} *arm_delay_ops;
1482
1483 -#define __delay(n) arm_delay_ops.delay(n)
1484 +#define __delay(n) arm_delay_ops->delay(n)
1485
1486 /*
1487 * This function intentionally does not exist; if you see references to
1488 @@ -47,8 +47,8 @@ extern void __bad_udelay(void);
1489 * first constant multiplications gets optimized away if the delay is
1490 * a constant)
1491 */
1492 -#define __udelay(n) arm_delay_ops.udelay(n)
1493 -#define __const_udelay(n) arm_delay_ops.const_udelay(n)
1494 +#define __udelay(n) arm_delay_ops->udelay(n)
1495 +#define __const_udelay(n) arm_delay_ops->const_udelay(n)
1496
1497 #define udelay(n) \
1498 (__builtin_constant_p(n) ? \
1499 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1500 index 38050b1..9d90e8b 100644
1501 --- a/arch/arm/include/asm/elf.h
1502 +++ b/arch/arm/include/asm/elf.h
1503 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1504 the loader. We need to make sure that it is out of the way of the program
1505 that it will "exec", and that there is sufficient room for the brk. */
1506
1507 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1508 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1509 +
1510 +#ifdef CONFIG_PAX_ASLR
1511 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1512 +
1513 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1514 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1515 +#endif
1516
1517 /* When the program starts, a1 contains a pointer to a function to be
1518 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1519 @@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1520 extern void elf_set_personality(const struct elf32_hdr *);
1521 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1522
1523 -struct mm_struct;
1524 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1525 -#define arch_randomize_brk arch_randomize_brk
1526 -
1527 #endif
1528 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1529 index 83eb2f7..ed77159 100644
1530 --- a/arch/arm/include/asm/kmap_types.h
1531 +++ b/arch/arm/include/asm/kmap_types.h
1532 @@ -4,6 +4,6 @@
1533 /*
1534 * This is the "bare minimum". AIO seems to require this.
1535 */
1536 -#define KM_TYPE_NR 16
1537 +#define KM_TYPE_NR 17
1538
1539 #endif
1540 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1541 index 9e614a1..3302cca 100644
1542 --- a/arch/arm/include/asm/mach/dma.h
1543 +++ b/arch/arm/include/asm/mach/dma.h
1544 @@ -22,7 +22,7 @@ struct dma_ops {
1545 int (*residue)(unsigned int, dma_t *); /* optional */
1546 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1547 const char *type;
1548 -};
1549 +} __do_const;
1550
1551 struct dma_struct {
1552 void *addr; /* single DMA address */
1553 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1554 index 195ac2f..2272f0d 100644
1555 --- a/arch/arm/include/asm/mach/map.h
1556 +++ b/arch/arm/include/asm/mach/map.h
1557 @@ -34,6 +34,9 @@ struct map_desc {
1558 #define MT_MEMORY_ITCM 13
1559 #define MT_MEMORY_SO 14
1560 #define MT_MEMORY_DMA_READY 15
1561 +#define MT_MEMORY_R 16
1562 +#define MT_MEMORY_RW 17
1563 +#define MT_MEMORY_RX 18
1564
1565 #ifdef CONFIG_MMU
1566 extern void iotable_init(struct map_desc *, int);
1567 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1568 index 53426c6..c7baff3 100644
1569 --- a/arch/arm/include/asm/outercache.h
1570 +++ b/arch/arm/include/asm/outercache.h
1571 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1572 #endif
1573 void (*set_debug)(unsigned long);
1574 void (*resume)(void);
1575 -};
1576 +} __no_const;
1577
1578 #ifdef CONFIG_OUTER_CACHE
1579
1580 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1581 index 812a494..71fc0b6 100644
1582 --- a/arch/arm/include/asm/page.h
1583 +++ b/arch/arm/include/asm/page.h
1584 @@ -114,7 +114,7 @@ struct cpu_user_fns {
1585 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1586 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1587 unsigned long vaddr, struct vm_area_struct *vma);
1588 -};
1589 +} __no_const;
1590
1591 #ifdef MULTI_USER
1592 extern struct cpu_user_fns cpu_user;
1593 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1594 index 943504f..84d0f84 100644
1595 --- a/arch/arm/include/asm/pgalloc.h
1596 +++ b/arch/arm/include/asm/pgalloc.h
1597 @@ -17,6 +17,7 @@
1598 #include <asm/processor.h>
1599 #include <asm/cacheflush.h>
1600 #include <asm/tlbflush.h>
1601 +#include <asm/system_info.h>
1602
1603 #define check_pgt_cache() do { } while (0)
1604
1605 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1606 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1607 }
1608
1609 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1610 +{
1611 + pud_populate(mm, pud, pmd);
1612 +}
1613 +
1614 #else /* !CONFIG_ARM_LPAE */
1615
1616 /*
1617 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1618 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1619 #define pmd_free(mm, pmd) do { } while (0)
1620 #define pud_populate(mm,pmd,pte) BUG()
1621 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1622
1623 #endif /* CONFIG_ARM_LPAE */
1624
1625 @@ -126,6 +133,16 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1626 __free_page(pte);
1627 }
1628
1629 +static inline void __pmd_update(pmd_t *pmdp, pmdval_t prot)
1630 +{
1631 + pmdval_t pmdval = pmd_val(*pmdp) | prot;
1632 + pmdp[0] = __pmd(pmdval);
1633 +#ifndef CONFIG_ARM_LPAE
1634 + pmdp[1] = __pmd(pmdval + 256 * sizeof(pte_t));
1635 +#endif
1636 + flush_pmd_entry(pmdp);
1637 +}
1638 +
1639 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1640 pmdval_t prot)
1641 {
1642 @@ -155,7 +172,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1643 static inline void
1644 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1645 {
1646 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1647 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1648 }
1649 #define pmd_pgtable(pmd) pmd_page(pmd)
1650
1651 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1652 index 5cfba15..d437dc2 100644
1653 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1654 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1655 @@ -20,12 +20,15 @@
1656 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1657 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1658 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1659 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* PXN */
1660 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1661 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1662 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1663 +
1664 /*
1665 * - section
1666 */
1667 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0)
1668 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1669 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1670 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1671 @@ -37,6 +40,7 @@
1672 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1673 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1674 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1675 +#define PMD_SECT_AP_RDONLY (_AT(pmdval_t, 0))
1676
1677 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1678 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1679 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1680 index 2317a71..1897391 100644
1681 --- a/arch/arm/include/asm/pgtable-2level.h
1682 +++ b/arch/arm/include/asm/pgtable-2level.h
1683 @@ -123,6 +123,7 @@
1684 #define L_PTE_USER (_AT(pteval_t, 1) << 8)
1685 #define L_PTE_XN (_AT(pteval_t, 1) << 9)
1686 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1687 +#define L_PTE_PXN (_AT(pteval_t, 1) << 11) /* v7*/
1688
1689 /*
1690 * These are the memory types, defined to be compatible with
1691 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1692 index d795282..d82ff13 100644
1693 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1694 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1695 @@ -32,6 +32,7 @@
1696 #define PMD_TYPE_SECT (_AT(pmdval_t, 1) << 0)
1697 #define PMD_BIT4 (_AT(pmdval_t, 0))
1698 #define PMD_DOMAIN(x) (_AT(pmdval_t, 0))
1699 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 59) /* PXNTable */
1700
1701 /*
1702 * - section
1703 @@ -41,9 +42,11 @@
1704 #define PMD_SECT_S (_AT(pmdval_t, 3) << 8)
1705 #define PMD_SECT_AF (_AT(pmdval_t, 1) << 10)
1706 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 11)
1707 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 53)
1708 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 54)
1709 #define PMD_SECT_AP_WRITE (_AT(pmdval_t, 0))
1710 #define PMD_SECT_AP_READ (_AT(pmdval_t, 0))
1711 +#define PMD_SECT_AP_RDONLY (_AT(pmdval_t, 1) << 7)
1712 #define PMD_SECT_TEX(x) (_AT(pmdval_t, 0))
1713
1714 /*
1715 @@ -66,6 +69,7 @@
1716 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1717 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1718 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1719 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1720 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1721
1722 /*
1723 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1724 index b249035..4ab204b 100644
1725 --- a/arch/arm/include/asm/pgtable-3level.h
1726 +++ b/arch/arm/include/asm/pgtable-3level.h
1727 @@ -73,6 +73,7 @@
1728 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1729 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1730 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1731 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1732 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1733 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1734 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1735 @@ -80,6 +81,7 @@
1736 /*
1737 * To be used in assembly code with the upper page attributes.
1738 */
1739 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
1740 #define L_PTE_XN_HIGH (1 << (54 - 32))
1741 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1742
1743 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1744 index 08c1231..1031bb4 100644
1745 --- a/arch/arm/include/asm/pgtable.h
1746 +++ b/arch/arm/include/asm/pgtable.h
1747 @@ -30,6 +30,9 @@
1748 #include <asm/pgtable-2level.h>
1749 #endif
1750
1751 +#define ktla_ktva(addr) (addr)
1752 +#define ktva_ktla(addr) (addr)
1753 +
1754 /*
1755 * Just any arbitrary offset to the start of the vmalloc VM area: the
1756 * current 8MB value just means that there will be a 8MB "hole" after the
1757 @@ -45,6 +48,9 @@
1758 #define LIBRARY_TEXT_START 0x0c000000
1759
1760 #ifndef __ASSEMBLY__
1761 +extern pteval_t __supported_pte_mask;
1762 +extern pmdval_t __supported_pmd_mask;
1763 +
1764 extern void __pte_error(const char *file, int line, pte_t);
1765 extern void __pmd_error(const char *file, int line, pmd_t);
1766 extern void __pgd_error(const char *file, int line, pgd_t);
1767 @@ -53,6 +59,17 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1768 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1769 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1770
1771 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
1772 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
1773 +
1774 +#ifdef CONFIG_PAX_KERNEXEC
1775 +static inline unsigned long pax_open_kernel(void) { return 0; /* TODO */ }
1776 +static inline unsigned long pax_close_kernel(void) { return 0; /* TODO */ }
1777 +#else
1778 +static inline unsigned long pax_open_kernel(void) { return 0; }
1779 +static inline unsigned long pax_close_kernel(void) { return 0; }
1780 +#endif
1781 +
1782 /*
1783 * This is the lowest virtual address we can permit any user space
1784 * mapping to be mapped at. This is particularly important for
1785 @@ -63,8 +80,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1786 /*
1787 * The pgprot_* and protection_map entries will be fixed up in runtime
1788 * to include the cachable and bufferable bits based on memory policy,
1789 - * as well as any architecture dependent bits like global/ASID and SMP
1790 - * shared mapping bits.
1791 + * as well as any architecture dependent bits like global/ASID, PXN,
1792 + * and SMP shared mapping bits.
1793 */
1794 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
1795
1796 @@ -242,7 +259,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
1797
1798 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
1799 {
1800 - const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER;
1801 + const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER | __supported_pte_mask;
1802 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
1803 return pte;
1804 }
1805 diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
1806 index f3628fb..a0672dd 100644
1807 --- a/arch/arm/include/asm/proc-fns.h
1808 +++ b/arch/arm/include/asm/proc-fns.h
1809 @@ -75,7 +75,7 @@ extern struct processor {
1810 unsigned int suspend_size;
1811 void (*do_suspend)(void *);
1812 void (*do_resume)(void *);
1813 -} processor;
1814 +} __do_const processor;
1815
1816 #ifndef MULTI_CPU
1817 extern void cpu_proc_init(void);
1818 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
1819 index 2e3be16..4dc90fc 100644
1820 --- a/arch/arm/include/asm/smp.h
1821 +++ b/arch/arm/include/asm/smp.h
1822 @@ -106,7 +106,7 @@ struct smp_operations {
1823 int (*cpu_disable)(unsigned int cpu);
1824 #endif
1825 #endif
1826 -};
1827 +} __no_const;
1828
1829 /*
1830 * set platform specific SMP operations
1831 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1832 index 8477b4c..801a6a9 100644
1833 --- a/arch/arm/include/asm/thread_info.h
1834 +++ b/arch/arm/include/asm/thread_info.h
1835 @@ -151,6 +151,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1836 #define TIF_SYSCALL_TRACE 8
1837 #define TIF_SYSCALL_AUDIT 9
1838 #define TIF_SYSCALL_TRACEPOINT 10
1839 +
1840 +/* within 8 bits of TIF_SYSCALL_TRACE
1841 + to meet flexible second operand requirements
1842 +*/
1843 +#define TIF_GRSEC_SETXID 11
1844 +
1845 #define TIF_USING_IWMMXT 17
1846 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1847 #define TIF_RESTORE_SIGMASK 20
1848 @@ -165,9 +171,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1849 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
1850 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1851 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1852 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1853
1854 /* Checks for any syscall work in entry-common.S */
1855 -#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
1856 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | \
1857 + _TIF_GRSEC_SETXID)
1858
1859 /*
1860 * Change these and you break ASM code in entry-common.S
1861 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1862 index 7e1f760..f2c37b1 100644
1863 --- a/arch/arm/include/asm/uaccess.h
1864 +++ b/arch/arm/include/asm/uaccess.h
1865 @@ -418,8 +418,23 @@ do { \
1866
1867
1868 #ifdef CONFIG_MMU
1869 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1870 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1871 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1872 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1873 +
1874 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1875 +{
1876 + check_object_size(to, n, false);
1877 +
1878 + return ___copy_from_user(to, from, n);
1879 +}
1880 +
1881 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1882 +{
1883 + check_object_size(from, n, true);
1884 +
1885 + return ___copy_to_user(to, from, n);
1886 +}
1887 +
1888 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1889 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1890 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1891 @@ -431,6 +446,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
1892
1893 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1894 {
1895 + if ((long)n < 0)
1896 + return n;
1897 +
1898 if (access_ok(VERIFY_READ, from, n))
1899 n = __copy_from_user(to, from, n);
1900 else /* security hole - plug it */
1901 @@ -440,6 +458,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1902
1903 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1904 {
1905 + if ((long)n < 0)
1906 + return n;
1907 +
1908 if (access_ok(VERIFY_WRITE, to, n))
1909 n = __copy_to_user(to, from, n);
1910 return n;
1911 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
1912 index 96ee092..37f1844 100644
1913 --- a/arch/arm/include/uapi/asm/ptrace.h
1914 +++ b/arch/arm/include/uapi/asm/ptrace.h
1915 @@ -73,7 +73,7 @@
1916 * ARMv7 groups of PSR bits
1917 */
1918 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
1919 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
1920 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
1921 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
1922 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
1923
1924 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1925 index 60d3b73..9168db0 100644
1926 --- a/arch/arm/kernel/armksyms.c
1927 +++ b/arch/arm/kernel/armksyms.c
1928 @@ -89,8 +89,8 @@ EXPORT_SYMBOL(__memzero);
1929 #ifdef CONFIG_MMU
1930 EXPORT_SYMBOL(copy_page);
1931
1932 -EXPORT_SYMBOL(__copy_from_user);
1933 -EXPORT_SYMBOL(__copy_to_user);
1934 +EXPORT_SYMBOL(___copy_from_user);
1935 +EXPORT_SYMBOL(___copy_to_user);
1936 EXPORT_SYMBOL(__clear_user);
1937
1938 EXPORT_SYMBOL(__get_user_1);
1939 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
1940 index 486a15a..d95523a 100644
1941 --- a/arch/arm/kernel/head.S
1942 +++ b/arch/arm/kernel/head.S
1943 @@ -52,7 +52,9 @@
1944 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
1945
1946 .macro pgtbl, rd, phys
1947 - add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
1948 + mov \rd, #TEXT_OFFSET
1949 + sub \rd, #PG_DIR_SIZE
1950 + add \rd, \rd, \phys
1951 .endm
1952
1953 /*
1954 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
1955 index 1e9be5d..03edbc2 100644
1956 --- a/arch/arm/kernel/module.c
1957 +++ b/arch/arm/kernel/module.c
1958 @@ -37,12 +37,37 @@
1959 #endif
1960
1961 #ifdef CONFIG_MMU
1962 -void *module_alloc(unsigned long size)
1963 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
1964 {
1965 + if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
1966 + return NULL;
1967 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
1968 - GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
1969 + GFP_KERNEL, prot, -1,
1970 __builtin_return_address(0));
1971 }
1972 +
1973 +void *module_alloc(unsigned long size)
1974 +{
1975 +
1976 +#ifdef CONFIG_PAX_KERNEXEC
1977 + return __module_alloc(size, PAGE_KERNEL);
1978 +#else
1979 + return __module_alloc(size, PAGE_KERNEL_EXEC);
1980 +#endif
1981 +
1982 +}
1983 +
1984 +#ifdef CONFIG_PAX_KERNEXEC
1985 +void module_free_exec(struct module *mod, void *module_region)
1986 +{
1987 + module_free(mod, module_region);
1988 +}
1989 +
1990 +void *module_alloc_exec(unsigned long size)
1991 +{
1992 + return __module_alloc(size, PAGE_KERNEL_EXEC);
1993 +}
1994 +#endif
1995 #endif
1996
1997 int
1998 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1999 index 90084a6..a8b26bc 100644
2000 --- a/arch/arm/kernel/process.c
2001 +++ b/arch/arm/kernel/process.c
2002 @@ -28,7 +28,6 @@
2003 #include <linux/tick.h>
2004 #include <linux/utsname.h>
2005 #include <linux/uaccess.h>
2006 -#include <linux/random.h>
2007 #include <linux/hw_breakpoint.h>
2008 #include <linux/cpuidle.h>
2009 #include <linux/leds.h>
2010 @@ -256,9 +255,10 @@ void machine_power_off(void)
2011 machine_shutdown();
2012 if (pm_power_off)
2013 pm_power_off();
2014 + BUG();
2015 }
2016
2017 -void machine_restart(char *cmd)
2018 +__noreturn void machine_restart(char *cmd)
2019 {
2020 machine_shutdown();
2021
2022 @@ -283,8 +283,8 @@ void __show_regs(struct pt_regs *regs)
2023 init_utsname()->release,
2024 (int)strcspn(init_utsname()->version, " "),
2025 init_utsname()->version);
2026 - print_symbol("PC is at %s\n", instruction_pointer(regs));
2027 - print_symbol("LR is at %s\n", regs->ARM_lr);
2028 + printk("PC is at %pA\n", instruction_pointer(regs));
2029 + printk("LR is at %pA\n", regs->ARM_lr);
2030 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2031 "sp : %08lx ip : %08lx fp : %08lx\n",
2032 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2033 @@ -451,12 +451,6 @@ unsigned long get_wchan(struct task_struct *p)
2034 return 0;
2035 }
2036
2037 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2038 -{
2039 - unsigned long range_end = mm->brk + 0x02000000;
2040 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2041 -}
2042 -
2043 #ifdef CONFIG_MMU
2044 /*
2045 * The vectors page is always readable from user space for the
2046 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2047 index 739db3a..7f4a272 100644
2048 --- a/arch/arm/kernel/ptrace.c
2049 +++ b/arch/arm/kernel/ptrace.c
2050 @@ -916,6 +916,10 @@ enum ptrace_syscall_dir {
2051 PTRACE_SYSCALL_EXIT,
2052 };
2053
2054 +#ifdef CONFIG_GRKERNSEC_SETXID
2055 +extern void gr_delayed_cred_worker(void);
2056 +#endif
2057 +
2058 static int ptrace_syscall_trace(struct pt_regs *regs, int scno,
2059 enum ptrace_syscall_dir dir)
2060 {
2061 @@ -923,6 +927,11 @@ static int ptrace_syscall_trace(struct pt_regs *regs, int scno,
2062
2063 current_thread_info()->syscall = scno;
2064
2065 +#ifdef CONFIG_GRKERNSEC_SETXID
2066 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2067 + gr_delayed_cred_worker();
2068 +#endif
2069 +
2070 if (!test_thread_flag(TIF_SYSCALL_TRACE))
2071 return scno;
2072
2073 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2074 index da1d1aa..ef9bc58 100644
2075 --- a/arch/arm/kernel/setup.c
2076 +++ b/arch/arm/kernel/setup.c
2077 @@ -97,21 +97,23 @@ EXPORT_SYMBOL(system_serial_high);
2078 unsigned int elf_hwcap __read_mostly;
2079 EXPORT_SYMBOL(elf_hwcap);
2080
2081 +pteval_t __supported_pte_mask __read_only;
2082 +pmdval_t __supported_pmd_mask __read_only;
2083
2084 #ifdef MULTI_CPU
2085 -struct processor processor __read_mostly;
2086 +struct processor processor;
2087 #endif
2088 #ifdef MULTI_TLB
2089 -struct cpu_tlb_fns cpu_tlb __read_mostly;
2090 +struct cpu_tlb_fns cpu_tlb __read_only;
2091 #endif
2092 #ifdef MULTI_USER
2093 -struct cpu_user_fns cpu_user __read_mostly;
2094 +struct cpu_user_fns cpu_user __read_only;
2095 #endif
2096 #ifdef MULTI_CACHE
2097 -struct cpu_cache_fns cpu_cache __read_mostly;
2098 +struct cpu_cache_fns cpu_cache __read_only;
2099 #endif
2100 #ifdef CONFIG_OUTER_CACHE
2101 -struct outer_cache_fns outer_cache __read_mostly;
2102 +struct outer_cache_fns outer_cache __read_only;
2103 EXPORT_SYMBOL(outer_cache);
2104 #endif
2105
2106 @@ -236,9 +238,13 @@ static int __get_cpu_architecture(void)
2107 asm("mrc p15, 0, %0, c0, c1, 4"
2108 : "=r" (mmfr0));
2109 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2110 - (mmfr0 & 0x000000f0) >= 0x00000030)
2111 + (mmfr0 & 0x000000f0) >= 0x00000030) {
2112 cpu_arch = CPU_ARCH_ARMv7;
2113 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2114 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2115 + __supported_pte_mask |= L_PTE_PXN;
2116 + __supported_pmd_mask |= PMD_PXNTABLE;
2117 + }
2118 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2119 (mmfr0 & 0x000000f0) == 0x00000020)
2120 cpu_arch = CPU_ARCH_ARMv6;
2121 else
2122 @@ -455,7 +461,7 @@ static void __init setup_processor(void)
2123 __cpu_architecture = __get_cpu_architecture();
2124
2125 #ifdef MULTI_CPU
2126 - processor = *list->proc;
2127 + memcpy((void *)&processor, list->proc, sizeof processor);
2128 #endif
2129 #ifdef MULTI_TLB
2130 cpu_tlb = *list->tlb;
2131 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
2132 index fbc8b26..000ded0 100644
2133 --- a/arch/arm/kernel/smp.c
2134 +++ b/arch/arm/kernel/smp.c
2135 @@ -70,7 +70,7 @@ enum ipi_msg_type {
2136
2137 static DECLARE_COMPLETION(cpu_running);
2138
2139 -static struct smp_operations smp_ops;
2140 +static struct smp_operations smp_ops __read_only;
2141
2142 void __init smp_set_ops(struct smp_operations *ops)
2143 {
2144 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
2145 index b0179b8..7713948 100644
2146 --- a/arch/arm/kernel/traps.c
2147 +++ b/arch/arm/kernel/traps.c
2148 @@ -57,7 +57,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
2149 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
2150 {
2151 #ifdef CONFIG_KALLSYMS
2152 - printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
2153 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
2154 #else
2155 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
2156 #endif
2157 @@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
2158 static int die_owner = -1;
2159 static unsigned int die_nest_count;
2160
2161 +extern void gr_handle_kernel_exploit(void);
2162 +
2163 static unsigned long oops_begin(void)
2164 {
2165 int cpu;
2166 @@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
2167 panic("Fatal exception in interrupt");
2168 if (panic_on_oops)
2169 panic("Fatal exception");
2170 +
2171 + gr_handle_kernel_exploit();
2172 +
2173 if (signr)
2174 do_exit(signr);
2175 }
2176 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
2177 index 36ff15b..75d9e9d 100644
2178 --- a/arch/arm/kernel/vmlinux.lds.S
2179 +++ b/arch/arm/kernel/vmlinux.lds.S
2180 @@ -8,7 +8,11 @@
2181 #include <asm/thread_info.h>
2182 #include <asm/memory.h>
2183 #include <asm/page.h>
2184 -
2185 +
2186 +#ifdef CONFIG_PAX_KERNEXEC
2187 +#include <asm/pgtable.h>
2188 +#endif
2189 +
2190 #define PROC_INFO \
2191 . = ALIGN(4); \
2192 VMLINUX_SYMBOL(__proc_info_begin) = .; \
2193 @@ -90,6 +94,11 @@ SECTIONS
2194 _text = .;
2195 HEAD_TEXT
2196 }
2197 +
2198 +#ifdef CONFIG_PAX_KERNEXEC
2199 + . = ALIGN(1<<SECTION_SHIFT);
2200 +#endif
2201 +
2202 .text : { /* Real text segment */
2203 _stext = .; /* Text and read-only data */
2204 __exception_text_start = .;
2205 @@ -133,6 +142,10 @@ SECTIONS
2206
2207 _etext = .; /* End of text and rodata section */
2208
2209 +#ifdef CONFIG_PAX_KERNEXEC
2210 + . = ALIGN(1<<SECTION_SHIFT);
2211 +#endif
2212 +
2213 #ifndef CONFIG_XIP_KERNEL
2214 . = ALIGN(PAGE_SIZE);
2215 __init_begin = .;
2216 @@ -192,6 +205,11 @@ SECTIONS
2217 . = PAGE_OFFSET + TEXT_OFFSET;
2218 #else
2219 __init_end = .;
2220 +
2221 +#ifdef CONFIG_PAX_KERNEXEC
2222 + . = ALIGN(1<<SECTION_SHIFT);
2223 +#endif
2224 +
2225 . = ALIGN(THREAD_SIZE);
2226 __data_loc = .;
2227 #endif
2228 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
2229 index 66a477a..bee61d3 100644
2230 --- a/arch/arm/lib/copy_from_user.S
2231 +++ b/arch/arm/lib/copy_from_user.S
2232 @@ -16,7 +16,7 @@
2233 /*
2234 * Prototype:
2235 *
2236 - * size_t __copy_from_user(void *to, const void *from, size_t n)
2237 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
2238 *
2239 * Purpose:
2240 *
2241 @@ -84,11 +84,11 @@
2242
2243 .text
2244
2245 -ENTRY(__copy_from_user)
2246 +ENTRY(___copy_from_user)
2247
2248 #include "copy_template.S"
2249
2250 -ENDPROC(__copy_from_user)
2251 +ENDPROC(___copy_from_user)
2252
2253 .pushsection .fixup,"ax"
2254 .align 0
2255 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
2256 index 6ee2f67..d1cce76 100644
2257 --- a/arch/arm/lib/copy_page.S
2258 +++ b/arch/arm/lib/copy_page.S
2259 @@ -10,6 +10,7 @@
2260 * ASM optimised string functions
2261 */
2262 #include <linux/linkage.h>
2263 +#include <linux/const.h>
2264 #include <asm/assembler.h>
2265 #include <asm/asm-offsets.h>
2266 #include <asm/cache.h>
2267 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
2268 index d066df6..df28194 100644
2269 --- a/arch/arm/lib/copy_to_user.S
2270 +++ b/arch/arm/lib/copy_to_user.S
2271 @@ -16,7 +16,7 @@
2272 /*
2273 * Prototype:
2274 *
2275 - * size_t __copy_to_user(void *to, const void *from, size_t n)
2276 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
2277 *
2278 * Purpose:
2279 *
2280 @@ -88,11 +88,11 @@
2281 .text
2282
2283 ENTRY(__copy_to_user_std)
2284 -WEAK(__copy_to_user)
2285 +WEAK(___copy_to_user)
2286
2287 #include "copy_template.S"
2288
2289 -ENDPROC(__copy_to_user)
2290 +ENDPROC(___copy_to_user)
2291 ENDPROC(__copy_to_user_std)
2292
2293 .pushsection .fixup,"ax"
2294 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
2295 index 0dc5385..45833ef 100644
2296 --- a/arch/arm/lib/delay.c
2297 +++ b/arch/arm/lib/delay.c
2298 @@ -28,12 +28,14 @@
2299 /*
2300 * Default to the loop-based delay implementation.
2301 */
2302 -struct arm_delay_ops arm_delay_ops = {
2303 +static struct arm_delay_ops arm_loop_delay_ops = {
2304 .delay = __loop_delay,
2305 .const_udelay = __loop_const_udelay,
2306 .udelay = __loop_udelay,
2307 };
2308
2309 +struct arm_delay_ops *arm_delay_ops __read_only = &arm_loop_delay_ops;
2310 +
2311 static const struct delay_timer *delay_timer;
2312 static bool delay_calibrated;
2313
2314 @@ -67,6 +69,12 @@ static void __timer_udelay(unsigned long usecs)
2315 __timer_const_udelay(usecs * UDELAY_MULT);
2316 }
2317
2318 +static struct arm_delay_ops arm_timer_delay_ops = {
2319 + .delay = __timer_delay,
2320 + .const_udelay = __timer_const_udelay,
2321 + .udelay = __timer_udelay,
2322 +};
2323 +
2324 void __init register_current_timer_delay(const struct delay_timer *timer)
2325 {
2326 if (!delay_calibrated) {
2327 @@ -74,9 +82,7 @@ void __init register_current_timer_delay(const struct delay_timer *timer)
2328 delay_timer = timer;
2329 lpj_fine = timer->freq / HZ;
2330 loops_per_jiffy = lpj_fine;
2331 - arm_delay_ops.delay = __timer_delay;
2332 - arm_delay_ops.const_udelay = __timer_const_udelay;
2333 - arm_delay_ops.udelay = __timer_udelay;
2334 + arm_delay_ops = &arm_timer_delay_ops;
2335 delay_calibrated = true;
2336 } else {
2337 pr_info("Ignoring duplicate/late registration of read_current_timer delay\n");
2338 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
2339 index 025f742..8432b08 100644
2340 --- a/arch/arm/lib/uaccess_with_memcpy.c
2341 +++ b/arch/arm/lib/uaccess_with_memcpy.c
2342 @@ -104,7 +104,7 @@ out:
2343 }
2344
2345 unsigned long
2346 -__copy_to_user(void __user *to, const void *from, unsigned long n)
2347 +___copy_to_user(void __user *to, const void *from, unsigned long n)
2348 {
2349 /*
2350 * This test is stubbed out of the main function above to keep
2351 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
2352 index 2c6c218..2b87c2d 100644
2353 --- a/arch/arm/mach-kirkwood/common.c
2354 +++ b/arch/arm/mach-kirkwood/common.c
2355 @@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
2356 clk_gate_ops.disable(hw);
2357 }
2358
2359 -static struct clk_ops clk_gate_fn_ops;
2360 +static int clk_gate_fn_is_enabled(struct clk_hw *hw)
2361 +{
2362 + return clk_gate_ops.is_enabled(hw);
2363 +}
2364 +
2365 +static struct clk_ops clk_gate_fn_ops = {
2366 + .enable = clk_gate_fn_enable,
2367 + .disable = clk_gate_fn_disable,
2368 + .is_enabled = clk_gate_fn_is_enabled,
2369 +};
2370
2371 static struct clk __init *clk_register_gate_fn(struct device *dev,
2372 const char *name,
2373 @@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
2374 gate_fn->fn_en = fn_en;
2375 gate_fn->fn_dis = fn_dis;
2376
2377 - /* ops is the gate ops, but with our enable/disable functions */
2378 - if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
2379 - clk_gate_fn_ops.disable != clk_gate_fn_disable) {
2380 - clk_gate_fn_ops = clk_gate_ops;
2381 - clk_gate_fn_ops.enable = clk_gate_fn_enable;
2382 - clk_gate_fn_ops.disable = clk_gate_fn_disable;
2383 - }
2384 -
2385 clk = clk_register(dev, &gate_fn->gate.hw);
2386
2387 if (IS_ERR(clk))
2388 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
2389 index d95f727..12f10dd 100644
2390 --- a/arch/arm/mach-omap2/board-n8x0.c
2391 +++ b/arch/arm/mach-omap2/board-n8x0.c
2392 @@ -589,7 +589,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
2393 }
2394 #endif
2395
2396 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
2397 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
2398 .late_init = n8x0_menelaus_late_init,
2399 };
2400
2401 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
2402 index 87cc6d0..fd4f248 100644
2403 --- a/arch/arm/mach-omap2/omap_hwmod.c
2404 +++ b/arch/arm/mach-omap2/omap_hwmod.c
2405 @@ -189,10 +189,10 @@ struct omap_hwmod_soc_ops {
2406 int (*is_hardreset_asserted)(struct omap_hwmod *oh,
2407 struct omap_hwmod_rst_info *ohri);
2408 int (*init_clkdm)(struct omap_hwmod *oh);
2409 -};
2410 +} __no_const;
2411
2412 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
2413 -static struct omap_hwmod_soc_ops soc_ops;
2414 +static struct omap_hwmod_soc_ops soc_ops __read_only;
2415
2416 /* omap_hwmod_list contains all registered struct omap_hwmods */
2417 static LIST_HEAD(omap_hwmod_list);
2418 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
2419 index 5dbf13f..9be36fd 100644
2420 --- a/arch/arm/mm/fault.c
2421 +++ b/arch/arm/mm/fault.c
2422 @@ -25,6 +25,7 @@
2423 #include <asm/system_misc.h>
2424 #include <asm/system_info.h>
2425 #include <asm/tlbflush.h>
2426 +#include <asm/sections.h>
2427
2428 #include "fault.h"
2429
2430 @@ -138,6 +139,19 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
2431 if (fixup_exception(regs))
2432 return;
2433
2434 +#ifdef CONFIG_PAX_KERNEXEC
2435 + if (fsr & FSR_WRITE) {
2436 + if (((unsigned long)_stext <= addr && addr < init_mm.end_code) || (MODULES_VADDR <= addr && addr < MODULES_END)) {
2437 + if (current->signal->curr_ip)
2438 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
2439 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
2440 + else
2441 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
2442 + current->comm, task_pid_nr(current), current_uid(), current_euid());
2443 + }
2444 + }
2445 +#endif
2446 +
2447 /*
2448 * No handler, we'll have to terminate things with extreme prejudice.
2449 */
2450 @@ -174,6 +188,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
2451 }
2452 #endif
2453
2454 +#ifdef CONFIG_PAX_PAGEEXEC
2455 + if (fsr & FSR_LNX_PF) {
2456 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
2457 + do_group_exit(SIGKILL);
2458 + }
2459 +#endif
2460 +
2461 tsk->thread.address = addr;
2462 tsk->thread.error_code = fsr;
2463 tsk->thread.trap_no = 14;
2464 @@ -398,6 +419,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
2465 }
2466 #endif /* CONFIG_MMU */
2467
2468 +#ifdef CONFIG_PAX_PAGEEXEC
2469 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2470 +{
2471 + long i;
2472 +
2473 + printk(KERN_ERR "PAX: bytes at PC: ");
2474 + for (i = 0; i < 20; i++) {
2475 + unsigned char c;
2476 + if (get_user(c, (__force unsigned char __user *)pc+i))
2477 + printk(KERN_CONT "?? ");
2478 + else
2479 + printk(KERN_CONT "%02x ", c);
2480 + }
2481 + printk("\n");
2482 +
2483 + printk(KERN_ERR "PAX: bytes at SP-4: ");
2484 + for (i = -1; i < 20; i++) {
2485 + unsigned long c;
2486 + if (get_user(c, (__force unsigned long __user *)sp+i))
2487 + printk(KERN_CONT "???????? ");
2488 + else
2489 + printk(KERN_CONT "%08lx ", c);
2490 + }
2491 + printk("\n");
2492 +}
2493 +#endif
2494 +
2495 /*
2496 * First Level Translation Fault Handler
2497 *
2498 @@ -575,12 +623,41 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
2499 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
2500 struct siginfo info;
2501
2502 +#ifdef CONFIG_PAX_KERNEXEC
2503 + if (!user_mode(regs) && is_xn_fault(ifsr)) {
2504 + if (current->signal->curr_ip)
2505 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n",
2506 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid(),
2507 + addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
2508 + else
2509 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n",
2510 + current->comm, task_pid_nr(current), current_uid(), current_euid(),
2511 + addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
2512 + goto die;
2513 + }
2514 +#endif
2515 +
2516 +#ifdef CONFIG_PAX_REFCOUNT
2517 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
2518 + unsigned int bkpt;
2519 +
2520 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
2521 + current->thread.error_code = ifsr;
2522 + current->thread.trap_no = 0;
2523 + pax_report_refcount_overflow(regs);
2524 + fixup_exception(regs);
2525 + return;
2526 + }
2527 + }
2528 +#endif
2529 +
2530 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
2531 return;
2532
2533 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
2534 inf->name, ifsr, addr);
2535
2536 +die:
2537 info.si_signo = inf->sig;
2538 info.si_errno = 0;
2539 info.si_code = inf->code;
2540 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
2541 index cf08bdf..f1a0383 100644
2542 --- a/arch/arm/mm/fault.h
2543 +++ b/arch/arm/mm/fault.h
2544 @@ -3,6 +3,7 @@
2545
2546 /*
2547 * Fault status register encodings. We steal bit 31 for our own purposes.
2548 + * Set when the FSR value is from an instruction fault.
2549 */
2550 #define FSR_LNX_PF (1 << 31)
2551 #define FSR_WRITE (1 << 11)
2552 @@ -22,6 +23,12 @@ static inline int fsr_fs(unsigned int fsr)
2553 }
2554 #endif
2555
2556 +/* valid for LPAE and !LPAE */
2557 +static inline int is_xn_fault(unsigned int fsr)
2558 +{
2559 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
2560 +}
2561 +
2562 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
2563 unsigned long search_exception_table(unsigned long addr);
2564
2565 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
2566 index ad722f1..46b670e 100644
2567 --- a/arch/arm/mm/init.c
2568 +++ b/arch/arm/mm/init.c
2569 @@ -734,9 +734,43 @@ void __init mem_init(void)
2570
2571 void free_initmem(void)
2572 {
2573 +
2574 +#ifdef CONFIG_PAX_KERNEXEC
2575 + unsigned long addr;
2576 + pgd_t *pgd;
2577 + pud_t *pud;
2578 + pmd_t *pmd;
2579 +#endif
2580 +
2581 #ifdef CONFIG_HAVE_TCM
2582 extern char __tcm_start, __tcm_end;
2583 +#endif
2584
2585 +#ifdef CONFIG_PAX_KERNEXEC
2586 + /* make pages tables, etc before .text NX */
2587 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += PMD_SIZE) {
2588 + pgd = pgd_offset_k(addr);
2589 + pud = pud_offset(pgd, addr);
2590 + pmd = pmd_offset(pud, addr);
2591 + __pmd_update(pmd, PMD_SECT_XN);
2592 + }
2593 + /* make init NX */
2594 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += PMD_SIZE) {
2595 + pgd = pgd_offset_k(addr);
2596 + pud = pud_offset(pgd, addr);
2597 + pmd = pmd_offset(pud, addr);
2598 + __pmd_update(pmd, PMD_SECT_XN);
2599 + }
2600 + /* make kernel code/rodata read-only */
2601 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += PMD_SIZE) {
2602 + pgd = pgd_offset_k(addr);
2603 + pud = pud_offset(pgd, addr);
2604 + pmd = pmd_offset(pud, addr);
2605 + __pmd_update(pmd, PMD_SECT_AP_RDONLY);
2606 + }
2607 +#endif
2608 +
2609 +#ifdef CONFIG_HAVE_TCM
2610 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
2611 totalram_pages += free_area(__phys_to_pfn(__pa(&__tcm_start)),
2612 __phys_to_pfn(__pa(&__tcm_end)),
2613 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
2614 index ce8cb19..061aa14 100644
2615 --- a/arch/arm/mm/mmap.c
2616 +++ b/arch/arm/mm/mmap.c
2617 @@ -72,6 +72,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
2618 unsigned long start_addr;
2619 int do_align = 0;
2620 int aliasing = cache_is_vipt_aliasing();
2621 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
2622
2623 /*
2624 * We only need to do colour alignment if either the I or D
2625 @@ -93,6 +94,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
2626 if (len > TASK_SIZE)
2627 return -ENOMEM;
2628
2629 +#ifdef CONFIG_PAX_RANDMMAP
2630 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
2631 +#endif
2632 +
2633 if (addr) {
2634 if (do_align)
2635 addr = COLOUR_ALIGN(addr, pgoff);
2636 @@ -100,15 +105,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
2637 addr = PAGE_ALIGN(addr);
2638
2639 vma = find_vma(mm, addr);
2640 - if (TASK_SIZE - len >= addr &&
2641 - (!vma || addr + len <= vma->vm_start))
2642 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
2643 return addr;
2644 }
2645 if (len > mm->cached_hole_size) {
2646 - start_addr = addr = mm->free_area_cache;
2647 + start_addr = addr = mm->free_area_cache;
2648 } else {
2649 - start_addr = addr = mm->mmap_base;
2650 - mm->cached_hole_size = 0;
2651 + start_addr = addr = mm->mmap_base;
2652 + mm->cached_hole_size = 0;
2653 }
2654
2655 full_search:
2656 @@ -124,14 +128,14 @@ full_search:
2657 * Start a new search - just in case we missed
2658 * some holes.
2659 */
2660 - if (start_addr != TASK_UNMAPPED_BASE) {
2661 - start_addr = addr = TASK_UNMAPPED_BASE;
2662 + if (start_addr != mm->mmap_base) {
2663 + start_addr = addr = mm->mmap_base;
2664 mm->cached_hole_size = 0;
2665 goto full_search;
2666 }
2667 return -ENOMEM;
2668 }
2669 - if (!vma || addr + len <= vma->vm_start) {
2670 + if (check_heap_stack_gap(vma, addr, len, offset)) {
2671 /*
2672 * Remember the place where we stopped the search:
2673 */
2674 @@ -156,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2675 unsigned long addr = addr0;
2676 int do_align = 0;
2677 int aliasing = cache_is_vipt_aliasing();
2678 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
2679
2680 /*
2681 * We only need to do colour alignment if either the I or D
2682 @@ -175,6 +180,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2683 return addr;
2684 }
2685
2686 +#ifdef CONFIG_PAX_RANDMMAP
2687 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
2688 +#endif
2689 +
2690 /* requesting a specific address */
2691 if (addr) {
2692 if (do_align)
2693 @@ -182,8 +191,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2694 else
2695 addr = PAGE_ALIGN(addr);
2696 vma = find_vma(mm, addr);
2697 - if (TASK_SIZE - len >= addr &&
2698 - (!vma || addr + len <= vma->vm_start))
2699 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
2700 return addr;
2701 }
2702
2703 @@ -203,7 +211,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2704 /* make sure it can fit in the remaining address space */
2705 if (addr > len) {
2706 vma = find_vma(mm, addr-len);
2707 - if (!vma || addr <= vma->vm_start)
2708 + if (check_heap_stack_gap(vma, addr - len, len, offset))
2709 /* remember the address as a hint for next time */
2710 return (mm->free_area_cache = addr-len);
2711 }
2712 @@ -212,17 +220,17 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2713 goto bottomup;
2714
2715 addr = mm->mmap_base - len;
2716 - if (do_align)
2717 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
2718
2719 do {
2720 + if (do_align)
2721 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
2722 /*
2723 * Lookup failure means no vma is above this address,
2724 * else if new region fits below vma->vm_start,
2725 * return with success:
2726 */
2727 vma = find_vma(mm, addr);
2728 - if (!vma || addr+len <= vma->vm_start)
2729 + if (check_heap_stack_gap(vma, addr, len, offset))
2730 /* remember the address as a hint for next time */
2731 return (mm->free_area_cache = addr);
2732
2733 @@ -231,10 +239,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2734 mm->cached_hole_size = vma->vm_start - addr;
2735
2736 /* try just below the current vma->vm_start */
2737 - addr = vma->vm_start - len;
2738 - if (do_align)
2739 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
2740 - } while (len < vma->vm_start);
2741 + addr = skip_heap_stack_gap(vma, len, offset);
2742 + } while (!IS_ERR_VALUE(addr));
2743
2744 bottomup:
2745 /*
2746 @@ -259,6 +265,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2747 {
2748 unsigned long random_factor = 0UL;
2749
2750 +#ifdef CONFIG_PAX_RANDMMAP
2751 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
2752 +#endif
2753 +
2754 /* 8 bits of randomness in 20 address space bits */
2755 if ((current->flags & PF_RANDOMIZE) &&
2756 !(current->personality & ADDR_NO_RANDOMIZE))
2757 @@ -266,10 +276,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2758
2759 if (mmap_is_legacy()) {
2760 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
2761 +
2762 +#ifdef CONFIG_PAX_RANDMMAP
2763 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2764 + mm->mmap_base += mm->delta_mmap;
2765 +#endif
2766 +
2767 mm->get_unmapped_area = arch_get_unmapped_area;
2768 mm->unmap_area = arch_unmap_area;
2769 } else {
2770 mm->mmap_base = mmap_base(random_factor);
2771 +
2772 +#ifdef CONFIG_PAX_RANDMMAP
2773 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2774 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2775 +#endif
2776 +
2777 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2778 mm->unmap_area = arch_unmap_area_topdown;
2779 }
2780 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
2781 index 99b47b9..579b667 100644
2782 --- a/arch/arm/mm/mmu.c
2783 +++ b/arch/arm/mm/mmu.c
2784 @@ -227,16 +227,16 @@ static struct mem_type mem_types[] = {
2785 [MT_UNCACHED] = {
2786 .prot_pte = PROT_PTE_DEVICE,
2787 .prot_l1 = PMD_TYPE_TABLE,
2788 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
2789 + .prot_sect = PROT_SECT_DEVICE | PMD_SECT_XN,
2790 .domain = DOMAIN_IO,
2791 },
2792 [MT_CACHECLEAN] = {
2793 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
2794 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_AP_RDONLY,
2795 .domain = DOMAIN_KERNEL,
2796 },
2797 #ifndef CONFIG_ARM_LPAE
2798 [MT_MINICLEAN] = {
2799 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
2800 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE | PMD_SECT_AP_RDONLY,
2801 .domain = DOMAIN_KERNEL,
2802 },
2803 #endif
2804 @@ -258,8 +258,26 @@ static struct mem_type mem_types[] = {
2805 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
2806 .domain = DOMAIN_KERNEL,
2807 },
2808 + [MT_MEMORY_R] = {
2809 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_RDONLY | L_PTE_XN,
2810 + .prot_l1 = PMD_TYPE_TABLE,
2811 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_RDONLY | PMD_SECT_XN,
2812 + .domain = DOMAIN_KERNEL,
2813 + },
2814 + [MT_MEMORY_RW] = {
2815 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY | L_PTE_XN,
2816 + .prot_l1 = PMD_TYPE_TABLE,
2817 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_XN,
2818 + .domain = DOMAIN_KERNEL,
2819 + },
2820 + [MT_MEMORY_RX] = {
2821 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_RDONLY,
2822 + .prot_l1 = PMD_TYPE_TABLE,
2823 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_RDONLY,
2824 + .domain = DOMAIN_KERNEL,
2825 + },
2826 [MT_ROM] = {
2827 - .prot_sect = PMD_TYPE_SECT,
2828 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_RDONLY,
2829 .domain = DOMAIN_KERNEL,
2830 },
2831 [MT_MEMORY_NONCACHED] = {
2832 @@ -273,7 +291,7 @@ static struct mem_type mem_types[] = {
2833 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
2834 L_PTE_XN,
2835 .prot_l1 = PMD_TYPE_TABLE,
2836 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
2837 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_AP_RDONLY,
2838 .domain = DOMAIN_KERNEL,
2839 },
2840 [MT_MEMORY_ITCM] = {
2841 @@ -432,6 +450,8 @@ static void __init build_mem_type_table(void)
2842 * from SVC mode and no access from userspace.
2843 */
2844 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2845 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2846 + mem_types[MT_MEMORY_R].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2847 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2848 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2849 #endif
2850 @@ -450,6 +470,12 @@ static void __init build_mem_type_table(void)
2851 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
2852 mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
2853 mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
2854 + mem_types[MT_MEMORY_R].prot_sect |= PMD_SECT_S;
2855 + mem_types[MT_MEMORY_R].prot_pte |= L_PTE_SHARED;
2856 + mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
2857 + mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
2858 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
2859 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
2860 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
2861 mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
2862 mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
2863 @@ -487,6 +513,8 @@ static void __init build_mem_type_table(void)
2864 vecs_pgprot |= PTE_EXT_AF;
2865 #endif
2866
2867 + user_pgprot |= __supported_pte_mask;
2868 +
2869 for (i = 0; i < 16; i++) {
2870 pteval_t v = pgprot_val(protection_map[i]);
2871 protection_map[i] = __pgprot(v | user_pgprot);
2872 @@ -503,6 +531,12 @@ static void __init build_mem_type_table(void)
2873 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
2874 mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
2875 mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
2876 + mem_types[MT_MEMORY_R].prot_sect |= ecc_mask | cp->pmd;
2877 + mem_types[MT_MEMORY_R].prot_pte |= kern_pgprot;
2878 + mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
2879 + mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
2880 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
2881 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
2882 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
2883 mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
2884 mem_types[MT_ROM].prot_sect |= cp->pmd;
2885 @@ -1198,7 +1232,41 @@ static void __init map_lowmem(void)
2886 map.pfn = __phys_to_pfn(start);
2887 map.virtual = __phys_to_virt(start);
2888 map.length = end - start;
2889 +
2890 +#ifdef CONFIG_PAX_KERNEXEC
2891 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
2892 + struct map_desc kernel;
2893 + struct map_desc initmap;
2894 +
2895 + /* when freeing initmem we will make this RW */
2896 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
2897 + initmap.virtual = (unsigned long)__init_begin;
2898 + initmap.length = _sdata - __init_begin;
2899 + initmap.type = MT_MEMORY;
2900 + create_mapping(&initmap);
2901 +
2902 + /* when freeing initmem we will make this RX */
2903 + kernel.pfn = __phys_to_pfn(__pa(_stext));
2904 + kernel.virtual = (unsigned long)_stext;
2905 + kernel.length = __init_begin - _stext;
2906 + kernel.type = MT_MEMORY;
2907 + create_mapping(&kernel);
2908 +
2909 + if (map.virtual < (unsigned long)_stext) {
2910 + map.length = (unsigned long)_stext - map.virtual;
2911 + map.type = MT_MEMORY;
2912 + create_mapping(&map);
2913 + }
2914 +
2915 + map.pfn = __phys_to_pfn(__pa(_sdata));
2916 + map.virtual = (unsigned long)_sdata;
2917 + map.length = end - __pa(_sdata);
2918 + }
2919 +
2920 + map.type = MT_MEMORY_RW;
2921 +#else
2922 map.type = MT_MEMORY;
2923 +#endif
2924
2925 create_mapping(&map);
2926 }
2927 diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2928 index ec63e4a..62aa5f1d 100644
2929 --- a/arch/arm/plat-orion/include/plat/addr-map.h
2930 +++ b/arch/arm/plat-orion/include/plat/addr-map.h
2931 @@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2932 value in bridge_virt_base */
2933 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2934 const int win);
2935 -};
2936 +} __no_const;
2937
2938 /*
2939 * Information needed to setup one address mapping.
2940 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2941 index f5144cd..71f6d1f 100644
2942 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2943 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2944 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
2945 int (*started)(unsigned ch);
2946 int (*flush)(unsigned ch);
2947 int (*stop)(unsigned ch);
2948 -};
2949 +} __no_const;
2950
2951 extern void *samsung_dmadev_get_ops(void);
2952 extern void *s3c_dma_get_ops(void);
2953 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2954 index c3a58a1..78fbf54 100644
2955 --- a/arch/avr32/include/asm/cache.h
2956 +++ b/arch/avr32/include/asm/cache.h
2957 @@ -1,8 +1,10 @@
2958 #ifndef __ASM_AVR32_CACHE_H
2959 #define __ASM_AVR32_CACHE_H
2960
2961 +#include <linux/const.h>
2962 +
2963 #define L1_CACHE_SHIFT 5
2964 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2965 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2966
2967 /*
2968 * Memory returned by kmalloc() may be used for DMA, so we must make
2969 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2970 index e2c3287..6c4f98c 100644
2971 --- a/arch/avr32/include/asm/elf.h
2972 +++ b/arch/avr32/include/asm/elf.h
2973 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2974 the loader. We need to make sure that it is out of the way of the program
2975 that it will "exec", and that there is sufficient room for the brk. */
2976
2977 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2978 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2979
2980 +#ifdef CONFIG_PAX_ASLR
2981 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2982 +
2983 +#define PAX_DELTA_MMAP_LEN 15
2984 +#define PAX_DELTA_STACK_LEN 15
2985 +#endif
2986
2987 /* This yields a mask that user programs can use to figure out what
2988 instruction set this CPU supports. This could be done in user space,
2989 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2990 index 479330b..53717a8 100644
2991 --- a/arch/avr32/include/asm/kmap_types.h
2992 +++ b/arch/avr32/include/asm/kmap_types.h
2993 @@ -2,9 +2,9 @@
2994 #define __ASM_AVR32_KMAP_TYPES_H
2995
2996 #ifdef CONFIG_DEBUG_HIGHMEM
2997 -# define KM_TYPE_NR 29
2998 +# define KM_TYPE_NR 30
2999 #else
3000 -# define KM_TYPE_NR 14
3001 +# define KM_TYPE_NR 15
3002 #endif
3003
3004 #endif /* __ASM_AVR32_KMAP_TYPES_H */
3005 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
3006 index b2f2d2d..d1c85cb 100644
3007 --- a/arch/avr32/mm/fault.c
3008 +++ b/arch/avr32/mm/fault.c
3009 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
3010
3011 int exception_trace = 1;
3012
3013 +#ifdef CONFIG_PAX_PAGEEXEC
3014 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3015 +{
3016 + unsigned long i;
3017 +
3018 + printk(KERN_ERR "PAX: bytes at PC: ");
3019 + for (i = 0; i < 20; i++) {
3020 + unsigned char c;
3021 + if (get_user(c, (unsigned char *)pc+i))
3022 + printk(KERN_CONT "???????? ");
3023 + else
3024 + printk(KERN_CONT "%02x ", c);
3025 + }
3026 + printk("\n");
3027 +}
3028 +#endif
3029 +
3030 /*
3031 * This routine handles page faults. It determines the address and the
3032 * problem, and then passes it off to one of the appropriate routines.
3033 @@ -174,6 +191,16 @@ bad_area:
3034 up_read(&mm->mmap_sem);
3035
3036 if (user_mode(regs)) {
3037 +
3038 +#ifdef CONFIG_PAX_PAGEEXEC
3039 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
3040 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
3041 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
3042 + do_group_exit(SIGKILL);
3043 + }
3044 + }
3045 +#endif
3046 +
3047 if (exception_trace && printk_ratelimit())
3048 printk("%s%s[%d]: segfault at %08lx pc %08lx "
3049 "sp %08lx ecr %lu\n",
3050 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
3051 index 568885a..f8008df 100644
3052 --- a/arch/blackfin/include/asm/cache.h
3053 +++ b/arch/blackfin/include/asm/cache.h
3054 @@ -7,6 +7,7 @@
3055 #ifndef __ARCH_BLACKFIN_CACHE_H
3056 #define __ARCH_BLACKFIN_CACHE_H
3057
3058 +#include <linux/const.h>
3059 #include <linux/linkage.h> /* for asmlinkage */
3060
3061 /*
3062 @@ -14,7 +15,7 @@
3063 * Blackfin loads 32 bytes for cache
3064 */
3065 #define L1_CACHE_SHIFT 5
3066 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3067 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3068 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3069
3070 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
3071 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
3072 index aea2718..3639a60 100644
3073 --- a/arch/cris/include/arch-v10/arch/cache.h
3074 +++ b/arch/cris/include/arch-v10/arch/cache.h
3075 @@ -1,8 +1,9 @@
3076 #ifndef _ASM_ARCH_CACHE_H
3077 #define _ASM_ARCH_CACHE_H
3078
3079 +#include <linux/const.h>
3080 /* Etrax 100LX have 32-byte cache-lines. */
3081 -#define L1_CACHE_BYTES 32
3082 #define L1_CACHE_SHIFT 5
3083 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3084
3085 #endif /* _ASM_ARCH_CACHE_H */
3086 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
3087 index 7caf25d..ee65ac5 100644
3088 --- a/arch/cris/include/arch-v32/arch/cache.h
3089 +++ b/arch/cris/include/arch-v32/arch/cache.h
3090 @@ -1,11 +1,12 @@
3091 #ifndef _ASM_CRIS_ARCH_CACHE_H
3092 #define _ASM_CRIS_ARCH_CACHE_H
3093
3094 +#include <linux/const.h>
3095 #include <arch/hwregs/dma.h>
3096
3097 /* A cache-line is 32 bytes. */
3098 -#define L1_CACHE_BYTES 32
3099 #define L1_CACHE_SHIFT 5
3100 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3101
3102 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
3103
3104 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
3105 index b86329d..6709906 100644
3106 --- a/arch/frv/include/asm/atomic.h
3107 +++ b/arch/frv/include/asm/atomic.h
3108 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
3109 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
3110 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
3111
3112 +#define atomic64_read_unchecked(v) atomic64_read(v)
3113 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3114 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3115 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3116 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3117 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3118 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3119 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3120 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3121 +
3122 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
3123 {
3124 int c, old;
3125 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
3126 index 2797163..c2a401d 100644
3127 --- a/arch/frv/include/asm/cache.h
3128 +++ b/arch/frv/include/asm/cache.h
3129 @@ -12,10 +12,11 @@
3130 #ifndef __ASM_CACHE_H
3131 #define __ASM_CACHE_H
3132
3133 +#include <linux/const.h>
3134
3135 /* bytes per L1 cache line */
3136 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
3137 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3138 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3139
3140 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
3141 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
3142 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
3143 index 43901f2..0d8b865 100644
3144 --- a/arch/frv/include/asm/kmap_types.h
3145 +++ b/arch/frv/include/asm/kmap_types.h
3146 @@ -2,6 +2,6 @@
3147 #ifndef _ASM_KMAP_TYPES_H
3148 #define _ASM_KMAP_TYPES_H
3149
3150 -#define KM_TYPE_NR 17
3151 +#define KM_TYPE_NR 18
3152
3153 #endif
3154 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
3155 index 385fd30..3aaf4fe 100644
3156 --- a/arch/frv/mm/elf-fdpic.c
3157 +++ b/arch/frv/mm/elf-fdpic.c
3158 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3159 {
3160 struct vm_area_struct *vma;
3161 unsigned long limit;
3162 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
3163
3164 if (len > TASK_SIZE)
3165 return -ENOMEM;
3166 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3167 if (addr) {
3168 addr = PAGE_ALIGN(addr);
3169 vma = find_vma(current->mm, addr);
3170 - if (TASK_SIZE - len >= addr &&
3171 - (!vma || addr + len <= vma->vm_start))
3172 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3173 goto success;
3174 }
3175
3176 @@ -89,7 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3177 for (; vma; vma = vma->vm_next) {
3178 if (addr > limit)
3179 break;
3180 - if (addr + len <= vma->vm_start)
3181 + if (check_heap_stack_gap(vma, addr, len, offset))
3182 goto success;
3183 addr = vma->vm_end;
3184 }
3185 @@ -104,7 +104,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3186 for (; vma; vma = vma->vm_next) {
3187 if (addr > limit)
3188 break;
3189 - if (addr + len <= vma->vm_start)
3190 + if (check_heap_stack_gap(vma, addr, len, offset))
3191 goto success;
3192 addr = vma->vm_end;
3193 }
3194 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
3195 index f4ca594..adc72fd6 100644
3196 --- a/arch/hexagon/include/asm/cache.h
3197 +++ b/arch/hexagon/include/asm/cache.h
3198 @@ -21,9 +21,11 @@
3199 #ifndef __ASM_CACHE_H
3200 #define __ASM_CACHE_H
3201
3202 +#include <linux/const.h>
3203 +
3204 /* Bytes per L1 cache line */
3205 -#define L1_CACHE_SHIFT (5)
3206 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3207 +#define L1_CACHE_SHIFT 5
3208 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3209
3210 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
3211 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
3212 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
3213 index 6e6fe18..a6ae668 100644
3214 --- a/arch/ia64/include/asm/atomic.h
3215 +++ b/arch/ia64/include/asm/atomic.h
3216 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
3217 #define atomic64_inc(v) atomic64_add(1, (v))
3218 #define atomic64_dec(v) atomic64_sub(1, (v))
3219
3220 +#define atomic64_read_unchecked(v) atomic64_read(v)
3221 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3222 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3223 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3224 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3225 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3226 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3227 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3228 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3229 +
3230 /* Atomic operations are already serializing */
3231 #define smp_mb__before_atomic_dec() barrier()
3232 #define smp_mb__after_atomic_dec() barrier()
3233 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
3234 index 988254a..e1ee885 100644
3235 --- a/arch/ia64/include/asm/cache.h
3236 +++ b/arch/ia64/include/asm/cache.h
3237 @@ -1,6 +1,7 @@
3238 #ifndef _ASM_IA64_CACHE_H
3239 #define _ASM_IA64_CACHE_H
3240
3241 +#include <linux/const.h>
3242
3243 /*
3244 * Copyright (C) 1998-2000 Hewlett-Packard Co
3245 @@ -9,7 +10,7 @@
3246
3247 /* Bytes per L1 (data) cache line. */
3248 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
3249 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3250 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3251
3252 #ifdef CONFIG_SMP
3253 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
3254 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
3255 index b5298eb..67c6e62 100644
3256 --- a/arch/ia64/include/asm/elf.h
3257 +++ b/arch/ia64/include/asm/elf.h
3258 @@ -42,6 +42,13 @@
3259 */
3260 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
3261
3262 +#ifdef CONFIG_PAX_ASLR
3263 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
3264 +
3265 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
3266 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
3267 +#endif
3268 +
3269 #define PT_IA_64_UNWIND 0x70000001
3270
3271 /* IA-64 relocations: */
3272 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
3273 index 96a8d92..617a1cf 100644
3274 --- a/arch/ia64/include/asm/pgalloc.h
3275 +++ b/arch/ia64/include/asm/pgalloc.h
3276 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
3277 pgd_val(*pgd_entry) = __pa(pud);
3278 }
3279
3280 +static inline void
3281 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
3282 +{
3283 + pgd_populate(mm, pgd_entry, pud);
3284 +}
3285 +
3286 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3287 {
3288 return quicklist_alloc(0, GFP_KERNEL, NULL);
3289 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
3290 pud_val(*pud_entry) = __pa(pmd);
3291 }
3292
3293 +static inline void
3294 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
3295 +{
3296 + pud_populate(mm, pud_entry, pmd);
3297 +}
3298 +
3299 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
3300 {
3301 return quicklist_alloc(0, GFP_KERNEL, NULL);
3302 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
3303 index 815810c..d60bd4c 100644
3304 --- a/arch/ia64/include/asm/pgtable.h
3305 +++ b/arch/ia64/include/asm/pgtable.h
3306 @@ -12,7 +12,7 @@
3307 * David Mosberger-Tang <davidm@hpl.hp.com>
3308 */
3309
3310 -
3311 +#include <linux/const.h>
3312 #include <asm/mman.h>
3313 #include <asm/page.h>
3314 #include <asm/processor.h>
3315 @@ -142,6 +142,17 @@
3316 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3317 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3318 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
3319 +
3320 +#ifdef CONFIG_PAX_PAGEEXEC
3321 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
3322 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3323 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3324 +#else
3325 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3326 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3327 +# define PAGE_COPY_NOEXEC PAGE_COPY
3328 +#endif
3329 +
3330 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
3331 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
3332 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
3333 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
3334 index 54ff557..70c88b7 100644
3335 --- a/arch/ia64/include/asm/spinlock.h
3336 +++ b/arch/ia64/include/asm/spinlock.h
3337 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
3338 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
3339
3340 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
3341 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
3342 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
3343 }
3344
3345 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
3346 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
3347 index 449c8c0..50cdf87 100644
3348 --- a/arch/ia64/include/asm/uaccess.h
3349 +++ b/arch/ia64/include/asm/uaccess.h
3350 @@ -42,6 +42,8 @@
3351 #include <asm/pgtable.h>
3352 #include <asm/io.h>
3353
3354 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3355 +
3356 /*
3357 * For historical reasons, the following macros are grossly misnamed:
3358 */
3359 @@ -240,12 +242,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
3360 static inline unsigned long
3361 __copy_to_user (void __user *to, const void *from, unsigned long count)
3362 {
3363 + if (count > INT_MAX)
3364 + return count;
3365 +
3366 + if (!__builtin_constant_p(count))
3367 + check_object_size(from, count, true);
3368 +
3369 return __copy_user(to, (__force void __user *) from, count);
3370 }
3371
3372 static inline unsigned long
3373 __copy_from_user (void *to, const void __user *from, unsigned long count)
3374 {
3375 + if (count > INT_MAX)
3376 + return count;
3377 +
3378 + if (!__builtin_constant_p(count))
3379 + check_object_size(to, count, false);
3380 +
3381 return __copy_user((__force void __user *) to, from, count);
3382 }
3383
3384 @@ -255,10 +269,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
3385 ({ \
3386 void __user *__cu_to = (to); \
3387 const void *__cu_from = (from); \
3388 - long __cu_len = (n); \
3389 + unsigned long __cu_len = (n); \
3390 \
3391 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
3392 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
3393 + if (!__builtin_constant_p(n)) \
3394 + check_object_size(__cu_from, __cu_len, true); \
3395 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
3396 + } \
3397 __cu_len; \
3398 })
3399
3400 @@ -266,11 +283,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
3401 ({ \
3402 void *__cu_to = (to); \
3403 const void __user *__cu_from = (from); \
3404 - long __cu_len = (n); \
3405 + unsigned long __cu_len = (n); \
3406 \
3407 __chk_user_ptr(__cu_from); \
3408 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
3409 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
3410 + if (!__builtin_constant_p(n)) \
3411 + check_object_size(__cu_to, __cu_len, false); \
3412 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
3413 + } \
3414 __cu_len; \
3415 })
3416
3417 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
3418 index 24603be..948052d 100644
3419 --- a/arch/ia64/kernel/module.c
3420 +++ b/arch/ia64/kernel/module.c
3421 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
3422 void
3423 module_free (struct module *mod, void *module_region)
3424 {
3425 - if (mod && mod->arch.init_unw_table &&
3426 - module_region == mod->module_init) {
3427 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
3428 unw_remove_unwind_table(mod->arch.init_unw_table);
3429 mod->arch.init_unw_table = NULL;
3430 }
3431 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
3432 }
3433
3434 static inline int
3435 +in_init_rx (const struct module *mod, uint64_t addr)
3436 +{
3437 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
3438 +}
3439 +
3440 +static inline int
3441 +in_init_rw (const struct module *mod, uint64_t addr)
3442 +{
3443 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
3444 +}
3445 +
3446 +static inline int
3447 in_init (const struct module *mod, uint64_t addr)
3448 {
3449 - return addr - (uint64_t) mod->module_init < mod->init_size;
3450 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
3451 +}
3452 +
3453 +static inline int
3454 +in_core_rx (const struct module *mod, uint64_t addr)
3455 +{
3456 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
3457 +}
3458 +
3459 +static inline int
3460 +in_core_rw (const struct module *mod, uint64_t addr)
3461 +{
3462 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
3463 }
3464
3465 static inline int
3466 in_core (const struct module *mod, uint64_t addr)
3467 {
3468 - return addr - (uint64_t) mod->module_core < mod->core_size;
3469 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
3470 }
3471
3472 static inline int
3473 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
3474 break;
3475
3476 case RV_BDREL:
3477 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
3478 + if (in_init_rx(mod, val))
3479 + val -= (uint64_t) mod->module_init_rx;
3480 + else if (in_init_rw(mod, val))
3481 + val -= (uint64_t) mod->module_init_rw;
3482 + else if (in_core_rx(mod, val))
3483 + val -= (uint64_t) mod->module_core_rx;
3484 + else if (in_core_rw(mod, val))
3485 + val -= (uint64_t) mod->module_core_rw;
3486 break;
3487
3488 case RV_LTV:
3489 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
3490 * addresses have been selected...
3491 */
3492 uint64_t gp;
3493 - if (mod->core_size > MAX_LTOFF)
3494 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
3495 /*
3496 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
3497 * at the end of the module.
3498 */
3499 - gp = mod->core_size - MAX_LTOFF / 2;
3500 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
3501 else
3502 - gp = mod->core_size / 2;
3503 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
3504 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
3505 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
3506 mod->arch.gp = gp;
3507 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
3508 }
3509 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
3510 index d9439ef..d0cac6b 100644
3511 --- a/arch/ia64/kernel/sys_ia64.c
3512 +++ b/arch/ia64/kernel/sys_ia64.c
3513 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
3514 unsigned long start_addr, align_mask = PAGE_SIZE - 1;
3515 struct mm_struct *mm = current->mm;
3516 struct vm_area_struct *vma;
3517 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3518
3519 if (len > RGN_MAP_LIMIT)
3520 return -ENOMEM;
3521 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
3522 if (REGION_NUMBER(addr) == RGN_HPAGE)
3523 addr = 0;
3524 #endif
3525 +
3526 +#ifdef CONFIG_PAX_RANDMMAP
3527 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3528 + addr = mm->free_area_cache;
3529 + else
3530 +#endif
3531 +
3532 if (!addr)
3533 addr = mm->free_area_cache;
3534
3535 @@ -61,14 +69,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
3536 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
3537 /* At this point: (!vma || addr < vma->vm_end). */
3538 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
3539 - if (start_addr != TASK_UNMAPPED_BASE) {
3540 + if (start_addr != mm->mmap_base) {
3541 /* Start a new search --- just in case we missed some holes. */
3542 - addr = TASK_UNMAPPED_BASE;
3543 + addr = mm->mmap_base;
3544 goto full_search;
3545 }
3546 return -ENOMEM;
3547 }
3548 - if (!vma || addr + len <= vma->vm_start) {
3549 + if (check_heap_stack_gap(vma, addr, len, offset)) {
3550 /* Remember the address where we stopped this search: */
3551 mm->free_area_cache = addr + len;
3552 return addr;
3553 diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
3554 index c64460b..4d250a6 100644
3555 --- a/arch/ia64/kernel/topology.c
3556 +++ b/arch/ia64/kernel/topology.c
3557 @@ -445,7 +445,7 @@ static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
3558 return NOTIFY_OK;
3559 }
3560
3561 -static struct notifier_block __cpuinitdata cache_cpu_notifier =
3562 +static struct notifier_block cache_cpu_notifier =
3563 {
3564 .notifier_call = cache_cpu_callback
3565 };
3566 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
3567 index 0ccb28f..8992469 100644
3568 --- a/arch/ia64/kernel/vmlinux.lds.S
3569 +++ b/arch/ia64/kernel/vmlinux.lds.S
3570 @@ -198,7 +198,7 @@ SECTIONS {
3571 /* Per-cpu data: */
3572 . = ALIGN(PERCPU_PAGE_SIZE);
3573 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
3574 - __phys_per_cpu_start = __per_cpu_load;
3575 + __phys_per_cpu_start = per_cpu_load;
3576 /*
3577 * ensure percpu data fits
3578 * into percpu page size
3579 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
3580 index 6cf0341..d352594 100644
3581 --- a/arch/ia64/mm/fault.c
3582 +++ b/arch/ia64/mm/fault.c
3583 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
3584 return pte_present(pte);
3585 }
3586
3587 +#ifdef CONFIG_PAX_PAGEEXEC
3588 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3589 +{
3590 + unsigned long i;
3591 +
3592 + printk(KERN_ERR "PAX: bytes at PC: ");
3593 + for (i = 0; i < 8; i++) {
3594 + unsigned int c;
3595 + if (get_user(c, (unsigned int *)pc+i))
3596 + printk(KERN_CONT "???????? ");
3597 + else
3598 + printk(KERN_CONT "%08x ", c);
3599 + }
3600 + printk("\n");
3601 +}
3602 +#endif
3603 +
3604 # define VM_READ_BIT 0
3605 # define VM_WRITE_BIT 1
3606 # define VM_EXEC_BIT 2
3607 @@ -149,8 +166,21 @@ retry:
3608 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
3609 goto bad_area;
3610
3611 - if ((vma->vm_flags & mask) != mask)
3612 + if ((vma->vm_flags & mask) != mask) {
3613 +
3614 +#ifdef CONFIG_PAX_PAGEEXEC
3615 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
3616 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
3617 + goto bad_area;
3618 +
3619 + up_read(&mm->mmap_sem);
3620 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
3621 + do_group_exit(SIGKILL);
3622 + }
3623 +#endif
3624 +
3625 goto bad_area;
3626 + }
3627
3628 /*
3629 * If for any reason at all we couldn't handle the fault, make
3630 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
3631 index 5ca674b..127c3cb 100644
3632 --- a/arch/ia64/mm/hugetlbpage.c
3633 +++ b/arch/ia64/mm/hugetlbpage.c
3634 @@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
3635 unsigned long pgoff, unsigned long flags)
3636 {
3637 struct vm_area_struct *vmm;
3638 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
3639
3640 if (len > RGN_MAP_LIMIT)
3641 return -ENOMEM;
3642 @@ -171,7 +172,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
3643 /* At this point: (!vmm || addr < vmm->vm_end). */
3644 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
3645 return -ENOMEM;
3646 - if (!vmm || (addr + len) <= vmm->vm_start)
3647 + if (check_heap_stack_gap(vmm, addr, len, offset))
3648 return addr;
3649 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
3650 }
3651 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
3652 index 082e383..fb7be80 100644
3653 --- a/arch/ia64/mm/init.c
3654 +++ b/arch/ia64/mm/init.c
3655 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
3656 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
3657 vma->vm_end = vma->vm_start + PAGE_SIZE;
3658 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
3659 +
3660 +#ifdef CONFIG_PAX_PAGEEXEC
3661 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
3662 + vma->vm_flags &= ~VM_EXEC;
3663 +
3664 +#ifdef CONFIG_PAX_MPROTECT
3665 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
3666 + vma->vm_flags &= ~VM_MAYEXEC;
3667 +#endif
3668 +
3669 + }
3670 +#endif
3671 +
3672 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
3673 down_write(&current->mm->mmap_sem);
3674 if (insert_vm_struct(current->mm, vma)) {
3675 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
3676 index 40b3ee9..8c2c112 100644
3677 --- a/arch/m32r/include/asm/cache.h
3678 +++ b/arch/m32r/include/asm/cache.h
3679 @@ -1,8 +1,10 @@
3680 #ifndef _ASM_M32R_CACHE_H
3681 #define _ASM_M32R_CACHE_H
3682
3683 +#include <linux/const.h>
3684 +
3685 /* L1 cache line size */
3686 #define L1_CACHE_SHIFT 4
3687 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3688 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3689
3690 #endif /* _ASM_M32R_CACHE_H */
3691 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
3692 index 82abd15..d95ae5d 100644
3693 --- a/arch/m32r/lib/usercopy.c
3694 +++ b/arch/m32r/lib/usercopy.c
3695 @@ -14,6 +14,9 @@
3696 unsigned long
3697 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
3698 {
3699 + if ((long)n < 0)
3700 + return n;
3701 +
3702 prefetch(from);
3703 if (access_ok(VERIFY_WRITE, to, n))
3704 __copy_user(to,from,n);
3705 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
3706 unsigned long
3707 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
3708 {
3709 + if ((long)n < 0)
3710 + return n;
3711 +
3712 prefetchw(to);
3713 if (access_ok(VERIFY_READ, from, n))
3714 __copy_user_zeroing(to,from,n);
3715 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
3716 index 0395c51..5f26031 100644
3717 --- a/arch/m68k/include/asm/cache.h
3718 +++ b/arch/m68k/include/asm/cache.h
3719 @@ -4,9 +4,11 @@
3720 #ifndef __ARCH_M68K_CACHE_H
3721 #define __ARCH_M68K_CACHE_H
3722
3723 +#include <linux/const.h>
3724 +
3725 /* bytes per L1 cache line */
3726 #define L1_CACHE_SHIFT 4
3727 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
3728 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3729
3730 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
3731
3732 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
3733 index 4efe96a..60e8699 100644
3734 --- a/arch/microblaze/include/asm/cache.h
3735 +++ b/arch/microblaze/include/asm/cache.h
3736 @@ -13,11 +13,12 @@
3737 #ifndef _ASM_MICROBLAZE_CACHE_H
3738 #define _ASM_MICROBLAZE_CACHE_H
3739
3740 +#include <linux/const.h>
3741 #include <asm/registers.h>
3742
3743 #define L1_CACHE_SHIFT 5
3744 /* word-granular cache in microblaze */
3745 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3746 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3747
3748 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3749
3750 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
3751 index 01cc6ba..bcb7a5d 100644
3752 --- a/arch/mips/include/asm/atomic.h
3753 +++ b/arch/mips/include/asm/atomic.h
3754 @@ -21,6 +21,10 @@
3755 #include <asm/cmpxchg.h>
3756 #include <asm/war.h>
3757
3758 +#ifdef CONFIG_GENERIC_ATOMIC64
3759 +#include <asm-generic/atomic64.h>
3760 +#endif
3761 +
3762 #define ATOMIC_INIT(i) { (i) }
3763
3764 /*
3765 @@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3766 */
3767 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
3768
3769 +#define atomic64_read_unchecked(v) atomic64_read(v)
3770 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3771 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3772 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3773 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3774 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3775 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3776 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3777 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3778 +
3779 #endif /* CONFIG_64BIT */
3780
3781 /*
3782 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
3783 index b4db69f..8f3b093 100644
3784 --- a/arch/mips/include/asm/cache.h
3785 +++ b/arch/mips/include/asm/cache.h
3786 @@ -9,10 +9,11 @@
3787 #ifndef _ASM_CACHE_H
3788 #define _ASM_CACHE_H
3789
3790 +#include <linux/const.h>
3791 #include <kmalloc.h>
3792
3793 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
3794 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3795 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3796
3797 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
3798 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3799 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
3800 index 455c0ac..ad65fbe 100644
3801 --- a/arch/mips/include/asm/elf.h
3802 +++ b/arch/mips/include/asm/elf.h
3803 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
3804 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
3805 #endif
3806
3807 +#ifdef CONFIG_PAX_ASLR
3808 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3809 +
3810 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3811 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3812 +#endif
3813 +
3814 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
3815 struct linux_binprm;
3816 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3817 int uses_interp);
3818
3819 -struct mm_struct;
3820 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3821 -#define arch_randomize_brk arch_randomize_brk
3822 -
3823 #endif /* _ASM_ELF_H */
3824 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
3825 index c1f6afa..38cc6e9 100644
3826 --- a/arch/mips/include/asm/exec.h
3827 +++ b/arch/mips/include/asm/exec.h
3828 @@ -12,6 +12,6 @@
3829 #ifndef _ASM_EXEC_H
3830 #define _ASM_EXEC_H
3831
3832 -extern unsigned long arch_align_stack(unsigned long sp);
3833 +#define arch_align_stack(x) ((x) & ~0xfUL)
3834
3835 #endif /* _ASM_EXEC_H */
3836 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
3837 index da9bd7d..91aa7ab 100644
3838 --- a/arch/mips/include/asm/page.h
3839 +++ b/arch/mips/include/asm/page.h
3840 @@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
3841 #ifdef CONFIG_CPU_MIPS32
3842 typedef struct { unsigned long pte_low, pte_high; } pte_t;
3843 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
3844 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
3845 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
3846 #else
3847 typedef struct { unsigned long long pte; } pte_t;
3848 #define pte_val(x) ((x).pte)
3849 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
3850 index 881d18b..cea38bc 100644
3851 --- a/arch/mips/include/asm/pgalloc.h
3852 +++ b/arch/mips/include/asm/pgalloc.h
3853 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3854 {
3855 set_pud(pud, __pud((unsigned long)pmd));
3856 }
3857 +
3858 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3859 +{
3860 + pud_populate(mm, pud, pmd);
3861 +}
3862 #endif
3863
3864 /*
3865 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
3866 index 18806a5..141ffcf 100644
3867 --- a/arch/mips/include/asm/thread_info.h
3868 +++ b/arch/mips/include/asm/thread_info.h
3869 @@ -110,6 +110,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
3870 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
3871 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
3872 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
3873 +/* li takes a 32bit immediate */
3874 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
3875 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
3876
3877 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3878 @@ -125,15 +127,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
3879 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
3880 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
3881 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
3882 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3883 +
3884 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
3885
3886 /* work to do in syscall_trace_leave() */
3887 -#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
3888 +#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
3889
3890 /* work to do on interrupt/exception return */
3891 #define _TIF_WORK_MASK \
3892 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
3893 /* work to do on any return to u-space */
3894 -#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
3895 +#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
3896
3897 #endif /* __KERNEL__ */
3898
3899 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
3900 index 9fdd8bc..4bd7f1a 100644
3901 --- a/arch/mips/kernel/binfmt_elfn32.c
3902 +++ b/arch/mips/kernel/binfmt_elfn32.c
3903 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
3904 #undef ELF_ET_DYN_BASE
3905 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
3906
3907 +#ifdef CONFIG_PAX_ASLR
3908 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3909 +
3910 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3911 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3912 +#endif
3913 +
3914 #include <asm/processor.h>
3915 #include <linux/module.h>
3916 #include <linux/elfcore.h>
3917 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
3918 index ff44823..97f8906 100644
3919 --- a/arch/mips/kernel/binfmt_elfo32.c
3920 +++ b/arch/mips/kernel/binfmt_elfo32.c
3921 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
3922 #undef ELF_ET_DYN_BASE
3923 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
3924
3925 +#ifdef CONFIG_PAX_ASLR
3926 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3927 +
3928 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3929 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3930 +#endif
3931 +
3932 #include <asm/processor.h>
3933
3934 /*
3935 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
3936 index 69b17a9..9db82f9 100644
3937 --- a/arch/mips/kernel/process.c
3938 +++ b/arch/mips/kernel/process.c
3939 @@ -478,15 +478,3 @@ unsigned long get_wchan(struct task_struct *task)
3940 out:
3941 return pc;
3942 }
3943 -
3944 -/*
3945 - * Don't forget that the stack pointer must be aligned on a 8 bytes
3946 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
3947 - */
3948 -unsigned long arch_align_stack(unsigned long sp)
3949 -{
3950 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
3951 - sp -= get_random_int() & ~PAGE_MASK;
3952 -
3953 - return sp & ALMASK;
3954 -}
3955 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
3956 index 4812c6d..2069554 100644
3957 --- a/arch/mips/kernel/ptrace.c
3958 +++ b/arch/mips/kernel/ptrace.c
3959 @@ -528,6 +528,10 @@ static inline int audit_arch(void)
3960 return arch;
3961 }
3962
3963 +#ifdef CONFIG_GRKERNSEC_SETXID
3964 +extern void gr_delayed_cred_worker(void);
3965 +#endif
3966 +
3967 /*
3968 * Notification of system call entry/exit
3969 * - triggered by current->work.syscall_trace
3970 @@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
3971 /* do the secure computing check first */
3972 secure_computing_strict(regs->regs[2]);
3973
3974 +#ifdef CONFIG_GRKERNSEC_SETXID
3975 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3976 + gr_delayed_cred_worker();
3977 +#endif
3978 +
3979 if (!(current->ptrace & PT_PTRACED))
3980 goto out;
3981
3982 diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3983 index 374f66e..1c882a0 100644
3984 --- a/arch/mips/kernel/scall32-o32.S
3985 +++ b/arch/mips/kernel/scall32-o32.S
3986 @@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3987
3988 stack_done:
3989 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3990 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3991 + li t1, _TIF_SYSCALL_WORK
3992 and t0, t1
3993 bnez t0, syscall_trace_entry # -> yes
3994
3995 diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3996 index 169de6a..f594a89 100644
3997 --- a/arch/mips/kernel/scall64-64.S
3998 +++ b/arch/mips/kernel/scall64-64.S
3999 @@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
4000
4001 sd a3, PT_R26(sp) # save a3 for syscall restarting
4002
4003 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
4004 + li t1, _TIF_SYSCALL_WORK
4005 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
4006 and t0, t1, t0
4007 bnez t0, syscall_trace_entry
4008 diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
4009 index 86ec03f..1235baf 100644
4010 --- a/arch/mips/kernel/scall64-n32.S
4011 +++ b/arch/mips/kernel/scall64-n32.S
4012 @@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
4013
4014 sd a3, PT_R26(sp) # save a3 for syscall restarting
4015
4016 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
4017 + li t1, _TIF_SYSCALL_WORK
4018 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
4019 and t0, t1, t0
4020 bnez t0, n32_syscall_trace_entry
4021 diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
4022 index 53c2d72..3734584 100644
4023 --- a/arch/mips/kernel/scall64-o32.S
4024 +++ b/arch/mips/kernel/scall64-o32.S
4025 @@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
4026 PTR 4b, bad_stack
4027 .previous
4028
4029 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
4030 + li t1, _TIF_SYSCALL_WORK
4031 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
4032 and t0, t1, t0
4033 bnez t0, trace_a_syscall
4034 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
4035 index ddcec1e..c7f983e 100644
4036 --- a/arch/mips/mm/fault.c
4037 +++ b/arch/mips/mm/fault.c
4038 @@ -27,6 +27,23 @@
4039 #include <asm/highmem.h> /* For VMALLOC_END */
4040 #include <linux/kdebug.h>
4041
4042 +#ifdef CONFIG_PAX_PAGEEXEC
4043 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4044 +{
4045 + unsigned long i;
4046 +
4047 + printk(KERN_ERR "PAX: bytes at PC: ");
4048 + for (i = 0; i < 5; i++) {
4049 + unsigned int c;
4050 + if (get_user(c, (unsigned int *)pc+i))
4051 + printk(KERN_CONT "???????? ");
4052 + else
4053 + printk(KERN_CONT "%08x ", c);
4054 + }
4055 + printk("\n");
4056 +}
4057 +#endif
4058 +
4059 /*
4060 * This routine handles page faults. It determines the address,
4061 * and the problem, and then passes it off to one of the appropriate
4062 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
4063 index 302d779..6459dc0 100644
4064 --- a/arch/mips/mm/mmap.c
4065 +++ b/arch/mips/mm/mmap.c
4066 @@ -71,6 +71,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4067 struct vm_area_struct *vma;
4068 unsigned long addr = addr0;
4069 int do_color_align;
4070 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4071
4072 if (unlikely(len > TASK_SIZE))
4073 return -ENOMEM;
4074 @@ -95,6 +96,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4075 do_color_align = 1;
4076
4077 /* requesting a specific address */
4078 +
4079 +#ifdef CONFIG_PAX_RANDMMAP
4080 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
4081 +#endif
4082 +
4083 if (addr) {
4084 if (do_color_align)
4085 addr = COLOUR_ALIGN(addr, pgoff);
4086 @@ -102,8 +108,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4087 addr = PAGE_ALIGN(addr);
4088
4089 vma = find_vma(mm, addr);
4090 - if (TASK_SIZE - len >= addr &&
4091 - (!vma || addr + len <= vma->vm_start))
4092 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
4093 return addr;
4094 }
4095
4096 @@ -118,7 +123,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4097 /* At this point: (!vma || addr < vma->vm_end). */
4098 if (TASK_SIZE - len < addr)
4099 return -ENOMEM;
4100 - if (!vma || addr + len <= vma->vm_start)
4101 + if (check_heap_stack_gap(vmm, addr, len, offset))
4102 return addr;
4103 addr = vma->vm_end;
4104 if (do_color_align)
4105 @@ -145,7 +150,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4106 /* make sure it can fit in the remaining address space */
4107 if (likely(addr > len)) {
4108 vma = find_vma(mm, addr - len);
4109 - if (!vma || addr <= vma->vm_start) {
4110 + if (check_heap_stack_gap(vmm, addr - len, len, offset))
4111 /* cache the address as a hint for next time */
4112 return mm->free_area_cache = addr - len;
4113 }
4114 @@ -155,17 +160,17 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4115 goto bottomup;
4116
4117 addr = mm->mmap_base - len;
4118 - if (do_color_align)
4119 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4120
4121 do {
4122 + if (do_color_align)
4123 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4124 /*
4125 * Lookup failure means no vma is above this address,
4126 * else if new region fits below vma->vm_start,
4127 * return with success:
4128 */
4129 vma = find_vma(mm, addr);
4130 - if (likely(!vma || addr + len <= vma->vm_start)) {
4131 + if (check_heap_stack_gap(vmm, addr, len, offset)) {
4132 /* cache the address as a hint for next time */
4133 return mm->free_area_cache = addr;
4134 }
4135 @@ -175,10 +180,8 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4136 mm->cached_hole_size = vma->vm_start - addr;
4137
4138 /* try just below the current vma->vm_start */
4139 - addr = vma->vm_start - len;
4140 - if (do_color_align)
4141 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4142 - } while (likely(len < vma->vm_start));
4143 + addr = skip_heap_stack_gap(vma, len, offset);
4144 + } while (!IS_ERR_VALUE(addr));
4145
4146 bottomup:
4147 /*
4148 @@ -223,6 +226,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4149 {
4150 unsigned long random_factor = 0UL;
4151
4152 +#ifdef CONFIG_PAX_RANDMMAP
4153 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
4154 +#endif
4155 +
4156 if (current->flags & PF_RANDOMIZE) {
4157 random_factor = get_random_int();
4158 random_factor = random_factor << PAGE_SHIFT;
4159 @@ -234,38 +241,23 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4160
4161 if (mmap_is_legacy()) {
4162 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4163 +
4164 +#ifdef CONFIG_PAX_RANDMMAP
4165 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4166 + mm->mmap_base += mm->delta_mmap;
4167 +#endif
4168 +
4169 mm->get_unmapped_area = arch_get_unmapped_area;
4170 mm->unmap_area = arch_unmap_area;
4171 } else {
4172 mm->mmap_base = mmap_base(random_factor);
4173 +
4174 +#ifdef CONFIG_PAX_RANDMMAP
4175 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4176 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4177 +#endif
4178 +
4179 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4180 mm->unmap_area = arch_unmap_area_topdown;
4181 }
4182 }
4183 -
4184 -static inline unsigned long brk_rnd(void)
4185 -{
4186 - unsigned long rnd = get_random_int();
4187 -
4188 - rnd = rnd << PAGE_SHIFT;
4189 - /* 8MB for 32bit, 256MB for 64bit */
4190 - if (TASK_IS_32BIT_ADDR)
4191 - rnd = rnd & 0x7ffffful;
4192 - else
4193 - rnd = rnd & 0xffffffful;
4194 -
4195 - return rnd;
4196 -}
4197 -
4198 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4199 -{
4200 - unsigned long base = mm->brk;
4201 - unsigned long ret;
4202 -
4203 - ret = PAGE_ALIGN(base + brk_rnd());
4204 -
4205 - if (ret < mm->brk)
4206 - return mm->brk;
4207 -
4208 - return ret;
4209 -}
4210 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
4211 index 967d144..db12197 100644
4212 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
4213 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
4214 @@ -11,12 +11,14 @@
4215 #ifndef _ASM_PROC_CACHE_H
4216 #define _ASM_PROC_CACHE_H
4217
4218 +#include <linux/const.h>
4219 +
4220 /* L1 cache */
4221
4222 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
4223 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
4224 -#define L1_CACHE_BYTES 16 /* bytes per entry */
4225 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
4226 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
4227 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
4228
4229 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
4230 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
4231 index bcb5df2..84fabd2 100644
4232 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
4233 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
4234 @@ -16,13 +16,15 @@
4235 #ifndef _ASM_PROC_CACHE_H
4236 #define _ASM_PROC_CACHE_H
4237
4238 +#include <linux/const.h>
4239 +
4240 /*
4241 * L1 cache
4242 */
4243 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
4244 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
4245 -#define L1_CACHE_BYTES 32 /* bytes per entry */
4246 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
4247 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
4248 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
4249
4250 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
4251 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
4252 index 4ce7a01..449202a 100644
4253 --- a/arch/openrisc/include/asm/cache.h
4254 +++ b/arch/openrisc/include/asm/cache.h
4255 @@ -19,11 +19,13 @@
4256 #ifndef __ASM_OPENRISC_CACHE_H
4257 #define __ASM_OPENRISC_CACHE_H
4258
4259 +#include <linux/const.h>
4260 +
4261 /* FIXME: How can we replace these with values from the CPU...
4262 * they shouldn't be hard-coded!
4263 */
4264
4265 -#define L1_CACHE_BYTES 16
4266 #define L1_CACHE_SHIFT 4
4267 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4268
4269 #endif /* __ASM_OPENRISC_CACHE_H */
4270 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
4271 index af9cf30..2aae9b2 100644
4272 --- a/arch/parisc/include/asm/atomic.h
4273 +++ b/arch/parisc/include/asm/atomic.h
4274 @@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
4275
4276 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4277
4278 +#define atomic64_read_unchecked(v) atomic64_read(v)
4279 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4280 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4281 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4282 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4283 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4284 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4285 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4286 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4287 +
4288 #endif /* !CONFIG_64BIT */
4289
4290
4291 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
4292 index 47f11c7..3420df2 100644
4293 --- a/arch/parisc/include/asm/cache.h
4294 +++ b/arch/parisc/include/asm/cache.h
4295 @@ -5,6 +5,7 @@
4296 #ifndef __ARCH_PARISC_CACHE_H
4297 #define __ARCH_PARISC_CACHE_H
4298
4299 +#include <linux/const.h>
4300
4301 /*
4302 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
4303 @@ -15,13 +16,13 @@
4304 * just ruin performance.
4305 */
4306 #ifdef CONFIG_PA20
4307 -#define L1_CACHE_BYTES 64
4308 #define L1_CACHE_SHIFT 6
4309 #else
4310 -#define L1_CACHE_BYTES 32
4311 #define L1_CACHE_SHIFT 5
4312 #endif
4313
4314 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4315 +
4316 #ifndef __ASSEMBLY__
4317
4318 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4319 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
4320 index 19f6cb1..6c78cf2 100644
4321 --- a/arch/parisc/include/asm/elf.h
4322 +++ b/arch/parisc/include/asm/elf.h
4323 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
4324
4325 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
4326
4327 +#ifdef CONFIG_PAX_ASLR
4328 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
4329 +
4330 +#define PAX_DELTA_MMAP_LEN 16
4331 +#define PAX_DELTA_STACK_LEN 16
4332 +#endif
4333 +
4334 /* This yields a mask that user programs can use to figure out what
4335 instruction set this CPU supports. This could be done in user space,
4336 but it's not easy, and we've already done it here. */
4337 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
4338 index fc987a1..6e068ef 100644
4339 --- a/arch/parisc/include/asm/pgalloc.h
4340 +++ b/arch/parisc/include/asm/pgalloc.h
4341 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
4342 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
4343 }
4344
4345 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
4346 +{
4347 + pgd_populate(mm, pgd, pmd);
4348 +}
4349 +
4350 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
4351 {
4352 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
4353 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
4354 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
4355 #define pmd_free(mm, x) do { } while (0)
4356 #define pgd_populate(mm, pmd, pte) BUG()
4357 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
4358
4359 #endif
4360
4361 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
4362 index ee99f23..802b0a1 100644
4363 --- a/arch/parisc/include/asm/pgtable.h
4364 +++ b/arch/parisc/include/asm/pgtable.h
4365 @@ -212,6 +212,17 @@ struct vm_area_struct;
4366 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
4367 #define PAGE_COPY PAGE_EXECREAD
4368 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
4369 +
4370 +#ifdef CONFIG_PAX_PAGEEXEC
4371 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
4372 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
4373 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
4374 +#else
4375 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
4376 +# define PAGE_COPY_NOEXEC PAGE_COPY
4377 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
4378 +#endif
4379 +
4380 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
4381 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
4382 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
4383 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
4384 index 4ba2c93..f5e3974 100644
4385 --- a/arch/parisc/include/asm/uaccess.h
4386 +++ b/arch/parisc/include/asm/uaccess.h
4387 @@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
4388 const void __user *from,
4389 unsigned long n)
4390 {
4391 - int sz = __compiletime_object_size(to);
4392 + size_t sz = __compiletime_object_size(to);
4393 int ret = -EFAULT;
4394
4395 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
4396 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
4397 ret = __copy_from_user(to, from, n);
4398 else
4399 copy_from_user_overflow();
4400 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
4401 index 5e34ccf..672bc9c 100644
4402 --- a/arch/parisc/kernel/module.c
4403 +++ b/arch/parisc/kernel/module.c
4404 @@ -98,16 +98,38 @@
4405
4406 /* three functions to determine where in the module core
4407 * or init pieces the location is */
4408 +static inline int in_init_rx(struct module *me, void *loc)
4409 +{
4410 + return (loc >= me->module_init_rx &&
4411 + loc < (me->module_init_rx + me->init_size_rx));
4412 +}
4413 +
4414 +static inline int in_init_rw(struct module *me, void *loc)
4415 +{
4416 + return (loc >= me->module_init_rw &&
4417 + loc < (me->module_init_rw + me->init_size_rw));
4418 +}
4419 +
4420 static inline int in_init(struct module *me, void *loc)
4421 {
4422 - return (loc >= me->module_init &&
4423 - loc <= (me->module_init + me->init_size));
4424 + return in_init_rx(me, loc) || in_init_rw(me, loc);
4425 +}
4426 +
4427 +static inline int in_core_rx(struct module *me, void *loc)
4428 +{
4429 + return (loc >= me->module_core_rx &&
4430 + loc < (me->module_core_rx + me->core_size_rx));
4431 +}
4432 +
4433 +static inline int in_core_rw(struct module *me, void *loc)
4434 +{
4435 + return (loc >= me->module_core_rw &&
4436 + loc < (me->module_core_rw + me->core_size_rw));
4437 }
4438
4439 static inline int in_core(struct module *me, void *loc)
4440 {
4441 - return (loc >= me->module_core &&
4442 - loc <= (me->module_core + me->core_size));
4443 + return in_core_rx(me, loc) || in_core_rw(me, loc);
4444 }
4445
4446 static inline int in_local(struct module *me, void *loc)
4447 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
4448 }
4449
4450 /* align things a bit */
4451 - me->core_size = ALIGN(me->core_size, 16);
4452 - me->arch.got_offset = me->core_size;
4453 - me->core_size += gots * sizeof(struct got_entry);
4454 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
4455 + me->arch.got_offset = me->core_size_rw;
4456 + me->core_size_rw += gots * sizeof(struct got_entry);
4457
4458 - me->core_size = ALIGN(me->core_size, 16);
4459 - me->arch.fdesc_offset = me->core_size;
4460 - me->core_size += fdescs * sizeof(Elf_Fdesc);
4461 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
4462 + me->arch.fdesc_offset = me->core_size_rw;
4463 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
4464
4465 me->arch.got_max = gots;
4466 me->arch.fdesc_max = fdescs;
4467 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
4468
4469 BUG_ON(value == 0);
4470
4471 - got = me->module_core + me->arch.got_offset;
4472 + got = me->module_core_rw + me->arch.got_offset;
4473 for (i = 0; got[i].addr; i++)
4474 if (got[i].addr == value)
4475 goto out;
4476 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
4477 #ifdef CONFIG_64BIT
4478 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
4479 {
4480 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
4481 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
4482
4483 if (!value) {
4484 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
4485 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
4486
4487 /* Create new one */
4488 fdesc->addr = value;
4489 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
4490 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
4491 return (Elf_Addr)fdesc;
4492 }
4493 #endif /* CONFIG_64BIT */
4494 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
4495
4496 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
4497 end = table + sechdrs[me->arch.unwind_section].sh_size;
4498 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
4499 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
4500
4501 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
4502 me->arch.unwind_section, table, end, gp);
4503 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
4504 index f76c108..92bad82 100644
4505 --- a/arch/parisc/kernel/sys_parisc.c
4506 +++ b/arch/parisc/kernel/sys_parisc.c
4507 @@ -33,9 +33,11 @@
4508 #include <linux/utsname.h>
4509 #include <linux/personality.h>
4510
4511 -static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
4512 +static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
4513 + unsigned long flags)
4514 {
4515 struct vm_area_struct *vma;
4516 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4517
4518 addr = PAGE_ALIGN(addr);
4519
4520 @@ -43,7 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
4521 /* At this point: (!vma || addr < vma->vm_end). */
4522 if (TASK_SIZE - len < addr)
4523 return -ENOMEM;
4524 - if (!vma || addr + len <= vma->vm_start)
4525 + if (check_heap_stack_gap(vma, addr, len, offset))
4526 return addr;
4527 addr = vma->vm_end;
4528 }
4529 @@ -67,11 +69,12 @@ static int get_offset(struct address_space *mapping)
4530 return offset & 0x3FF000;
4531 }
4532
4533 -static unsigned long get_shared_area(struct address_space *mapping,
4534 - unsigned long addr, unsigned long len, unsigned long pgoff)
4535 +static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
4536 + unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
4537 {
4538 struct vm_area_struct *vma;
4539 int offset = mapping ? get_offset(mapping) : 0;
4540 + unsigned long rand_offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4541
4542 offset = (offset + (pgoff << PAGE_SHIFT)) & 0x3FF000;
4543
4544 @@ -81,7 +84,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
4545 /* At this point: (!vma || addr < vma->vm_end). */
4546 if (TASK_SIZE - len < addr)
4547 return -ENOMEM;
4548 - if (!vma || addr + len <= vma->vm_start)
4549 + if (check_heap_stack_gap(vma, addr, len, rand_offset))
4550 return addr;
4551 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
4552 if (addr < vma->vm_end) /* handle wraparound */
4553 @@ -100,14 +103,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
4554 if (flags & MAP_FIXED)
4555 return addr;
4556 if (!addr)
4557 - addr = TASK_UNMAPPED_BASE;
4558 + addr = current->mm->mmap_base;
4559
4560 if (filp) {
4561 - addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
4562 + addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
4563 } else if(flags & MAP_SHARED) {
4564 - addr = get_shared_area(NULL, addr, len, pgoff);
4565 + addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
4566 } else {
4567 - addr = get_unshared_area(addr, len);
4568 + addr = get_unshared_area(filp, addr, len, flags);
4569 }
4570 return addr;
4571 }
4572 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
4573 index 45ba99f..8e22c33 100644
4574 --- a/arch/parisc/kernel/traps.c
4575 +++ b/arch/parisc/kernel/traps.c
4576 @@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
4577
4578 down_read(&current->mm->mmap_sem);
4579 vma = find_vma(current->mm,regs->iaoq[0]);
4580 - if (vma && (regs->iaoq[0] >= vma->vm_start)
4581 - && (vma->vm_flags & VM_EXEC)) {
4582 -
4583 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
4584 fault_address = regs->iaoq[0];
4585 fault_space = regs->iasq[0];
4586
4587 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
4588 index 18162ce..94de376 100644
4589 --- a/arch/parisc/mm/fault.c
4590 +++ b/arch/parisc/mm/fault.c
4591 @@ -15,6 +15,7 @@
4592 #include <linux/sched.h>
4593 #include <linux/interrupt.h>
4594 #include <linux/module.h>
4595 +#include <linux/unistd.h>
4596
4597 #include <asm/uaccess.h>
4598 #include <asm/traps.h>
4599 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
4600 static unsigned long
4601 parisc_acctyp(unsigned long code, unsigned int inst)
4602 {
4603 - if (code == 6 || code == 16)
4604 + if (code == 6 || code == 7 || code == 16)
4605 return VM_EXEC;
4606
4607 switch (inst & 0xf0000000) {
4608 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
4609 }
4610 #endif
4611
4612 +#ifdef CONFIG_PAX_PAGEEXEC
4613 +/*
4614 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
4615 + *
4616 + * returns 1 when task should be killed
4617 + * 2 when rt_sigreturn trampoline was detected
4618 + * 3 when unpatched PLT trampoline was detected
4619 + */
4620 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4621 +{
4622 +
4623 +#ifdef CONFIG_PAX_EMUPLT
4624 + int err;
4625 +
4626 + do { /* PaX: unpatched PLT emulation */
4627 + unsigned int bl, depwi;
4628 +
4629 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
4630 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
4631 +
4632 + if (err)
4633 + break;
4634 +
4635 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
4636 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
4637 +
4638 + err = get_user(ldw, (unsigned int *)addr);
4639 + err |= get_user(bv, (unsigned int *)(addr+4));
4640 + err |= get_user(ldw2, (unsigned int *)(addr+8));
4641 +
4642 + if (err)
4643 + break;
4644 +
4645 + if (ldw == 0x0E801096U &&
4646 + bv == 0xEAC0C000U &&
4647 + ldw2 == 0x0E881095U)
4648 + {
4649 + unsigned int resolver, map;
4650 +
4651 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
4652 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
4653 + if (err)
4654 + break;
4655 +
4656 + regs->gr[20] = instruction_pointer(regs)+8;
4657 + regs->gr[21] = map;
4658 + regs->gr[22] = resolver;
4659 + regs->iaoq[0] = resolver | 3UL;
4660 + regs->iaoq[1] = regs->iaoq[0] + 4;
4661 + return 3;
4662 + }
4663 + }
4664 + } while (0);
4665 +#endif
4666 +
4667 +#ifdef CONFIG_PAX_EMUTRAMP
4668 +
4669 +#ifndef CONFIG_PAX_EMUSIGRT
4670 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
4671 + return 1;
4672 +#endif
4673 +
4674 + do { /* PaX: rt_sigreturn emulation */
4675 + unsigned int ldi1, ldi2, bel, nop;
4676 +
4677 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
4678 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
4679 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
4680 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
4681 +
4682 + if (err)
4683 + break;
4684 +
4685 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
4686 + ldi2 == 0x3414015AU &&
4687 + bel == 0xE4008200U &&
4688 + nop == 0x08000240U)
4689 + {
4690 + regs->gr[25] = (ldi1 & 2) >> 1;
4691 + regs->gr[20] = __NR_rt_sigreturn;
4692 + regs->gr[31] = regs->iaoq[1] + 16;
4693 + regs->sr[0] = regs->iasq[1];
4694 + regs->iaoq[0] = 0x100UL;
4695 + regs->iaoq[1] = regs->iaoq[0] + 4;
4696 + regs->iasq[0] = regs->sr[2];
4697 + regs->iasq[1] = regs->sr[2];
4698 + return 2;
4699 + }
4700 + } while (0);
4701 +#endif
4702 +
4703 + return 1;
4704 +}
4705 +
4706 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4707 +{
4708 + unsigned long i;
4709 +
4710 + printk(KERN_ERR "PAX: bytes at PC: ");
4711 + for (i = 0; i < 5; i++) {
4712 + unsigned int c;
4713 + if (get_user(c, (unsigned int *)pc+i))
4714 + printk(KERN_CONT "???????? ");
4715 + else
4716 + printk(KERN_CONT "%08x ", c);
4717 + }
4718 + printk("\n");
4719 +}
4720 +#endif
4721 +
4722 int fixup_exception(struct pt_regs *regs)
4723 {
4724 const struct exception_table_entry *fix;
4725 @@ -192,8 +303,33 @@ good_area:
4726
4727 acc_type = parisc_acctyp(code,regs->iir);
4728
4729 - if ((vma->vm_flags & acc_type) != acc_type)
4730 + if ((vma->vm_flags & acc_type) != acc_type) {
4731 +
4732 +#ifdef CONFIG_PAX_PAGEEXEC
4733 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
4734 + (address & ~3UL) == instruction_pointer(regs))
4735 + {
4736 + up_read(&mm->mmap_sem);
4737 + switch (pax_handle_fetch_fault(regs)) {
4738 +
4739 +#ifdef CONFIG_PAX_EMUPLT
4740 + case 3:
4741 + return;
4742 +#endif
4743 +
4744 +#ifdef CONFIG_PAX_EMUTRAMP
4745 + case 2:
4746 + return;
4747 +#endif
4748 +
4749 + }
4750 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
4751 + do_group_exit(SIGKILL);
4752 + }
4753 +#endif
4754 +
4755 goto bad_area;
4756 + }
4757
4758 /*
4759 * If for any reason at all we couldn't handle the fault, make
4760 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
4761 index e3b1d41..8e81edf 100644
4762 --- a/arch/powerpc/include/asm/atomic.h
4763 +++ b/arch/powerpc/include/asm/atomic.h
4764 @@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
4765 return t1;
4766 }
4767
4768 +#define atomic64_read_unchecked(v) atomic64_read(v)
4769 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4770 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4771 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4772 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4773 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4774 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4775 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4776 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4777 +
4778 #endif /* __powerpc64__ */
4779
4780 #endif /* __KERNEL__ */
4781 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
4782 index 9e495c9..b6878e5 100644
4783 --- a/arch/powerpc/include/asm/cache.h
4784 +++ b/arch/powerpc/include/asm/cache.h
4785 @@ -3,6 +3,7 @@
4786
4787 #ifdef __KERNEL__
4788
4789 +#include <linux/const.h>
4790
4791 /* bytes per L1 cache line */
4792 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
4793 @@ -22,7 +23,7 @@
4794 #define L1_CACHE_SHIFT 7
4795 #endif
4796
4797 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4798 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4799
4800 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4801
4802 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
4803 index 6abf0a1..459d0f1 100644
4804 --- a/arch/powerpc/include/asm/elf.h
4805 +++ b/arch/powerpc/include/asm/elf.h
4806 @@ -28,8 +28,19 @@
4807 the loader. We need to make sure that it is out of the way of the program
4808 that it will "exec", and that there is sufficient room for the brk. */
4809
4810 -extern unsigned long randomize_et_dyn(unsigned long base);
4811 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
4812 +#define ELF_ET_DYN_BASE (0x20000000)
4813 +
4814 +#ifdef CONFIG_PAX_ASLR
4815 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
4816 +
4817 +#ifdef __powerpc64__
4818 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
4819 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
4820 +#else
4821 +#define PAX_DELTA_MMAP_LEN 15
4822 +#define PAX_DELTA_STACK_LEN 15
4823 +#endif
4824 +#endif
4825
4826 /*
4827 * Our registers are always unsigned longs, whether we're a 32 bit
4828 @@ -124,10 +135,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
4829 (0x7ff >> (PAGE_SHIFT - 12)) : \
4830 (0x3ffff >> (PAGE_SHIFT - 12)))
4831
4832 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4833 -#define arch_randomize_brk arch_randomize_brk
4834 -
4835 -
4836 #ifdef CONFIG_SPU_BASE
4837 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
4838 #define NT_SPU 1
4839 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
4840 index 8196e9c..d83a9f3 100644
4841 --- a/arch/powerpc/include/asm/exec.h
4842 +++ b/arch/powerpc/include/asm/exec.h
4843 @@ -4,6 +4,6 @@
4844 #ifndef _ASM_POWERPC_EXEC_H
4845 #define _ASM_POWERPC_EXEC_H
4846
4847 -extern unsigned long arch_align_stack(unsigned long sp);
4848 +#define arch_align_stack(x) ((x) & ~0xfUL)
4849
4850 #endif /* _ASM_POWERPC_EXEC_H */
4851 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
4852 index 5acabbd..7ea14fa 100644
4853 --- a/arch/powerpc/include/asm/kmap_types.h
4854 +++ b/arch/powerpc/include/asm/kmap_types.h
4855 @@ -10,7 +10,7 @@
4856 * 2 of the License, or (at your option) any later version.
4857 */
4858
4859 -#define KM_TYPE_NR 16
4860 +#define KM_TYPE_NR 17
4861
4862 #endif /* __KERNEL__ */
4863 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
4864 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
4865 index 8565c25..2865190 100644
4866 --- a/arch/powerpc/include/asm/mman.h
4867 +++ b/arch/powerpc/include/asm/mman.h
4868 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
4869 }
4870 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
4871
4872 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
4873 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
4874 {
4875 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
4876 }
4877 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
4878 index f072e97..b436dee 100644
4879 --- a/arch/powerpc/include/asm/page.h
4880 +++ b/arch/powerpc/include/asm/page.h
4881 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
4882 * and needs to be executable. This means the whole heap ends
4883 * up being executable.
4884 */
4885 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
4886 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4887 +#define VM_DATA_DEFAULT_FLAGS32 \
4888 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
4889 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4890
4891 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
4892 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4893 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
4894 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
4895 #endif
4896
4897 +#define ktla_ktva(addr) (addr)
4898 +#define ktva_ktla(addr) (addr)
4899 +
4900 /*
4901 * Use the top bit of the higher-level page table entries to indicate whether
4902 * the entries we point to contain hugepages. This works because we know that
4903 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
4904 index cd915d6..c10cee8 100644
4905 --- a/arch/powerpc/include/asm/page_64.h
4906 +++ b/arch/powerpc/include/asm/page_64.h
4907 @@ -154,15 +154,18 @@ do { \
4908 * stack by default, so in the absence of a PT_GNU_STACK program header
4909 * we turn execute permission off.
4910 */
4911 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
4912 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4913 +#define VM_STACK_DEFAULT_FLAGS32 \
4914 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
4915 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4916
4917 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
4918 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4919
4920 +#ifndef CONFIG_PAX_PAGEEXEC
4921 #define VM_STACK_DEFAULT_FLAGS \
4922 (is_32bit_task() ? \
4923 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
4924 +#endif
4925
4926 #include <asm-generic/getorder.h>
4927
4928 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
4929 index 292725c..f87ae14 100644
4930 --- a/arch/powerpc/include/asm/pgalloc-64.h
4931 +++ b/arch/powerpc/include/asm/pgalloc-64.h
4932 @@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
4933 #ifndef CONFIG_PPC_64K_PAGES
4934
4935 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
4936 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
4937
4938 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4939 {
4940 @@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
4941 pud_set(pud, (unsigned long)pmd);
4942 }
4943
4944 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
4945 +{
4946 + pud_populate(mm, pud, pmd);
4947 +}
4948 +
4949 #define pmd_populate(mm, pmd, pte_page) \
4950 pmd_populate_kernel(mm, pmd, page_address(pte_page))
4951 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
4952 @@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
4953 #else /* CONFIG_PPC_64K_PAGES */
4954
4955 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
4956 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
4957
4958 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
4959 pte_t *pte)
4960 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
4961 index a9cbd3b..3b67efa 100644
4962 --- a/arch/powerpc/include/asm/pgtable.h
4963 +++ b/arch/powerpc/include/asm/pgtable.h
4964 @@ -2,6 +2,7 @@
4965 #define _ASM_POWERPC_PGTABLE_H
4966 #ifdef __KERNEL__
4967
4968 +#include <linux/const.h>
4969 #ifndef __ASSEMBLY__
4970 #include <asm/processor.h> /* For TASK_SIZE */
4971 #include <asm/mmu.h>
4972 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
4973 index 4aad413..85d86bf 100644
4974 --- a/arch/powerpc/include/asm/pte-hash32.h
4975 +++ b/arch/powerpc/include/asm/pte-hash32.h
4976 @@ -21,6 +21,7 @@
4977 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
4978 #define _PAGE_USER 0x004 /* usermode access allowed */
4979 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
4980 +#define _PAGE_EXEC _PAGE_GUARDED
4981 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
4982 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
4983 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
4984 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
4985 index d24c141..b60696e 100644
4986 --- a/arch/powerpc/include/asm/reg.h
4987 +++ b/arch/powerpc/include/asm/reg.h
4988 @@ -215,6 +215,7 @@
4989 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
4990 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
4991 #define DSISR_NOHPTE 0x40000000 /* no translation found */
4992 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
4993 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
4994 #define DSISR_ISSTORE 0x02000000 /* access was a store */
4995 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
4996 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
4997 index 406b7b9..af63426 100644
4998 --- a/arch/powerpc/include/asm/thread_info.h
4999 +++ b/arch/powerpc/include/asm/thread_info.h
5000 @@ -97,7 +97,6 @@ static inline struct thread_info *current_thread_info(void)
5001 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
5002 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
5003 #define TIF_SINGLESTEP 8 /* singlestepping active */
5004 -#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
5005 #define TIF_SECCOMP 10 /* secure computing */
5006 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
5007 #define TIF_NOERROR 12 /* Force successful syscall return */
5008 @@ -106,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
5009 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
5010 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
5011 for stack store? */
5012 +#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
5013 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
5014 +#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
5015
5016 /* as above, but as bit values */
5017 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
5018 @@ -124,8 +126,10 @@ static inline struct thread_info *current_thread_info(void)
5019 #define _TIF_UPROBE (1<<TIF_UPROBE)
5020 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5021 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
5022 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5023 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
5024 - _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
5025 + _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
5026 + _TIF_GRSEC_SETXID)
5027
5028 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
5029 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
5030 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
5031 index 4db4959..335e00c 100644
5032 --- a/arch/powerpc/include/asm/uaccess.h
5033 +++ b/arch/powerpc/include/asm/uaccess.h
5034 @@ -13,6 +13,8 @@
5035 #define VERIFY_READ 0
5036 #define VERIFY_WRITE 1
5037
5038 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
5039 +
5040 /*
5041 * The fs value determines whether argument validity checking should be
5042 * performed or not. If get_fs() == USER_DS, checking is performed, with
5043 @@ -318,52 +320,6 @@ do { \
5044 extern unsigned long __copy_tofrom_user(void __user *to,
5045 const void __user *from, unsigned long size);
5046
5047 -#ifndef __powerpc64__
5048 -
5049 -static inline unsigned long copy_from_user(void *to,
5050 - const void __user *from, unsigned long n)
5051 -{
5052 - unsigned long over;
5053 -
5054 - if (access_ok(VERIFY_READ, from, n))
5055 - return __copy_tofrom_user((__force void __user *)to, from, n);
5056 - if ((unsigned long)from < TASK_SIZE) {
5057 - over = (unsigned long)from + n - TASK_SIZE;
5058 - return __copy_tofrom_user((__force void __user *)to, from,
5059 - n - over) + over;
5060 - }
5061 - return n;
5062 -}
5063 -
5064 -static inline unsigned long copy_to_user(void __user *to,
5065 - const void *from, unsigned long n)
5066 -{
5067 - unsigned long over;
5068 -
5069 - if (access_ok(VERIFY_WRITE, to, n))
5070 - return __copy_tofrom_user(to, (__force void __user *)from, n);
5071 - if ((unsigned long)to < TASK_SIZE) {
5072 - over = (unsigned long)to + n - TASK_SIZE;
5073 - return __copy_tofrom_user(to, (__force void __user *)from,
5074 - n - over) + over;
5075 - }
5076 - return n;
5077 -}
5078 -
5079 -#else /* __powerpc64__ */
5080 -
5081 -#define __copy_in_user(to, from, size) \
5082 - __copy_tofrom_user((to), (from), (size))
5083 -
5084 -extern unsigned long copy_from_user(void *to, const void __user *from,
5085 - unsigned long n);
5086 -extern unsigned long copy_to_user(void __user *to, const void *from,
5087 - unsigned long n);
5088 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
5089 - unsigned long n);
5090 -
5091 -#endif /* __powerpc64__ */
5092 -
5093 static inline unsigned long __copy_from_user_inatomic(void *to,
5094 const void __user *from, unsigned long n)
5095 {
5096 @@ -387,6 +343,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
5097 if (ret == 0)
5098 return 0;
5099 }
5100 +
5101 + if (!__builtin_constant_p(n))
5102 + check_object_size(to, n, false);
5103 +
5104 return __copy_tofrom_user((__force void __user *)to, from, n);
5105 }
5106
5107 @@ -413,6 +373,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
5108 if (ret == 0)
5109 return 0;
5110 }
5111 +
5112 + if (!__builtin_constant_p(n))
5113 + check_object_size(from, n, true);
5114 +
5115 return __copy_tofrom_user(to, (__force const void __user *)from, n);
5116 }
5117
5118 @@ -430,6 +394,92 @@ static inline unsigned long __copy_to_user(void __user *to,
5119 return __copy_to_user_inatomic(to, from, size);
5120 }
5121
5122 +#ifndef __powerpc64__
5123 +
5124 +static inline unsigned long __must_check copy_from_user(void *to,
5125 + const void __user *from, unsigned long n)
5126 +{
5127 + unsigned long over;
5128 +
5129 + if ((long)n < 0)
5130 + return n;
5131 +
5132 + if (access_ok(VERIFY_READ, from, n)) {
5133 + if (!__builtin_constant_p(n))
5134 + check_object_size(to, n, false);
5135 + return __copy_tofrom_user((__force void __user *)to, from, n);
5136 + }
5137 + if ((unsigned long)from < TASK_SIZE) {
5138 + over = (unsigned long)from + n - TASK_SIZE;
5139 + if (!__builtin_constant_p(n - over))
5140 + check_object_size(to, n - over, false);
5141 + return __copy_tofrom_user((__force void __user *)to, from,
5142 + n - over) + over;
5143 + }
5144 + return n;
5145 +}
5146 +
5147 +static inline unsigned long __must_check copy_to_user(void __user *to,
5148 + const void *from, unsigned long n)
5149 +{
5150 + unsigned long over;
5151 +
5152 + if ((long)n < 0)
5153 + return n;
5154 +
5155 + if (access_ok(VERIFY_WRITE, to, n)) {
5156 + if (!__builtin_constant_p(n))
5157 + check_object_size(from, n, true);
5158 + return __copy_tofrom_user(to, (__force void __user *)from, n);
5159 + }
5160 + if ((unsigned long)to < TASK_SIZE) {
5161 + over = (unsigned long)to + n - TASK_SIZE;
5162 + if (!__builtin_constant_p(n))
5163 + check_object_size(from, n - over, true);
5164 + return __copy_tofrom_user(to, (__force void __user *)from,
5165 + n - over) + over;
5166 + }
5167 + return n;
5168 +}
5169 +
5170 +#else /* __powerpc64__ */
5171 +
5172 +#define __copy_in_user(to, from, size) \
5173 + __copy_tofrom_user((to), (from), (size))
5174 +
5175 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
5176 +{
5177 + if ((long)n < 0 || n > INT_MAX)
5178 + return n;
5179 +
5180 + if (!__builtin_constant_p(n))
5181 + check_object_size(to, n, false);
5182 +
5183 + if (likely(access_ok(VERIFY_READ, from, n)))
5184 + n = __copy_from_user(to, from, n);
5185 + else
5186 + memset(to, 0, n);
5187 + return n;
5188 +}
5189 +
5190 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
5191 +{
5192 + if ((long)n < 0 || n > INT_MAX)
5193 + return n;
5194 +
5195 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
5196 + if (!__builtin_constant_p(n))
5197 + check_object_size(from, n, true);
5198 + n = __copy_to_user(to, from, n);
5199 + }
5200 + return n;
5201 +}
5202 +
5203 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
5204 + unsigned long n);
5205 +
5206 +#endif /* __powerpc64__ */
5207 +
5208 extern unsigned long __clear_user(void __user *addr, unsigned long size);
5209
5210 static inline unsigned long clear_user(void __user *addr, unsigned long size)
5211 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
5212 index 4684e33..acc4d19e 100644
5213 --- a/arch/powerpc/kernel/exceptions-64e.S
5214 +++ b/arch/powerpc/kernel/exceptions-64e.S
5215 @@ -715,6 +715,7 @@ storage_fault_common:
5216 std r14,_DAR(r1)
5217 std r15,_DSISR(r1)
5218 addi r3,r1,STACK_FRAME_OVERHEAD
5219 + bl .save_nvgprs
5220 mr r4,r14
5221 mr r5,r15
5222 ld r14,PACA_EXGEN+EX_R14(r13)
5223 @@ -723,8 +724,7 @@ storage_fault_common:
5224 cmpdi r3,0
5225 bne- 1f
5226 b .ret_from_except_lite
5227 -1: bl .save_nvgprs
5228 - mr r5,r3
5229 +1: mr r5,r3
5230 addi r3,r1,STACK_FRAME_OVERHEAD
5231 ld r4,_DAR(r1)
5232 bl .bad_page_fault
5233 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
5234 index 10b658a..e542888 100644
5235 --- a/arch/powerpc/kernel/exceptions-64s.S
5236 +++ b/arch/powerpc/kernel/exceptions-64s.S
5237 @@ -1013,10 +1013,10 @@ handle_page_fault:
5238 11: ld r4,_DAR(r1)
5239 ld r5,_DSISR(r1)
5240 addi r3,r1,STACK_FRAME_OVERHEAD
5241 + bl .save_nvgprs
5242 bl .do_page_fault
5243 cmpdi r3,0
5244 beq+ 12f
5245 - bl .save_nvgprs
5246 mr r5,r3
5247 addi r3,r1,STACK_FRAME_OVERHEAD
5248 lwz r4,_DAR(r1)
5249 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
5250 index 2e3200c..72095ce 100644
5251 --- a/arch/powerpc/kernel/module_32.c
5252 +++ b/arch/powerpc/kernel/module_32.c
5253 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
5254 me->arch.core_plt_section = i;
5255 }
5256 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
5257 - printk("Module doesn't contain .plt or .init.plt sections.\n");
5258 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
5259 return -ENOEXEC;
5260 }
5261
5262 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
5263
5264 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
5265 /* Init, or core PLT? */
5266 - if (location >= mod->module_core
5267 - && location < mod->module_core + mod->core_size)
5268 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
5269 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
5270 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
5271 - else
5272 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
5273 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
5274 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
5275 + else {
5276 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
5277 + return ~0UL;
5278 + }
5279
5280 /* Find this entry, or if that fails, the next avail. entry */
5281 while (entry->jump[0]) {
5282 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
5283 index ba48233..16ac31d 100644
5284 --- a/arch/powerpc/kernel/process.c
5285 +++ b/arch/powerpc/kernel/process.c
5286 @@ -680,8 +680,8 @@ void show_regs(struct pt_regs * regs)
5287 * Lookup NIP late so we have the best change of getting the
5288 * above info out without failing
5289 */
5290 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
5291 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
5292 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
5293 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
5294 #endif
5295 show_stack(current, (unsigned long *) regs->gpr[1]);
5296 if (!user_mode(regs))
5297 @@ -1175,10 +1175,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
5298 newsp = stack[0];
5299 ip = stack[STACK_FRAME_LR_SAVE];
5300 if (!firstframe || ip != lr) {
5301 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
5302 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
5303 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
5304 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
5305 - printk(" (%pS)",
5306 + printk(" (%pA)",
5307 (void *)current->ret_stack[curr_frame].ret);
5308 curr_frame--;
5309 }
5310 @@ -1198,7 +1198,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
5311 struct pt_regs *regs = (struct pt_regs *)
5312 (sp + STACK_FRAME_OVERHEAD);
5313 lr = regs->link;
5314 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
5315 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
5316 regs->trap, (void *)regs->nip, (void *)lr);
5317 firstframe = 1;
5318 }
5319 @@ -1240,58 +1240,3 @@ void __ppc64_runlatch_off(void)
5320 mtspr(SPRN_CTRLT, ctrl);
5321 }
5322 #endif /* CONFIG_PPC64 */
5323 -
5324 -unsigned long arch_align_stack(unsigned long sp)
5325 -{
5326 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5327 - sp -= get_random_int() & ~PAGE_MASK;
5328 - return sp & ~0xf;
5329 -}
5330 -
5331 -static inline unsigned long brk_rnd(void)
5332 -{
5333 - unsigned long rnd = 0;
5334 -
5335 - /* 8MB for 32bit, 1GB for 64bit */
5336 - if (is_32bit_task())
5337 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
5338 - else
5339 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
5340 -
5341 - return rnd << PAGE_SHIFT;
5342 -}
5343 -
5344 -unsigned long arch_randomize_brk(struct mm_struct *mm)
5345 -{
5346 - unsigned long base = mm->brk;
5347 - unsigned long ret;
5348 -
5349 -#ifdef CONFIG_PPC_STD_MMU_64
5350 - /*
5351 - * If we are using 1TB segments and we are allowed to randomise
5352 - * the heap, we can put it above 1TB so it is backed by a 1TB
5353 - * segment. Otherwise the heap will be in the bottom 1TB
5354 - * which always uses 256MB segments and this may result in a
5355 - * performance penalty.
5356 - */
5357 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
5358 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
5359 -#endif
5360 -
5361 - ret = PAGE_ALIGN(base + brk_rnd());
5362 -
5363 - if (ret < mm->brk)
5364 - return mm->brk;
5365 -
5366 - return ret;
5367 -}
5368 -
5369 -unsigned long randomize_et_dyn(unsigned long base)
5370 -{
5371 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
5372 -
5373 - if (ret < base)
5374 - return base;
5375 -
5376 - return ret;
5377 -}
5378 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
5379 index 79d8e56..38ffcbb 100644
5380 --- a/arch/powerpc/kernel/ptrace.c
5381 +++ b/arch/powerpc/kernel/ptrace.c
5382 @@ -1663,6 +1663,10 @@ long arch_ptrace(struct task_struct *child, long request,
5383 return ret;
5384 }
5385
5386 +#ifdef CONFIG_GRKERNSEC_SETXID
5387 +extern void gr_delayed_cred_worker(void);
5388 +#endif
5389 +
5390 /*
5391 * We must return the syscall number to actually look up in the table.
5392 * This can be -1L to skip running any syscall at all.
5393 @@ -1673,6 +1677,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
5394
5395 secure_computing_strict(regs->gpr[0]);
5396
5397 +#ifdef CONFIG_GRKERNSEC_SETXID
5398 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5399 + gr_delayed_cred_worker();
5400 +#endif
5401 +
5402 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
5403 tracehook_report_syscall_entry(regs))
5404 /*
5405 @@ -1707,6 +1716,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
5406 {
5407 int step;
5408
5409 +#ifdef CONFIG_GRKERNSEC_SETXID
5410 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5411 + gr_delayed_cred_worker();
5412 +#endif
5413 +
5414 audit_syscall_exit(regs);
5415
5416 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5417 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
5418 index 804e323..79181c1 100644
5419 --- a/arch/powerpc/kernel/signal_32.c
5420 +++ b/arch/powerpc/kernel/signal_32.c
5421 @@ -851,7 +851,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
5422 /* Save user registers on the stack */
5423 frame = &rt_sf->uc.uc_mcontext;
5424 addr = frame;
5425 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
5426 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
5427 if (save_user_regs(regs, frame, 0, 1))
5428 goto badframe;
5429 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
5430 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
5431 index d183f87..1867f1a 100644
5432 --- a/arch/powerpc/kernel/signal_64.c
5433 +++ b/arch/powerpc/kernel/signal_64.c
5434 @@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
5435 current->thread.fpscr.val = 0;
5436
5437 /* Set up to return from userspace. */
5438 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
5439 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
5440 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
5441 } else {
5442 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
5443 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
5444 index 3251840..3f7c77a 100644
5445 --- a/arch/powerpc/kernel/traps.c
5446 +++ b/arch/powerpc/kernel/traps.c
5447 @@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
5448 return flags;
5449 }
5450
5451 +extern void gr_handle_kernel_exploit(void);
5452 +
5453 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
5454 int signr)
5455 {
5456 @@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
5457 panic("Fatal exception in interrupt");
5458 if (panic_on_oops)
5459 panic("Fatal exception");
5460 +
5461 + gr_handle_kernel_exploit();
5462 +
5463 do_exit(signr);
5464 }
5465
5466 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
5467 index 1b2076f..835e4be 100644
5468 --- a/arch/powerpc/kernel/vdso.c
5469 +++ b/arch/powerpc/kernel/vdso.c
5470 @@ -34,6 +34,7 @@
5471 #include <asm/firmware.h>
5472 #include <asm/vdso.h>
5473 #include <asm/vdso_datapage.h>
5474 +#include <asm/mman.h>
5475
5476 #include "setup.h"
5477
5478 @@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
5479 vdso_base = VDSO32_MBASE;
5480 #endif
5481
5482 - current->mm->context.vdso_base = 0;
5483 + current->mm->context.vdso_base = ~0UL;
5484
5485 /* vDSO has a problem and was disabled, just don't "enable" it for the
5486 * process
5487 @@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
5488 vdso_base = get_unmapped_area(NULL, vdso_base,
5489 (vdso_pages << PAGE_SHIFT) +
5490 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
5491 - 0, 0);
5492 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
5493 if (IS_ERR_VALUE(vdso_base)) {
5494 rc = vdso_base;
5495 goto fail_mmapsem;
5496 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
5497 index 5eea6f3..5d10396 100644
5498 --- a/arch/powerpc/lib/usercopy_64.c
5499 +++ b/arch/powerpc/lib/usercopy_64.c
5500 @@ -9,22 +9,6 @@
5501 #include <linux/module.h>
5502 #include <asm/uaccess.h>
5503
5504 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5505 -{
5506 - if (likely(access_ok(VERIFY_READ, from, n)))
5507 - n = __copy_from_user(to, from, n);
5508 - else
5509 - memset(to, 0, n);
5510 - return n;
5511 -}
5512 -
5513 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5514 -{
5515 - if (likely(access_ok(VERIFY_WRITE, to, n)))
5516 - n = __copy_to_user(to, from, n);
5517 - return n;
5518 -}
5519 -
5520 unsigned long copy_in_user(void __user *to, const void __user *from,
5521 unsigned long n)
5522 {
5523 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
5524 return n;
5525 }
5526
5527 -EXPORT_SYMBOL(copy_from_user);
5528 -EXPORT_SYMBOL(copy_to_user);
5529 EXPORT_SYMBOL(copy_in_user);
5530
5531 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
5532 index 0a6b283..7674925 100644
5533 --- a/arch/powerpc/mm/fault.c
5534 +++ b/arch/powerpc/mm/fault.c
5535 @@ -32,6 +32,10 @@
5536 #include <linux/perf_event.h>
5537 #include <linux/magic.h>
5538 #include <linux/ratelimit.h>
5539 +#include <linux/slab.h>
5540 +#include <linux/pagemap.h>
5541 +#include <linux/compiler.h>
5542 +#include <linux/unistd.h>
5543
5544 #include <asm/firmware.h>
5545 #include <asm/page.h>
5546 @@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
5547 }
5548 #endif
5549
5550 +#ifdef CONFIG_PAX_PAGEEXEC
5551 +/*
5552 + * PaX: decide what to do with offenders (regs->nip = fault address)
5553 + *
5554 + * returns 1 when task should be killed
5555 + */
5556 +static int pax_handle_fetch_fault(struct pt_regs *regs)
5557 +{
5558 + return 1;
5559 +}
5560 +
5561 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5562 +{
5563 + unsigned long i;
5564 +
5565 + printk(KERN_ERR "PAX: bytes at PC: ");
5566 + for (i = 0; i < 5; i++) {
5567 + unsigned int c;
5568 + if (get_user(c, (unsigned int __user *)pc+i))
5569 + printk(KERN_CONT "???????? ");
5570 + else
5571 + printk(KERN_CONT "%08x ", c);
5572 + }
5573 + printk("\n");
5574 +}
5575 +#endif
5576 +
5577 /*
5578 * Check whether the instruction at regs->nip is a store using
5579 * an update addressing form which will update r1.
5580 @@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
5581 * indicate errors in DSISR but can validly be set in SRR1.
5582 */
5583 if (trap == 0x400)
5584 - error_code &= 0x48200000;
5585 + error_code &= 0x58200000;
5586 else
5587 is_write = error_code & DSISR_ISSTORE;
5588 #else
5589 @@ -367,7 +398,7 @@ good_area:
5590 * "undefined". Of those that can be set, this is the only
5591 * one which seems bad.
5592 */
5593 - if (error_code & 0x10000000)
5594 + if (error_code & DSISR_GUARDED)
5595 /* Guarded storage error. */
5596 goto bad_area;
5597 #endif /* CONFIG_8xx */
5598 @@ -382,7 +413,7 @@ good_area:
5599 * processors use the same I/D cache coherency mechanism
5600 * as embedded.
5601 */
5602 - if (error_code & DSISR_PROTFAULT)
5603 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
5604 goto bad_area;
5605 #endif /* CONFIG_PPC_STD_MMU */
5606
5607 @@ -465,6 +496,23 @@ bad_area:
5608 bad_area_nosemaphore:
5609 /* User mode accesses cause a SIGSEGV */
5610 if (user_mode(regs)) {
5611 +
5612 +#ifdef CONFIG_PAX_PAGEEXEC
5613 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
5614 +#ifdef CONFIG_PPC_STD_MMU
5615 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
5616 +#else
5617 + if (is_exec && regs->nip == address) {
5618 +#endif
5619 + switch (pax_handle_fetch_fault(regs)) {
5620 + }
5621 +
5622 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
5623 + do_group_exit(SIGKILL);
5624 + }
5625 + }
5626 +#endif
5627 +
5628 _exception(SIGSEGV, regs, code, address);
5629 return 0;
5630 }
5631 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
5632 index 67a42ed..c16ef80 100644
5633 --- a/arch/powerpc/mm/mmap_64.c
5634 +++ b/arch/powerpc/mm/mmap_64.c
5635 @@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
5636 {
5637 unsigned long rnd = 0;
5638
5639 +#ifdef CONFIG_PAX_RANDMMAP
5640 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
5641 +#endif
5642 +
5643 if (current->flags & PF_RANDOMIZE) {
5644 /* 8MB for 32bit, 1GB for 64bit */
5645 if (is_32bit_task())
5646 @@ -91,10 +95,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5647 */
5648 if (mmap_is_legacy()) {
5649 mm->mmap_base = TASK_UNMAPPED_BASE;
5650 +
5651 +#ifdef CONFIG_PAX_RANDMMAP
5652 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5653 + mm->mmap_base += mm->delta_mmap;
5654 +#endif
5655 +
5656 mm->get_unmapped_area = arch_get_unmapped_area;
5657 mm->unmap_area = arch_unmap_area;
5658 } else {
5659 mm->mmap_base = mmap_base();
5660 +
5661 +#ifdef CONFIG_PAX_RANDMMAP
5662 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5663 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5664 +#endif
5665 +
5666 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5667 mm->unmap_area = arch_unmap_area_topdown;
5668 }
5669 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
5670 index 5829d2a..af84242 100644
5671 --- a/arch/powerpc/mm/slice.c
5672 +++ b/arch/powerpc/mm/slice.c
5673 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
5674 if ((mm->task_size - len) < addr)
5675 return 0;
5676 vma = find_vma(mm, addr);
5677 - return (!vma || (addr + len) <= vma->vm_start);
5678 + return check_heap_stack_gap(vma, addr, len, 0);
5679 }
5680
5681 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
5682 @@ -272,7 +272,7 @@ full_search:
5683 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
5684 continue;
5685 }
5686 - if (!vma || addr + len <= vma->vm_start) {
5687 + if (check_heap_stack_gap(vma, addr, len, 0)) {
5688 /*
5689 * Remember the place where we stopped the search:
5690 */
5691 @@ -329,10 +329,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
5692 }
5693 }
5694
5695 - addr = mm->mmap_base;
5696 - while (addr > len) {
5697 + if (mm->mmap_base < len)
5698 + addr = -ENOMEM;
5699 + else
5700 + addr = mm->mmap_base - len;
5701 +
5702 + while (!IS_ERR_VALUE(addr)) {
5703 /* Go down by chunk size */
5704 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
5705 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
5706
5707 /* Check for hit with different page size */
5708 mask = slice_range_to_mask(addr, len);
5709 @@ -352,7 +356,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
5710 * return with success:
5711 */
5712 vma = find_vma(mm, addr);
5713 - if (!vma || (addr + len) <= vma->vm_start) {
5714 + if (check_heap_stack_gap(vma, addr, len, 0)) {
5715 /* remember the address as a hint for next time */
5716 if (use_cache)
5717 mm->free_area_cache = addr;
5718 @@ -364,7 +368,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
5719 mm->cached_hole_size = vma->vm_start - addr;
5720
5721 /* try just below the current vma->vm_start */
5722 - addr = vma->vm_start;
5723 + addr = skip_heap_stack_gap(vma, len, 0);
5724 }
5725
5726 /*
5727 @@ -442,6 +446,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
5728 if (fixed && addr > (mm->task_size - len))
5729 return -EINVAL;
5730
5731 +#ifdef CONFIG_PAX_RANDMMAP
5732 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
5733 + addr = 0;
5734 +#endif
5735 +
5736 /* If hint, make sure it matches our alignment restrictions */
5737 if (!fixed && addr) {
5738 addr = _ALIGN_UP(addr, 1ul << pshift);
5739 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
5740 index c797832..ce575c8 100644
5741 --- a/arch/s390/include/asm/atomic.h
5742 +++ b/arch/s390/include/asm/atomic.h
5743 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
5744 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
5745 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5746
5747 +#define atomic64_read_unchecked(v) atomic64_read(v)
5748 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5749 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5750 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5751 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5752 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5753 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5754 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5755 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5756 +
5757 #define smp_mb__before_atomic_dec() smp_mb()
5758 #define smp_mb__after_atomic_dec() smp_mb()
5759 #define smp_mb__before_atomic_inc() smp_mb()
5760 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
5761 index 4d7ccac..d03d0ad 100644
5762 --- a/arch/s390/include/asm/cache.h
5763 +++ b/arch/s390/include/asm/cache.h
5764 @@ -9,8 +9,10 @@
5765 #ifndef __ARCH_S390_CACHE_H
5766 #define __ARCH_S390_CACHE_H
5767
5768 -#define L1_CACHE_BYTES 256
5769 +#include <linux/const.h>
5770 +
5771 #define L1_CACHE_SHIFT 8
5772 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5773 #define NET_SKB_PAD 32
5774
5775 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5776 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
5777 index 178ff96..8c93bd1 100644
5778 --- a/arch/s390/include/asm/elf.h
5779 +++ b/arch/s390/include/asm/elf.h
5780 @@ -160,8 +160,14 @@ extern unsigned int vdso_enabled;
5781 the loader. We need to make sure that it is out of the way of the program
5782 that it will "exec", and that there is sufficient room for the brk. */
5783
5784 -extern unsigned long randomize_et_dyn(unsigned long base);
5785 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
5786 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
5787 +
5788 +#ifdef CONFIG_PAX_ASLR
5789 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
5790 +
5791 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
5792 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
5793 +#endif
5794
5795 /* This yields a mask that user programs can use to figure out what
5796 instruction set this CPU supports. */
5797 @@ -210,9 +216,6 @@ struct linux_binprm;
5798 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
5799 int arch_setup_additional_pages(struct linux_binprm *, int);
5800
5801 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5802 -#define arch_randomize_brk arch_randomize_brk
5803 -
5804 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
5805
5806 #endif
5807 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
5808 index c4a93d6..4d2a9b4 100644
5809 --- a/arch/s390/include/asm/exec.h
5810 +++ b/arch/s390/include/asm/exec.h
5811 @@ -7,6 +7,6 @@
5812 #ifndef __ASM_EXEC_H
5813 #define __ASM_EXEC_H
5814
5815 -extern unsigned long arch_align_stack(unsigned long sp);
5816 +#define arch_align_stack(x) ((x) & ~0xfUL)
5817
5818 #endif /* __ASM_EXEC_H */
5819 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
5820 index 34268df..ea97318 100644
5821 --- a/arch/s390/include/asm/uaccess.h
5822 +++ b/arch/s390/include/asm/uaccess.h
5823 @@ -252,6 +252,10 @@ static inline unsigned long __must_check
5824 copy_to_user(void __user *to, const void *from, unsigned long n)
5825 {
5826 might_fault();
5827 +
5828 + if ((long)n < 0)
5829 + return n;
5830 +
5831 if (access_ok(VERIFY_WRITE, to, n))
5832 n = __copy_to_user(to, from, n);
5833 return n;
5834 @@ -277,6 +281,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
5835 static inline unsigned long __must_check
5836 __copy_from_user(void *to, const void __user *from, unsigned long n)
5837 {
5838 + if ((long)n < 0)
5839 + return n;
5840 +
5841 if (__builtin_constant_p(n) && (n <= 256))
5842 return uaccess.copy_from_user_small(n, from, to);
5843 else
5844 @@ -308,10 +315,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
5845 static inline unsigned long __must_check
5846 copy_from_user(void *to, const void __user *from, unsigned long n)
5847 {
5848 - unsigned int sz = __compiletime_object_size(to);
5849 + size_t sz = __compiletime_object_size(to);
5850
5851 might_fault();
5852 - if (unlikely(sz != -1 && sz < n)) {
5853 +
5854 + if ((long)n < 0)
5855 + return n;
5856 +
5857 + if (unlikely(sz != (size_t)-1 && sz < n)) {
5858 copy_from_user_overflow();
5859 return n;
5860 }
5861 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
5862 index 4610dea..cf0af21 100644
5863 --- a/arch/s390/kernel/module.c
5864 +++ b/arch/s390/kernel/module.c
5865 @@ -171,11 +171,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
5866
5867 /* Increase core size by size of got & plt and set start
5868 offsets for got and plt. */
5869 - me->core_size = ALIGN(me->core_size, 4);
5870 - me->arch.got_offset = me->core_size;
5871 - me->core_size += me->arch.got_size;
5872 - me->arch.plt_offset = me->core_size;
5873 - me->core_size += me->arch.plt_size;
5874 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
5875 + me->arch.got_offset = me->core_size_rw;
5876 + me->core_size_rw += me->arch.got_size;
5877 + me->arch.plt_offset = me->core_size_rx;
5878 + me->core_size_rx += me->arch.plt_size;
5879 return 0;
5880 }
5881
5882 @@ -252,7 +252,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5883 if (info->got_initialized == 0) {
5884 Elf_Addr *gotent;
5885
5886 - gotent = me->module_core + me->arch.got_offset +
5887 + gotent = me->module_core_rw + me->arch.got_offset +
5888 info->got_offset;
5889 *gotent = val;
5890 info->got_initialized = 1;
5891 @@ -276,7 +276,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5892 else if (r_type == R_390_GOTENT ||
5893 r_type == R_390_GOTPLTENT)
5894 *(unsigned int *) loc =
5895 - (val + (Elf_Addr) me->module_core - loc) >> 1;
5896 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
5897 else if (r_type == R_390_GOT64 ||
5898 r_type == R_390_GOTPLT64)
5899 *(unsigned long *) loc = val;
5900 @@ -290,7 +290,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5901 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
5902 if (info->plt_initialized == 0) {
5903 unsigned int *ip;
5904 - ip = me->module_core + me->arch.plt_offset +
5905 + ip = me->module_core_rx + me->arch.plt_offset +
5906 info->plt_offset;
5907 #ifndef CONFIG_64BIT
5908 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
5909 @@ -315,7 +315,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5910 val - loc + 0xffffUL < 0x1ffffeUL) ||
5911 (r_type == R_390_PLT32DBL &&
5912 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
5913 - val = (Elf_Addr) me->module_core +
5914 + val = (Elf_Addr) me->module_core_rx +
5915 me->arch.plt_offset +
5916 info->plt_offset;
5917 val += rela->r_addend - loc;
5918 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5919 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
5920 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
5921 val = val + rela->r_addend -
5922 - ((Elf_Addr) me->module_core + me->arch.got_offset);
5923 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
5924 if (r_type == R_390_GOTOFF16)
5925 *(unsigned short *) loc = val;
5926 else if (r_type == R_390_GOTOFF32)
5927 @@ -347,7 +347,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5928 break;
5929 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
5930 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
5931 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
5932 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
5933 rela->r_addend - loc;
5934 if (r_type == R_390_GOTPC)
5935 *(unsigned int *) loc = val;
5936 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
5937 index cd31ad4..201c5a3 100644
5938 --- a/arch/s390/kernel/process.c
5939 +++ b/arch/s390/kernel/process.c
5940 @@ -283,39 +283,3 @@ unsigned long get_wchan(struct task_struct *p)
5941 }
5942 return 0;
5943 }
5944 -
5945 -unsigned long arch_align_stack(unsigned long sp)
5946 -{
5947 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5948 - sp -= get_random_int() & ~PAGE_MASK;
5949 - return sp & ~0xf;
5950 -}
5951 -
5952 -static inline unsigned long brk_rnd(void)
5953 -{
5954 - /* 8MB for 32bit, 1GB for 64bit */
5955 - if (is_32bit_task())
5956 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
5957 - else
5958 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
5959 -}
5960 -
5961 -unsigned long arch_randomize_brk(struct mm_struct *mm)
5962 -{
5963 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
5964 -
5965 - if (ret < mm->brk)
5966 - return mm->brk;
5967 - return ret;
5968 -}
5969 -
5970 -unsigned long randomize_et_dyn(unsigned long base)
5971 -{
5972 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
5973 -
5974 - if (!(current->flags & PF_RANDOMIZE))
5975 - return base;
5976 - if (ret < base)
5977 - return base;
5978 - return ret;
5979 -}
5980 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
5981 index c59a5ef..3fae59c 100644
5982 --- a/arch/s390/mm/mmap.c
5983 +++ b/arch/s390/mm/mmap.c
5984 @@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5985 */
5986 if (mmap_is_legacy()) {
5987 mm->mmap_base = TASK_UNMAPPED_BASE;
5988 +
5989 +#ifdef CONFIG_PAX_RANDMMAP
5990 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5991 + mm->mmap_base += mm->delta_mmap;
5992 +#endif
5993 +
5994 mm->get_unmapped_area = arch_get_unmapped_area;
5995 mm->unmap_area = arch_unmap_area;
5996 } else {
5997 mm->mmap_base = mmap_base();
5998 +
5999 +#ifdef CONFIG_PAX_RANDMMAP
6000 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6001 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6002 +#endif
6003 +
6004 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6005 mm->unmap_area = arch_unmap_area_topdown;
6006 }
6007 @@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6008 */
6009 if (mmap_is_legacy()) {
6010 mm->mmap_base = TASK_UNMAPPED_BASE;
6011 +
6012 +#ifdef CONFIG_PAX_RANDMMAP
6013 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6014 + mm->mmap_base += mm->delta_mmap;
6015 +#endif
6016 +
6017 mm->get_unmapped_area = s390_get_unmapped_area;
6018 mm->unmap_area = arch_unmap_area;
6019 } else {
6020 mm->mmap_base = mmap_base();
6021 +
6022 +#ifdef CONFIG_PAX_RANDMMAP
6023 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6024 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6025 +#endif
6026 +
6027 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
6028 mm->unmap_area = arch_unmap_area_topdown;
6029 }
6030 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
6031 index ae3d59f..f65f075 100644
6032 --- a/arch/score/include/asm/cache.h
6033 +++ b/arch/score/include/asm/cache.h
6034 @@ -1,7 +1,9 @@
6035 #ifndef _ASM_SCORE_CACHE_H
6036 #define _ASM_SCORE_CACHE_H
6037
6038 +#include <linux/const.h>
6039 +
6040 #define L1_CACHE_SHIFT 4
6041 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6042 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6043
6044 #endif /* _ASM_SCORE_CACHE_H */
6045 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
6046 index f9f3cd5..58ff438 100644
6047 --- a/arch/score/include/asm/exec.h
6048 +++ b/arch/score/include/asm/exec.h
6049 @@ -1,6 +1,6 @@
6050 #ifndef _ASM_SCORE_EXEC_H
6051 #define _ASM_SCORE_EXEC_H
6052
6053 -extern unsigned long arch_align_stack(unsigned long sp);
6054 +#define arch_align_stack(x) (x)
6055
6056 #endif /* _ASM_SCORE_EXEC_H */
6057 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
6058 index 637970c..0b6556b 100644
6059 --- a/arch/score/kernel/process.c
6060 +++ b/arch/score/kernel/process.c
6061 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
6062
6063 return task_pt_regs(task)->cp0_epc;
6064 }
6065 -
6066 -unsigned long arch_align_stack(unsigned long sp)
6067 -{
6068 - return sp;
6069 -}
6070 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
6071 index ef9e555..331bd29 100644
6072 --- a/arch/sh/include/asm/cache.h
6073 +++ b/arch/sh/include/asm/cache.h
6074 @@ -9,10 +9,11 @@
6075 #define __ASM_SH_CACHE_H
6076 #ifdef __KERNEL__
6077
6078 +#include <linux/const.h>
6079 #include <linux/init.h>
6080 #include <cpu/cache.h>
6081
6082 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6083 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6084
6085 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
6086
6087 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
6088 index afeb710..e8366ef 100644
6089 --- a/arch/sh/mm/mmap.c
6090 +++ b/arch/sh/mm/mmap.c
6091 @@ -49,6 +49,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
6092 struct vm_area_struct *vma;
6093 unsigned long start_addr;
6094 int do_colour_align;
6095 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6096
6097 if (flags & MAP_FIXED) {
6098 /* We do not accept a shared mapping if it would violate
6099 @@ -74,8 +75,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
6100 addr = PAGE_ALIGN(addr);
6101
6102 vma = find_vma(mm, addr);
6103 - if (TASK_SIZE - len >= addr &&
6104 - (!vma || addr + len <= vma->vm_start))
6105 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6106 return addr;
6107 }
6108
6109 @@ -106,7 +106,7 @@ full_search:
6110 }
6111 return -ENOMEM;
6112 }
6113 - if (likely(!vma || addr + len <= vma->vm_start)) {
6114 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
6115 /*
6116 * Remember the place where we stopped the search:
6117 */
6118 @@ -131,6 +131,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6119 struct mm_struct *mm = current->mm;
6120 unsigned long addr = addr0;
6121 int do_colour_align;
6122 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6123
6124 if (flags & MAP_FIXED) {
6125 /* We do not accept a shared mapping if it would violate
6126 @@ -157,8 +158,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6127 addr = PAGE_ALIGN(addr);
6128
6129 vma = find_vma(mm, addr);
6130 - if (TASK_SIZE - len >= addr &&
6131 - (!vma || addr + len <= vma->vm_start))
6132 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6133 return addr;
6134 }
6135
6136 @@ -179,7 +179,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6137 /* make sure it can fit in the remaining address space */
6138 if (likely(addr > len)) {
6139 vma = find_vma(mm, addr-len);
6140 - if (!vma || addr <= vma->vm_start) {
6141 + if (check_heap_stack_gap(vma, addr - len, len, offset)) {
6142 /* remember the address as a hint for next time */
6143 return (mm->free_area_cache = addr-len);
6144 }
6145 @@ -188,18 +188,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6146 if (unlikely(mm->mmap_base < len))
6147 goto bottomup;
6148
6149 - addr = mm->mmap_base-len;
6150 - if (do_colour_align)
6151 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6152 + addr = mm->mmap_base - len;
6153
6154 do {
6155 + if (do_colour_align)
6156 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6157 /*
6158 * Lookup failure means no vma is above this address,
6159 * else if new region fits below vma->vm_start,
6160 * return with success:
6161 */
6162 vma = find_vma(mm, addr);
6163 - if (likely(!vma || addr+len <= vma->vm_start)) {
6164 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
6165 /* remember the address as a hint for next time */
6166 return (mm->free_area_cache = addr);
6167 }
6168 @@ -209,10 +209,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6169 mm->cached_hole_size = vma->vm_start - addr;
6170
6171 /* try just below the current vma->vm_start */
6172 - addr = vma->vm_start-len;
6173 - if (do_colour_align)
6174 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6175 - } while (likely(len < vma->vm_start));
6176 + addr = skip_heap_stack_gap(vma, len, offset);
6177 + } while (!IS_ERR_VALUE(addr));
6178
6179 bottomup:
6180 /*
6181 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
6182 index be56a24..443328f 100644
6183 --- a/arch/sparc/include/asm/atomic_64.h
6184 +++ b/arch/sparc/include/asm/atomic_64.h
6185 @@ -14,18 +14,40 @@
6186 #define ATOMIC64_INIT(i) { (i) }
6187
6188 #define atomic_read(v) (*(volatile int *)&(v)->counter)
6189 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
6190 +{
6191 + return v->counter;
6192 +}
6193 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
6194 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6195 +{
6196 + return v->counter;
6197 +}
6198
6199 #define atomic_set(v, i) (((v)->counter) = i)
6200 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
6201 +{
6202 + v->counter = i;
6203 +}
6204 #define atomic64_set(v, i) (((v)->counter) = i)
6205 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6206 +{
6207 + v->counter = i;
6208 +}
6209
6210 extern void atomic_add(int, atomic_t *);
6211 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
6212 extern void atomic64_add(long, atomic64_t *);
6213 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
6214 extern void atomic_sub(int, atomic_t *);
6215 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
6216 extern void atomic64_sub(long, atomic64_t *);
6217 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
6218
6219 extern int atomic_add_ret(int, atomic_t *);
6220 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
6221 extern long atomic64_add_ret(long, atomic64_t *);
6222 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
6223 extern int atomic_sub_ret(int, atomic_t *);
6224 extern long atomic64_sub_ret(long, atomic64_t *);
6225
6226 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
6227 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
6228
6229 #define atomic_inc_return(v) atomic_add_ret(1, v)
6230 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6231 +{
6232 + return atomic_add_ret_unchecked(1, v);
6233 +}
6234 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
6235 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
6236 +{
6237 + return atomic64_add_ret_unchecked(1, v);
6238 +}
6239
6240 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
6241 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
6242
6243 #define atomic_add_return(i, v) atomic_add_ret(i, v)
6244 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
6245 +{
6246 + return atomic_add_ret_unchecked(i, v);
6247 +}
6248 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
6249 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6250 +{
6251 + return atomic64_add_ret_unchecked(i, v);
6252 +}
6253
6254 /*
6255 * atomic_inc_and_test - increment and test
6256 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
6257 * other cases.
6258 */
6259 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
6260 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6261 +{
6262 + return atomic_inc_return_unchecked(v) == 0;
6263 +}
6264 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6265
6266 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
6267 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
6268 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
6269
6270 #define atomic_inc(v) atomic_add(1, v)
6271 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
6272 +{
6273 + atomic_add_unchecked(1, v);
6274 +}
6275 #define atomic64_inc(v) atomic64_add(1, v)
6276 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
6277 +{
6278 + atomic64_add_unchecked(1, v);
6279 +}
6280
6281 #define atomic_dec(v) atomic_sub(1, v)
6282 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
6283 +{
6284 + atomic_sub_unchecked(1, v);
6285 +}
6286 #define atomic64_dec(v) atomic64_sub(1, v)
6287 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
6288 +{
6289 + atomic64_sub_unchecked(1, v);
6290 +}
6291
6292 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
6293 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
6294
6295 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
6296 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
6297 +{
6298 + return cmpxchg(&v->counter, old, new);
6299 +}
6300 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
6301 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
6302 +{
6303 + return xchg(&v->counter, new);
6304 +}
6305
6306 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
6307 {
6308 - int c, old;
6309 + int c, old, new;
6310 c = atomic_read(v);
6311 for (;;) {
6312 - if (unlikely(c == (u)))
6313 + if (unlikely(c == u))
6314 break;
6315 - old = atomic_cmpxchg((v), c, c + (a));
6316 +
6317 + asm volatile("addcc %2, %0, %0\n"
6318 +
6319 +#ifdef CONFIG_PAX_REFCOUNT
6320 + "tvs %%icc, 6\n"
6321 +#endif
6322 +
6323 + : "=r" (new)
6324 + : "0" (c), "ir" (a)
6325 + : "cc");
6326 +
6327 + old = atomic_cmpxchg(v, c, new);
6328 if (likely(old == c))
6329 break;
6330 c = old;
6331 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
6332 #define atomic64_cmpxchg(v, o, n) \
6333 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6334 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
6335 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6336 +{
6337 + return xchg(&v->counter, new);
6338 +}
6339
6340 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
6341 {
6342 - long c, old;
6343 + long c, old, new;
6344 c = atomic64_read(v);
6345 for (;;) {
6346 - if (unlikely(c == (u)))
6347 + if (unlikely(c == u))
6348 break;
6349 - old = atomic64_cmpxchg((v), c, c + (a));
6350 +
6351 + asm volatile("addcc %2, %0, %0\n"
6352 +
6353 +#ifdef CONFIG_PAX_REFCOUNT
6354 + "tvs %%xcc, 6\n"
6355 +#endif
6356 +
6357 + : "=r" (new)
6358 + : "0" (c), "ir" (a)
6359 + : "cc");
6360 +
6361 + old = atomic64_cmpxchg(v, c, new);
6362 if (likely(old == c))
6363 break;
6364 c = old;
6365 }
6366 - return c != (u);
6367 + return c != u;
6368 }
6369
6370 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
6371 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
6372 index 5bb6991..5c2132e 100644
6373 --- a/arch/sparc/include/asm/cache.h
6374 +++ b/arch/sparc/include/asm/cache.h
6375 @@ -7,10 +7,12 @@
6376 #ifndef _SPARC_CACHE_H
6377 #define _SPARC_CACHE_H
6378
6379 +#include <linux/const.h>
6380 +
6381 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
6382
6383 #define L1_CACHE_SHIFT 5
6384 -#define L1_CACHE_BYTES 32
6385 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6386
6387 #ifdef CONFIG_SPARC32
6388 #define SMP_CACHE_BYTES_SHIFT 5
6389 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
6390 index ac74a2c..a9e58af 100644
6391 --- a/arch/sparc/include/asm/elf_32.h
6392 +++ b/arch/sparc/include/asm/elf_32.h
6393 @@ -114,6 +114,13 @@ typedef struct {
6394
6395 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
6396
6397 +#ifdef CONFIG_PAX_ASLR
6398 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
6399 +
6400 +#define PAX_DELTA_MMAP_LEN 16
6401 +#define PAX_DELTA_STACK_LEN 16
6402 +#endif
6403 +
6404 /* This yields a mask that user programs can use to figure out what
6405 instruction set this cpu supports. This can NOT be done in userspace
6406 on Sparc. */
6407 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
6408 index 370ca1e..d4f4a98 100644
6409 --- a/arch/sparc/include/asm/elf_64.h
6410 +++ b/arch/sparc/include/asm/elf_64.h
6411 @@ -189,6 +189,13 @@ typedef struct {
6412 #define ELF_ET_DYN_BASE 0x0000010000000000UL
6413 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
6414
6415 +#ifdef CONFIG_PAX_ASLR
6416 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
6417 +
6418 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
6419 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
6420 +#endif
6421 +
6422 extern unsigned long sparc64_elf_hwcap;
6423 #define ELF_HWCAP sparc64_elf_hwcap
6424
6425 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
6426 index 9b1c36d..209298b 100644
6427 --- a/arch/sparc/include/asm/pgalloc_32.h
6428 +++ b/arch/sparc/include/asm/pgalloc_32.h
6429 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
6430 }
6431
6432 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
6433 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
6434
6435 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
6436 unsigned long address)
6437 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
6438 index bcfe063..b333142 100644
6439 --- a/arch/sparc/include/asm/pgalloc_64.h
6440 +++ b/arch/sparc/include/asm/pgalloc_64.h
6441 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6442 }
6443
6444 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
6445 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
6446
6447 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
6448 {
6449 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
6450 index 6fc1348..390c50a 100644
6451 --- a/arch/sparc/include/asm/pgtable_32.h
6452 +++ b/arch/sparc/include/asm/pgtable_32.h
6453 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
6454 #define PAGE_SHARED SRMMU_PAGE_SHARED
6455 #define PAGE_COPY SRMMU_PAGE_COPY
6456 #define PAGE_READONLY SRMMU_PAGE_RDONLY
6457 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
6458 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
6459 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
6460 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
6461
6462 /* Top-level page directory - dummy used by init-mm.
6463 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
6464
6465 /* xwr */
6466 #define __P000 PAGE_NONE
6467 -#define __P001 PAGE_READONLY
6468 -#define __P010 PAGE_COPY
6469 -#define __P011 PAGE_COPY
6470 +#define __P001 PAGE_READONLY_NOEXEC
6471 +#define __P010 PAGE_COPY_NOEXEC
6472 +#define __P011 PAGE_COPY_NOEXEC
6473 #define __P100 PAGE_READONLY
6474 #define __P101 PAGE_READONLY
6475 #define __P110 PAGE_COPY
6476 #define __P111 PAGE_COPY
6477
6478 #define __S000 PAGE_NONE
6479 -#define __S001 PAGE_READONLY
6480 -#define __S010 PAGE_SHARED
6481 -#define __S011 PAGE_SHARED
6482 +#define __S001 PAGE_READONLY_NOEXEC
6483 +#define __S010 PAGE_SHARED_NOEXEC
6484 +#define __S011 PAGE_SHARED_NOEXEC
6485 #define __S100 PAGE_READONLY
6486 #define __S101 PAGE_READONLY
6487 #define __S110 PAGE_SHARED
6488 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
6489 index 79da178..c2eede8 100644
6490 --- a/arch/sparc/include/asm/pgtsrmmu.h
6491 +++ b/arch/sparc/include/asm/pgtsrmmu.h
6492 @@ -115,6 +115,11 @@
6493 SRMMU_EXEC | SRMMU_REF)
6494 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
6495 SRMMU_EXEC | SRMMU_REF)
6496 +
6497 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
6498 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
6499 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
6500 +
6501 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
6502 SRMMU_DIRTY | SRMMU_REF)
6503
6504 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
6505 index 9689176..63c18ea 100644
6506 --- a/arch/sparc/include/asm/spinlock_64.h
6507 +++ b/arch/sparc/include/asm/spinlock_64.h
6508 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
6509
6510 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
6511
6512 -static void inline arch_read_lock(arch_rwlock_t *lock)
6513 +static inline void arch_read_lock(arch_rwlock_t *lock)
6514 {
6515 unsigned long tmp1, tmp2;
6516
6517 __asm__ __volatile__ (
6518 "1: ldsw [%2], %0\n"
6519 " brlz,pn %0, 2f\n"
6520 -"4: add %0, 1, %1\n"
6521 +"4: addcc %0, 1, %1\n"
6522 +
6523 +#ifdef CONFIG_PAX_REFCOUNT
6524 +" tvs %%icc, 6\n"
6525 +#endif
6526 +
6527 " cas [%2], %0, %1\n"
6528 " cmp %0, %1\n"
6529 " bne,pn %%icc, 1b\n"
6530 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
6531 " .previous"
6532 : "=&r" (tmp1), "=&r" (tmp2)
6533 : "r" (lock)
6534 - : "memory");
6535 + : "memory", "cc");
6536 }
6537
6538 -static int inline arch_read_trylock(arch_rwlock_t *lock)
6539 +static inline int arch_read_trylock(arch_rwlock_t *lock)
6540 {
6541 int tmp1, tmp2;
6542
6543 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
6544 "1: ldsw [%2], %0\n"
6545 " brlz,a,pn %0, 2f\n"
6546 " mov 0, %0\n"
6547 -" add %0, 1, %1\n"
6548 +" addcc %0, 1, %1\n"
6549 +
6550 +#ifdef CONFIG_PAX_REFCOUNT
6551 +" tvs %%icc, 6\n"
6552 +#endif
6553 +
6554 " cas [%2], %0, %1\n"
6555 " cmp %0, %1\n"
6556 " bne,pn %%icc, 1b\n"
6557 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
6558 return tmp1;
6559 }
6560
6561 -static void inline arch_read_unlock(arch_rwlock_t *lock)
6562 +static inline void arch_read_unlock(arch_rwlock_t *lock)
6563 {
6564 unsigned long tmp1, tmp2;
6565
6566 __asm__ __volatile__(
6567 "1: lduw [%2], %0\n"
6568 -" sub %0, 1, %1\n"
6569 +" subcc %0, 1, %1\n"
6570 +
6571 +#ifdef CONFIG_PAX_REFCOUNT
6572 +" tvs %%icc, 6\n"
6573 +#endif
6574 +
6575 " cas [%2], %0, %1\n"
6576 " cmp %0, %1\n"
6577 " bne,pn %%xcc, 1b\n"
6578 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
6579 : "memory");
6580 }
6581
6582 -static void inline arch_write_lock(arch_rwlock_t *lock)
6583 +static inline void arch_write_lock(arch_rwlock_t *lock)
6584 {
6585 unsigned long mask, tmp1, tmp2;
6586
6587 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
6588 : "memory");
6589 }
6590
6591 -static void inline arch_write_unlock(arch_rwlock_t *lock)
6592 +static inline void arch_write_unlock(arch_rwlock_t *lock)
6593 {
6594 __asm__ __volatile__(
6595 " stw %%g0, [%0]"
6596 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
6597 : "memory");
6598 }
6599
6600 -static int inline arch_write_trylock(arch_rwlock_t *lock)
6601 +static inline int arch_write_trylock(arch_rwlock_t *lock)
6602 {
6603 unsigned long mask, tmp1, tmp2, result;
6604
6605 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
6606 index 25849ae..924c54b 100644
6607 --- a/arch/sparc/include/asm/thread_info_32.h
6608 +++ b/arch/sparc/include/asm/thread_info_32.h
6609 @@ -49,6 +49,8 @@ struct thread_info {
6610 unsigned long w_saved;
6611
6612 struct restart_block restart_block;
6613 +
6614 + unsigned long lowest_stack;
6615 };
6616
6617 /*
6618 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
6619 index a3fe4dc..cae132a 100644
6620 --- a/arch/sparc/include/asm/thread_info_64.h
6621 +++ b/arch/sparc/include/asm/thread_info_64.h
6622 @@ -63,6 +63,8 @@ struct thread_info {
6623 struct pt_regs *kern_una_regs;
6624 unsigned int kern_una_insn;
6625
6626 + unsigned long lowest_stack;
6627 +
6628 unsigned long fpregs[0] __attribute__ ((aligned(64)));
6629 };
6630
6631 @@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
6632 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
6633 /* flag bit 6 is available */
6634 #define TIF_32BIT 7 /* 32-bit binary */
6635 -/* flag bit 8 is available */
6636 +#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
6637 #define TIF_SECCOMP 9 /* secure computing */
6638 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
6639 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
6640 +
6641 /* NOTE: Thread flags >= 12 should be ones we have no interest
6642 * in using in assembly, else we can't use the mask as
6643 * an immediate value in instructions such as andcc.
6644 @@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
6645 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
6646 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6647 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
6648 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6649
6650 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
6651 _TIF_DO_NOTIFY_RESUME_MASK | \
6652 _TIF_NEED_RESCHED)
6653 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
6654
6655 +#define _TIF_WORK_SYSCALL \
6656 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
6657 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6658 +
6659 +
6660 /*
6661 * Thread-synchronous status.
6662 *
6663 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
6664 index 0167d26..9acd8ed 100644
6665 --- a/arch/sparc/include/asm/uaccess.h
6666 +++ b/arch/sparc/include/asm/uaccess.h
6667 @@ -1,5 +1,13 @@
6668 #ifndef ___ASM_SPARC_UACCESS_H
6669 #define ___ASM_SPARC_UACCESS_H
6670 +
6671 +#ifdef __KERNEL__
6672 +#ifndef __ASSEMBLY__
6673 +#include <linux/types.h>
6674 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
6675 +#endif
6676 +#endif
6677 +
6678 #if defined(__sparc__) && defined(__arch64__)
6679 #include <asm/uaccess_64.h>
6680 #else
6681 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
6682 index 53a28dd..50c38c3 100644
6683 --- a/arch/sparc/include/asm/uaccess_32.h
6684 +++ b/arch/sparc/include/asm/uaccess_32.h
6685 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
6686
6687 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
6688 {
6689 - if (n && __access_ok((unsigned long) to, n))
6690 + if ((long)n < 0)
6691 + return n;
6692 +
6693 + if (n && __access_ok((unsigned long) to, n)) {
6694 + if (!__builtin_constant_p(n))
6695 + check_object_size(from, n, true);
6696 return __copy_user(to, (__force void __user *) from, n);
6697 - else
6698 + } else
6699 return n;
6700 }
6701
6702 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
6703 {
6704 + if ((long)n < 0)
6705 + return n;
6706 +
6707 + if (!__builtin_constant_p(n))
6708 + check_object_size(from, n, true);
6709 +
6710 return __copy_user(to, (__force void __user *) from, n);
6711 }
6712
6713 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
6714 {
6715 - if (n && __access_ok((unsigned long) from, n))
6716 + if ((long)n < 0)
6717 + return n;
6718 +
6719 + if (n && __access_ok((unsigned long) from, n)) {
6720 + if (!__builtin_constant_p(n))
6721 + check_object_size(to, n, false);
6722 return __copy_user((__force void __user *) to, from, n);
6723 - else
6724 + } else
6725 return n;
6726 }
6727
6728 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
6729 {
6730 + if ((long)n < 0)
6731 + return n;
6732 +
6733 return __copy_user((__force void __user *) to, from, n);
6734 }
6735
6736 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
6737 index 73083e1..2bc62a6 100644
6738 --- a/arch/sparc/include/asm/uaccess_64.h
6739 +++ b/arch/sparc/include/asm/uaccess_64.h
6740 @@ -10,6 +10,7 @@
6741 #include <linux/compiler.h>
6742 #include <linux/string.h>
6743 #include <linux/thread_info.h>
6744 +#include <linux/kernel.h>
6745 #include <asm/asi.h>
6746 #include <asm/spitfire.h>
6747 #include <asm-generic/uaccess-unaligned.h>
6748 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
6749 static inline unsigned long __must_check
6750 copy_from_user(void *to, const void __user *from, unsigned long size)
6751 {
6752 - unsigned long ret = ___copy_from_user(to, from, size);
6753 + unsigned long ret;
6754
6755 + if ((long)size < 0 || size > INT_MAX)
6756 + return size;
6757 +
6758 + if (!__builtin_constant_p(size))
6759 + check_object_size(to, size, false);
6760 +
6761 + ret = ___copy_from_user(to, from, size);
6762 if (unlikely(ret))
6763 ret = copy_from_user_fixup(to, from, size);
6764
6765 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
6766 static inline unsigned long __must_check
6767 copy_to_user(void __user *to, const void *from, unsigned long size)
6768 {
6769 - unsigned long ret = ___copy_to_user(to, from, size);
6770 + unsigned long ret;
6771
6772 + if ((long)size < 0 || size > INT_MAX)
6773 + return size;
6774 +
6775 + if (!__builtin_constant_p(size))
6776 + check_object_size(from, size, true);
6777 +
6778 + ret = ___copy_to_user(to, from, size);
6779 if (unlikely(ret))
6780 ret = copy_to_user_fixup(to, from, size);
6781 return ret;
6782 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
6783 index 6cf591b..b49e65a 100644
6784 --- a/arch/sparc/kernel/Makefile
6785 +++ b/arch/sparc/kernel/Makefile
6786 @@ -3,7 +3,7 @@
6787 #
6788
6789 asflags-y := -ansi
6790 -ccflags-y := -Werror
6791 +#ccflags-y := -Werror
6792
6793 extra-y := head_$(BITS).o
6794
6795 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
6796 index 487bffb..955a925 100644
6797 --- a/arch/sparc/kernel/process_32.c
6798 +++ b/arch/sparc/kernel/process_32.c
6799 @@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
6800
6801 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
6802 r->psr, r->pc, r->npc, r->y, print_tainted());
6803 - printk("PC: <%pS>\n", (void *) r->pc);
6804 + printk("PC: <%pA>\n", (void *) r->pc);
6805 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
6806 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
6807 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
6808 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
6809 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
6810 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
6811 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
6812 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
6813
6814 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
6815 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
6816 @@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6817 rw = (struct reg_window32 *) fp;
6818 pc = rw->ins[7];
6819 printk("[%08lx : ", pc);
6820 - printk("%pS ] ", (void *) pc);
6821 + printk("%pA ] ", (void *) pc);
6822 fp = rw->ins[6];
6823 } while (++count < 16);
6824 printk("\n");
6825 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
6826 index c6e0c29..052832b 100644
6827 --- a/arch/sparc/kernel/process_64.c
6828 +++ b/arch/sparc/kernel/process_64.c
6829 @@ -181,14 +181,14 @@ static void show_regwindow(struct pt_regs *regs)
6830 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
6831 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
6832 if (regs->tstate & TSTATE_PRIV)
6833 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
6834 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
6835 }
6836
6837 void show_regs(struct pt_regs *regs)
6838 {
6839 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
6840 regs->tpc, regs->tnpc, regs->y, print_tainted());
6841 - printk("TPC: <%pS>\n", (void *) regs->tpc);
6842 + printk("TPC: <%pA>\n", (void *) regs->tpc);
6843 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
6844 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
6845 regs->u_regs[3]);
6846 @@ -201,7 +201,7 @@ void show_regs(struct pt_regs *regs)
6847 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
6848 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
6849 regs->u_regs[15]);
6850 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
6851 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
6852 show_regwindow(regs);
6853 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
6854 }
6855 @@ -290,7 +290,7 @@ void arch_trigger_all_cpu_backtrace(void)
6856 ((tp && tp->task) ? tp->task->pid : -1));
6857
6858 if (gp->tstate & TSTATE_PRIV) {
6859 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
6860 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
6861 (void *) gp->tpc,
6862 (void *) gp->o7,
6863 (void *) gp->i7,
6864 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
6865 index 7ff45e4..a58f271 100644
6866 --- a/arch/sparc/kernel/ptrace_64.c
6867 +++ b/arch/sparc/kernel/ptrace_64.c
6868 @@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
6869 return ret;
6870 }
6871
6872 +#ifdef CONFIG_GRKERNSEC_SETXID
6873 +extern void gr_delayed_cred_worker(void);
6874 +#endif
6875 +
6876 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
6877 {
6878 int ret = 0;
6879 @@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
6880 /* do the secure computing check first */
6881 secure_computing_strict(regs->u_regs[UREG_G1]);
6882
6883 +#ifdef CONFIG_GRKERNSEC_SETXID
6884 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6885 + gr_delayed_cred_worker();
6886 +#endif
6887 +
6888 if (test_thread_flag(TIF_SYSCALL_TRACE))
6889 ret = tracehook_report_syscall_entry(regs);
6890
6891 @@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
6892
6893 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
6894 {
6895 +#ifdef CONFIG_GRKERNSEC_SETXID
6896 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6897 + gr_delayed_cred_worker();
6898 +#endif
6899 +
6900 audit_syscall_exit(regs);
6901
6902 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6903 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
6904 index 0c9b31b..55a8ba6 100644
6905 --- a/arch/sparc/kernel/sys_sparc_32.c
6906 +++ b/arch/sparc/kernel/sys_sparc_32.c
6907 @@ -39,6 +39,7 @@ asmlinkage unsigned long sys_getpagesize(void)
6908 unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
6909 {
6910 struct vm_area_struct * vmm;
6911 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
6912
6913 if (flags & MAP_FIXED) {
6914 /* We do not accept a shared mapping if it would violate
6915 @@ -54,7 +55,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6916 if (len > TASK_SIZE - PAGE_SIZE)
6917 return -ENOMEM;
6918 if (!addr)
6919 - addr = TASK_UNMAPPED_BASE;
6920 + addr = current->mm->mmap_base;
6921
6922 if (flags & MAP_SHARED)
6923 addr = COLOUR_ALIGN(addr);
6924 @@ -65,7 +66,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6925 /* At this point: (!vmm || addr < vmm->vm_end). */
6926 if (TASK_SIZE - PAGE_SIZE - len < addr)
6927 return -ENOMEM;
6928 - if (!vmm || addr + len <= vmm->vm_start)
6929 + if (check_heap_stack_gap(vmm, addr, len, offset))
6930 return addr;
6931 addr = vmm->vm_end;
6932 if (flags & MAP_SHARED)
6933 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
6934 index 878ef3d..f100719 100644
6935 --- a/arch/sparc/kernel/sys_sparc_64.c
6936 +++ b/arch/sparc/kernel/sys_sparc_64.c
6937 @@ -102,12 +102,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6938 unsigned long task_size = TASK_SIZE;
6939 unsigned long start_addr;
6940 int do_color_align;
6941 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6942
6943 if (flags & MAP_FIXED) {
6944 /* We do not accept a shared mapping if it would violate
6945 * cache aliasing constraints.
6946 */
6947 - if ((flags & MAP_SHARED) &&
6948 + if ((filp || (flags & MAP_SHARED)) &&
6949 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
6950 return -EINVAL;
6951 return addr;
6952 @@ -122,6 +123,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6953 if (filp || (flags & MAP_SHARED))
6954 do_color_align = 1;
6955
6956 +#ifdef CONFIG_PAX_RANDMMAP
6957 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6958 +#endif
6959 +
6960 if (addr) {
6961 if (do_color_align)
6962 addr = COLOUR_ALIGN(addr, pgoff);
6963 @@ -129,15 +134,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6964 addr = PAGE_ALIGN(addr);
6965
6966 vma = find_vma(mm, addr);
6967 - if (task_size - len >= addr &&
6968 - (!vma || addr + len <= vma->vm_start))
6969 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6970 return addr;
6971 }
6972
6973 if (len > mm->cached_hole_size) {
6974 - start_addr = addr = mm->free_area_cache;
6975 + start_addr = addr = mm->free_area_cache;
6976 } else {
6977 - start_addr = addr = TASK_UNMAPPED_BASE;
6978 + start_addr = addr = mm->mmap_base;
6979 mm->cached_hole_size = 0;
6980 }
6981
6982 @@ -157,14 +161,14 @@ full_search:
6983 vma = find_vma(mm, VA_EXCLUDE_END);
6984 }
6985 if (unlikely(task_size < addr)) {
6986 - if (start_addr != TASK_UNMAPPED_BASE) {
6987 - start_addr = addr = TASK_UNMAPPED_BASE;
6988 + if (start_addr != mm->mmap_base) {
6989 + start_addr = addr = mm->mmap_base;
6990 mm->cached_hole_size = 0;
6991 goto full_search;
6992 }
6993 return -ENOMEM;
6994 }
6995 - if (likely(!vma || addr + len <= vma->vm_start)) {
6996 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
6997 /*
6998 * Remember the place where we stopped the search:
6999 */
7000 @@ -190,6 +194,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7001 unsigned long task_size = STACK_TOP32;
7002 unsigned long addr = addr0;
7003 int do_color_align;
7004 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7005
7006 /* This should only ever run for 32-bit processes. */
7007 BUG_ON(!test_thread_flag(TIF_32BIT));
7008 @@ -198,7 +203,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7009 /* We do not accept a shared mapping if it would violate
7010 * cache aliasing constraints.
7011 */
7012 - if ((flags & MAP_SHARED) &&
7013 + if ((filp || (flags & MAP_SHARED)) &&
7014 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
7015 return -EINVAL;
7016 return addr;
7017 @@ -219,8 +224,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7018 addr = PAGE_ALIGN(addr);
7019
7020 vma = find_vma(mm, addr);
7021 - if (task_size - len >= addr &&
7022 - (!vma || addr + len <= vma->vm_start))
7023 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7024 return addr;
7025 }
7026
7027 @@ -241,7 +245,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7028 /* make sure it can fit in the remaining address space */
7029 if (likely(addr > len)) {
7030 vma = find_vma(mm, addr-len);
7031 - if (!vma || addr <= vma->vm_start) {
7032 + if (check_heap_stack_gap(vma, addr - len, len, offset)) {
7033 /* remember the address as a hint for next time */
7034 return (mm->free_area_cache = addr-len);
7035 }
7036 @@ -250,18 +254,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7037 if (unlikely(mm->mmap_base < len))
7038 goto bottomup;
7039
7040 - addr = mm->mmap_base-len;
7041 - if (do_color_align)
7042 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
7043 + addr = mm->mmap_base - len;
7044
7045 do {
7046 + if (do_color_align)
7047 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
7048 /*
7049 * Lookup failure means no vma is above this address,
7050 * else if new region fits below vma->vm_start,
7051 * return with success:
7052 */
7053 vma = find_vma(mm, addr);
7054 - if (likely(!vma || addr+len <= vma->vm_start)) {
7055 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
7056 /* remember the address as a hint for next time */
7057 return (mm->free_area_cache = addr);
7058 }
7059 @@ -271,10 +275,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7060 mm->cached_hole_size = vma->vm_start - addr;
7061
7062 /* try just below the current vma->vm_start */
7063 - addr = vma->vm_start-len;
7064 - if (do_color_align)
7065 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
7066 - } while (likely(len < vma->vm_start));
7067 + addr = skip_heap_stack_gap(vma, len, offset);
7068 + } while (!IS_ERR_VALUE(addr));
7069
7070 bottomup:
7071 /*
7072 @@ -348,6 +350,10 @@ static unsigned long mmap_rnd(void)
7073 {
7074 unsigned long rnd = 0UL;
7075
7076 +#ifdef CONFIG_PAX_RANDMMAP
7077 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7078 +#endif
7079 +
7080 if (current->flags & PF_RANDOMIZE) {
7081 unsigned long val = get_random_int();
7082 if (test_thread_flag(TIF_32BIT))
7083 @@ -373,6 +379,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7084 gap == RLIM_INFINITY ||
7085 sysctl_legacy_va_layout) {
7086 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7087 +
7088 +#ifdef CONFIG_PAX_RANDMMAP
7089 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7090 + mm->mmap_base += mm->delta_mmap;
7091 +#endif
7092 +
7093 mm->get_unmapped_area = arch_get_unmapped_area;
7094 mm->unmap_area = arch_unmap_area;
7095 } else {
7096 @@ -385,6 +397,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7097 gap = (task_size / 6 * 5);
7098
7099 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
7100 +
7101 +#ifdef CONFIG_PAX_RANDMMAP
7102 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7103 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7104 +#endif
7105 +
7106 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7107 mm->unmap_area = arch_unmap_area_topdown;
7108 }
7109 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
7110 index bf23477..b7425a6 100644
7111 --- a/arch/sparc/kernel/syscalls.S
7112 +++ b/arch/sparc/kernel/syscalls.S
7113 @@ -62,7 +62,7 @@ sys32_rt_sigreturn:
7114 #endif
7115 .align 32
7116 1: ldx [%g6 + TI_FLAGS], %l5
7117 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7118 + andcc %l5, _TIF_WORK_SYSCALL, %g0
7119 be,pt %icc, rtrap
7120 nop
7121 call syscall_trace_leave
7122 @@ -189,7 +189,7 @@ linux_sparc_syscall32:
7123
7124 srl %i5, 0, %o5 ! IEU1
7125 srl %i2, 0, %o2 ! IEU0 Group
7126 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7127 + andcc %l0, _TIF_WORK_SYSCALL, %g0
7128 bne,pn %icc, linux_syscall_trace32 ! CTI
7129 mov %i0, %l5 ! IEU1
7130 call %l7 ! CTI Group brk forced
7131 @@ -212,7 +212,7 @@ linux_sparc_syscall:
7132
7133 mov %i3, %o3 ! IEU1
7134 mov %i4, %o4 ! IEU0 Group
7135 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7136 + andcc %l0, _TIF_WORK_SYSCALL, %g0
7137 bne,pn %icc, linux_syscall_trace ! CTI Group
7138 mov %i0, %l5 ! IEU0
7139 2: call %l7 ! CTI Group brk forced
7140 @@ -228,7 +228,7 @@ ret_sys_call:
7141
7142 cmp %o0, -ERESTART_RESTARTBLOCK
7143 bgeu,pn %xcc, 1f
7144 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7145 + andcc %l0, _TIF_WORK_SYSCALL, %g0
7146 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
7147
7148 2:
7149 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
7150 index a5785ea..405c5f7 100644
7151 --- a/arch/sparc/kernel/traps_32.c
7152 +++ b/arch/sparc/kernel/traps_32.c
7153 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
7154 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
7155 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
7156
7157 +extern void gr_handle_kernel_exploit(void);
7158 +
7159 void die_if_kernel(char *str, struct pt_regs *regs)
7160 {
7161 static int die_counter;
7162 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
7163 count++ < 30 &&
7164 (((unsigned long) rw) >= PAGE_OFFSET) &&
7165 !(((unsigned long) rw) & 0x7)) {
7166 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
7167 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
7168 (void *) rw->ins[7]);
7169 rw = (struct reg_window32 *)rw->ins[6];
7170 }
7171 }
7172 printk("Instruction DUMP:");
7173 instruction_dump ((unsigned long *) regs->pc);
7174 - if(regs->psr & PSR_PS)
7175 + if(regs->psr & PSR_PS) {
7176 + gr_handle_kernel_exploit();
7177 do_exit(SIGKILL);
7178 + }
7179 do_exit(SIGSEGV);
7180 }
7181
7182 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
7183 index b66a779..8e8d66c 100644
7184 --- a/arch/sparc/kernel/traps_64.c
7185 +++ b/arch/sparc/kernel/traps_64.c
7186 @@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
7187 i + 1,
7188 p->trapstack[i].tstate, p->trapstack[i].tpc,
7189 p->trapstack[i].tnpc, p->trapstack[i].tt);
7190 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
7191 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
7192 }
7193 }
7194
7195 @@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
7196
7197 lvl -= 0x100;
7198 if (regs->tstate & TSTATE_PRIV) {
7199 +
7200 +#ifdef CONFIG_PAX_REFCOUNT
7201 + if (lvl == 6)
7202 + pax_report_refcount_overflow(regs);
7203 +#endif
7204 +
7205 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
7206 die_if_kernel(buffer, regs);
7207 }
7208 @@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
7209 void bad_trap_tl1(struct pt_regs *regs, long lvl)
7210 {
7211 char buffer[32];
7212 -
7213 +
7214 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
7215 0, lvl, SIGTRAP) == NOTIFY_STOP)
7216 return;
7217
7218 +#ifdef CONFIG_PAX_REFCOUNT
7219 + if (lvl == 6)
7220 + pax_report_refcount_overflow(regs);
7221 +#endif
7222 +
7223 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
7224
7225 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
7226 @@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
7227 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
7228 printk("%s" "ERROR(%d): ",
7229 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
7230 - printk("TPC<%pS>\n", (void *) regs->tpc);
7231 + printk("TPC<%pA>\n", (void *) regs->tpc);
7232 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
7233 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
7234 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
7235 @@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
7236 smp_processor_id(),
7237 (type & 0x1) ? 'I' : 'D',
7238 regs->tpc);
7239 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
7240 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
7241 panic("Irrecoverable Cheetah+ parity error.");
7242 }
7243
7244 @@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
7245 smp_processor_id(),
7246 (type & 0x1) ? 'I' : 'D',
7247 regs->tpc);
7248 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
7249 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
7250 }
7251
7252 struct sun4v_error_entry {
7253 @@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
7254
7255 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
7256 regs->tpc, tl);
7257 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
7258 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
7259 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
7260 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
7261 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
7262 (void *) regs->u_regs[UREG_I7]);
7263 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
7264 "pte[%lx] error[%lx]\n",
7265 @@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
7266
7267 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
7268 regs->tpc, tl);
7269 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
7270 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
7271 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
7272 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
7273 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
7274 (void *) regs->u_regs[UREG_I7]);
7275 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
7276 "pte[%lx] error[%lx]\n",
7277 @@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
7278 fp = (unsigned long)sf->fp + STACK_BIAS;
7279 }
7280
7281 - printk(" [%016lx] %pS\n", pc, (void *) pc);
7282 + printk(" [%016lx] %pA\n", pc, (void *) pc);
7283 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
7284 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
7285 int index = tsk->curr_ret_stack;
7286 if (tsk->ret_stack && index >= graph) {
7287 pc = tsk->ret_stack[index - graph].ret;
7288 - printk(" [%016lx] %pS\n", pc, (void *) pc);
7289 + printk(" [%016lx] %pA\n", pc, (void *) pc);
7290 graph++;
7291 }
7292 }
7293 @@ -2367,6 +2378,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
7294 return (struct reg_window *) (fp + STACK_BIAS);
7295 }
7296
7297 +extern void gr_handle_kernel_exploit(void);
7298 +
7299 void die_if_kernel(char *str, struct pt_regs *regs)
7300 {
7301 static int die_counter;
7302 @@ -2395,7 +2408,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
7303 while (rw &&
7304 count++ < 30 &&
7305 kstack_valid(tp, (unsigned long) rw)) {
7306 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
7307 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
7308 (void *) rw->ins[7]);
7309
7310 rw = kernel_stack_up(rw);
7311 @@ -2408,8 +2421,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
7312 }
7313 user_instruction_dump ((unsigned int __user *) regs->tpc);
7314 }
7315 - if (regs->tstate & TSTATE_PRIV)
7316 + if (regs->tstate & TSTATE_PRIV) {
7317 + gr_handle_kernel_exploit();
7318 do_exit(SIGKILL);
7319 + }
7320 do_exit(SIGSEGV);
7321 }
7322 EXPORT_SYMBOL(die_if_kernel);
7323 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
7324 index 8201c25e..072a2a7 100644
7325 --- a/arch/sparc/kernel/unaligned_64.c
7326 +++ b/arch/sparc/kernel/unaligned_64.c
7327 @@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
7328 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
7329
7330 if (__ratelimit(&ratelimit)) {
7331 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
7332 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
7333 regs->tpc, (void *) regs->tpc);
7334 }
7335 }
7336 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
7337 index 8410065f2..4fd4ca22 100644
7338 --- a/arch/sparc/lib/Makefile
7339 +++ b/arch/sparc/lib/Makefile
7340 @@ -2,7 +2,7 @@
7341 #
7342
7343 asflags-y := -ansi -DST_DIV0=0x02
7344 -ccflags-y := -Werror
7345 +#ccflags-y := -Werror
7346
7347 lib-$(CONFIG_SPARC32) += ashrdi3.o
7348 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
7349 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
7350 index 85c233d..68500e0 100644
7351 --- a/arch/sparc/lib/atomic_64.S
7352 +++ b/arch/sparc/lib/atomic_64.S
7353 @@ -17,7 +17,12 @@
7354 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
7355 BACKOFF_SETUP(%o2)
7356 1: lduw [%o1], %g1
7357 - add %g1, %o0, %g7
7358 + addcc %g1, %o0, %g7
7359 +
7360 +#ifdef CONFIG_PAX_REFCOUNT
7361 + tvs %icc, 6
7362 +#endif
7363 +
7364 cas [%o1], %g1, %g7
7365 cmp %g1, %g7
7366 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7367 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
7368 2: BACKOFF_SPIN(%o2, %o3, 1b)
7369 ENDPROC(atomic_add)
7370
7371 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7372 + BACKOFF_SETUP(%o2)
7373 +1: lduw [%o1], %g1
7374 + add %g1, %o0, %g7
7375 + cas [%o1], %g1, %g7
7376 + cmp %g1, %g7
7377 + bne,pn %icc, 2f
7378 + nop
7379 + retl
7380 + nop
7381 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7382 +ENDPROC(atomic_add_unchecked)
7383 +
7384 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7385 BACKOFF_SETUP(%o2)
7386 1: lduw [%o1], %g1
7387 - sub %g1, %o0, %g7
7388 + subcc %g1, %o0, %g7
7389 +
7390 +#ifdef CONFIG_PAX_REFCOUNT
7391 + tvs %icc, 6
7392 +#endif
7393 +
7394 cas [%o1], %g1, %g7
7395 cmp %g1, %g7
7396 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7397 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7398 2: BACKOFF_SPIN(%o2, %o3, 1b)
7399 ENDPROC(atomic_sub)
7400
7401 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
7402 + BACKOFF_SETUP(%o2)
7403 +1: lduw [%o1], %g1
7404 + sub %g1, %o0, %g7
7405 + cas [%o1], %g1, %g7
7406 + cmp %g1, %g7
7407 + bne,pn %icc, 2f
7408 + nop
7409 + retl
7410 + nop
7411 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7412 +ENDPROC(atomic_sub_unchecked)
7413 +
7414 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7415 BACKOFF_SETUP(%o2)
7416 1: lduw [%o1], %g1
7417 - add %g1, %o0, %g7
7418 + addcc %g1, %o0, %g7
7419 +
7420 +#ifdef CONFIG_PAX_REFCOUNT
7421 + tvs %icc, 6
7422 +#endif
7423 +
7424 cas [%o1], %g1, %g7
7425 cmp %g1, %g7
7426 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7427 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7428 2: BACKOFF_SPIN(%o2, %o3, 1b)
7429 ENDPROC(atomic_add_ret)
7430
7431 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7432 + BACKOFF_SETUP(%o2)
7433 +1: lduw [%o1], %g1
7434 + addcc %g1, %o0, %g7
7435 + cas [%o1], %g1, %g7
7436 + cmp %g1, %g7
7437 + bne,pn %icc, 2f
7438 + add %g7, %o0, %g7
7439 + sra %g7, 0, %o0
7440 + retl
7441 + nop
7442 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7443 +ENDPROC(atomic_add_ret_unchecked)
7444 +
7445 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
7446 BACKOFF_SETUP(%o2)
7447 1: lduw [%o1], %g1
7448 - sub %g1, %o0, %g7
7449 + subcc %g1, %o0, %g7
7450 +
7451 +#ifdef CONFIG_PAX_REFCOUNT
7452 + tvs %icc, 6
7453 +#endif
7454 +
7455 cas [%o1], %g1, %g7
7456 cmp %g1, %g7
7457 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7458 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
7459 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
7460 BACKOFF_SETUP(%o2)
7461 1: ldx [%o1], %g1
7462 - add %g1, %o0, %g7
7463 + addcc %g1, %o0, %g7
7464 +
7465 +#ifdef CONFIG_PAX_REFCOUNT
7466 + tvs %xcc, 6
7467 +#endif
7468 +
7469 casx [%o1], %g1, %g7
7470 cmp %g1, %g7
7471 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7472 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
7473 2: BACKOFF_SPIN(%o2, %o3, 1b)
7474 ENDPROC(atomic64_add)
7475
7476 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7477 + BACKOFF_SETUP(%o2)
7478 +1: ldx [%o1], %g1
7479 + addcc %g1, %o0, %g7
7480 + casx [%o1], %g1, %g7
7481 + cmp %g1, %g7
7482 + bne,pn %xcc, 2f
7483 + nop
7484 + retl
7485 + nop
7486 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7487 +ENDPROC(atomic64_add_unchecked)
7488 +
7489 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7490 BACKOFF_SETUP(%o2)
7491 1: ldx [%o1], %g1
7492 - sub %g1, %o0, %g7
7493 + subcc %g1, %o0, %g7
7494 +
7495 +#ifdef CONFIG_PAX_REFCOUNT
7496 + tvs %xcc, 6
7497 +#endif
7498 +
7499 casx [%o1], %g1, %g7
7500 cmp %g1, %g7
7501 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7502 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7503 2: BACKOFF_SPIN(%o2, %o3, 1b)
7504 ENDPROC(atomic64_sub)
7505
7506 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
7507 + BACKOFF_SETUP(%o2)
7508 +1: ldx [%o1], %g1
7509 + subcc %g1, %o0, %g7
7510 + casx [%o1], %g1, %g7
7511 + cmp %g1, %g7
7512 + bne,pn %xcc, 2f
7513 + nop
7514 + retl
7515 + nop
7516 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7517 +ENDPROC(atomic64_sub_unchecked)
7518 +
7519 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7520 BACKOFF_SETUP(%o2)
7521 1: ldx [%o1], %g1
7522 - add %g1, %o0, %g7
7523 + addcc %g1, %o0, %g7
7524 +
7525 +#ifdef CONFIG_PAX_REFCOUNT
7526 + tvs %xcc, 6
7527 +#endif
7528 +
7529 casx [%o1], %g1, %g7
7530 cmp %g1, %g7
7531 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7532 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7533 2: BACKOFF_SPIN(%o2, %o3, 1b)
7534 ENDPROC(atomic64_add_ret)
7535
7536 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7537 + BACKOFF_SETUP(%o2)
7538 +1: ldx [%o1], %g1
7539 + addcc %g1, %o0, %g7
7540 + casx [%o1], %g1, %g7
7541 + cmp %g1, %g7
7542 + bne,pn %xcc, 2f
7543 + add %g7, %o0, %g7
7544 + mov %g7, %o0
7545 + retl
7546 + nop
7547 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7548 +ENDPROC(atomic64_add_ret_unchecked)
7549 +
7550 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
7551 BACKOFF_SETUP(%o2)
7552 1: ldx [%o1], %g1
7553 - sub %g1, %o0, %g7
7554 + subcc %g1, %o0, %g7
7555 +
7556 +#ifdef CONFIG_PAX_REFCOUNT
7557 + tvs %xcc, 6
7558 +#endif
7559 +
7560 casx [%o1], %g1, %g7
7561 cmp %g1, %g7
7562 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7563 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
7564 index 0c4e35e..745d3e4 100644
7565 --- a/arch/sparc/lib/ksyms.c
7566 +++ b/arch/sparc/lib/ksyms.c
7567 @@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
7568
7569 /* Atomic counter implementation. */
7570 EXPORT_SYMBOL(atomic_add);
7571 +EXPORT_SYMBOL(atomic_add_unchecked);
7572 EXPORT_SYMBOL(atomic_add_ret);
7573 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
7574 EXPORT_SYMBOL(atomic_sub);
7575 +EXPORT_SYMBOL(atomic_sub_unchecked);
7576 EXPORT_SYMBOL(atomic_sub_ret);
7577 EXPORT_SYMBOL(atomic64_add);
7578 +EXPORT_SYMBOL(atomic64_add_unchecked);
7579 EXPORT_SYMBOL(atomic64_add_ret);
7580 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
7581 EXPORT_SYMBOL(atomic64_sub);
7582 +EXPORT_SYMBOL(atomic64_sub_unchecked);
7583 EXPORT_SYMBOL(atomic64_sub_ret);
7584 EXPORT_SYMBOL(atomic64_dec_if_positive);
7585
7586 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
7587 index 30c3ecc..736f015 100644
7588 --- a/arch/sparc/mm/Makefile
7589 +++ b/arch/sparc/mm/Makefile
7590 @@ -2,7 +2,7 @@
7591 #
7592
7593 asflags-y := -ansi
7594 -ccflags-y := -Werror
7595 +#ccflags-y := -Werror
7596
7597 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
7598 obj-y += fault_$(BITS).o
7599 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
7600 index e98bfda..ea8d221 100644
7601 --- a/arch/sparc/mm/fault_32.c
7602 +++ b/arch/sparc/mm/fault_32.c
7603 @@ -21,6 +21,9 @@
7604 #include <linux/perf_event.h>
7605 #include <linux/interrupt.h>
7606 #include <linux/kdebug.h>
7607 +#include <linux/slab.h>
7608 +#include <linux/pagemap.h>
7609 +#include <linux/compiler.h>
7610
7611 #include <asm/page.h>
7612 #include <asm/pgtable.h>
7613 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
7614 return safe_compute_effective_address(regs, insn);
7615 }
7616
7617 +#ifdef CONFIG_PAX_PAGEEXEC
7618 +#ifdef CONFIG_PAX_DLRESOLVE
7619 +static void pax_emuplt_close(struct vm_area_struct *vma)
7620 +{
7621 + vma->vm_mm->call_dl_resolve = 0UL;
7622 +}
7623 +
7624 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
7625 +{
7626 + unsigned int *kaddr;
7627 +
7628 + vmf->page = alloc_page(GFP_HIGHUSER);
7629 + if (!vmf->page)
7630 + return VM_FAULT_OOM;
7631 +
7632 + kaddr = kmap(vmf->page);
7633 + memset(kaddr, 0, PAGE_SIZE);
7634 + kaddr[0] = 0x9DE3BFA8U; /* save */
7635 + flush_dcache_page(vmf->page);
7636 + kunmap(vmf->page);
7637 + return VM_FAULT_MAJOR;
7638 +}
7639 +
7640 +static const struct vm_operations_struct pax_vm_ops = {
7641 + .close = pax_emuplt_close,
7642 + .fault = pax_emuplt_fault
7643 +};
7644 +
7645 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
7646 +{
7647 + int ret;
7648 +
7649 + INIT_LIST_HEAD(&vma->anon_vma_chain);
7650 + vma->vm_mm = current->mm;
7651 + vma->vm_start = addr;
7652 + vma->vm_end = addr + PAGE_SIZE;
7653 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
7654 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
7655 + vma->vm_ops = &pax_vm_ops;
7656 +
7657 + ret = insert_vm_struct(current->mm, vma);
7658 + if (ret)
7659 + return ret;
7660 +
7661 + ++current->mm->total_vm;
7662 + return 0;
7663 +}
7664 +#endif
7665 +
7666 +/*
7667 + * PaX: decide what to do with offenders (regs->pc = fault address)
7668 + *
7669 + * returns 1 when task should be killed
7670 + * 2 when patched PLT trampoline was detected
7671 + * 3 when unpatched PLT trampoline was detected
7672 + */
7673 +static int pax_handle_fetch_fault(struct pt_regs *regs)
7674 +{
7675 +
7676 +#ifdef CONFIG_PAX_EMUPLT
7677 + int err;
7678 +
7679 + do { /* PaX: patched PLT emulation #1 */
7680 + unsigned int sethi1, sethi2, jmpl;
7681 +
7682 + err = get_user(sethi1, (unsigned int *)regs->pc);
7683 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
7684 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
7685 +
7686 + if (err)
7687 + break;
7688 +
7689 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
7690 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
7691 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
7692 + {
7693 + unsigned int addr;
7694 +
7695 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
7696 + addr = regs->u_regs[UREG_G1];
7697 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
7698 + regs->pc = addr;
7699 + regs->npc = addr+4;
7700 + return 2;
7701 + }
7702 + } while (0);
7703 +
7704 + do { /* PaX: patched PLT emulation #2 */
7705 + unsigned int ba;
7706 +
7707 + err = get_user(ba, (unsigned int *)regs->pc);
7708 +
7709 + if (err)
7710 + break;
7711 +
7712 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
7713 + unsigned int addr;
7714 +
7715 + if ((ba & 0xFFC00000U) == 0x30800000U)
7716 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
7717 + else
7718 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
7719 + regs->pc = addr;
7720 + regs->npc = addr+4;
7721 + return 2;
7722 + }
7723 + } while (0);
7724 +
7725 + do { /* PaX: patched PLT emulation #3 */
7726 + unsigned int sethi, bajmpl, nop;
7727 +
7728 + err = get_user(sethi, (unsigned int *)regs->pc);
7729 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
7730 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
7731 +
7732 + if (err)
7733 + break;
7734 +
7735 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7736 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
7737 + nop == 0x01000000U)
7738 + {
7739 + unsigned int addr;
7740 +
7741 + addr = (sethi & 0x003FFFFFU) << 10;
7742 + regs->u_regs[UREG_G1] = addr;
7743 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
7744 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
7745 + else
7746 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
7747 + regs->pc = addr;
7748 + regs->npc = addr+4;
7749 + return 2;
7750 + }
7751 + } while (0);
7752 +
7753 + do { /* PaX: unpatched PLT emulation step 1 */
7754 + unsigned int sethi, ba, nop;
7755 +
7756 + err = get_user(sethi, (unsigned int *)regs->pc);
7757 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
7758 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
7759 +
7760 + if (err)
7761 + break;
7762 +
7763 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7764 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7765 + nop == 0x01000000U)
7766 + {
7767 + unsigned int addr, save, call;
7768 +
7769 + if ((ba & 0xFFC00000U) == 0x30800000U)
7770 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
7771 + else
7772 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
7773 +
7774 + err = get_user(save, (unsigned int *)addr);
7775 + err |= get_user(call, (unsigned int *)(addr+4));
7776 + err |= get_user(nop, (unsigned int *)(addr+8));
7777 + if (err)
7778 + break;
7779 +
7780 +#ifdef CONFIG_PAX_DLRESOLVE
7781 + if (save == 0x9DE3BFA8U &&
7782 + (call & 0xC0000000U) == 0x40000000U &&
7783 + nop == 0x01000000U)
7784 + {
7785 + struct vm_area_struct *vma;
7786 + unsigned long call_dl_resolve;
7787 +
7788 + down_read(&current->mm->mmap_sem);
7789 + call_dl_resolve = current->mm->call_dl_resolve;
7790 + up_read(&current->mm->mmap_sem);
7791 + if (likely(call_dl_resolve))
7792 + goto emulate;
7793 +
7794 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7795 +
7796 + down_write(&current->mm->mmap_sem);
7797 + if (current->mm->call_dl_resolve) {
7798 + call_dl_resolve = current->mm->call_dl_resolve;
7799 + up_write(&current->mm->mmap_sem);
7800 + if (vma)
7801 + kmem_cache_free(vm_area_cachep, vma);
7802 + goto emulate;
7803 + }
7804 +
7805 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7806 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7807 + up_write(&current->mm->mmap_sem);
7808 + if (vma)
7809 + kmem_cache_free(vm_area_cachep, vma);
7810 + return 1;
7811 + }
7812 +
7813 + if (pax_insert_vma(vma, call_dl_resolve)) {
7814 + up_write(&current->mm->mmap_sem);
7815 + kmem_cache_free(vm_area_cachep, vma);
7816 + return 1;
7817 + }
7818 +
7819 + current->mm->call_dl_resolve = call_dl_resolve;
7820 + up_write(&current->mm->mmap_sem);
7821 +
7822 +emulate:
7823 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7824 + regs->pc = call_dl_resolve;
7825 + regs->npc = addr+4;
7826 + return 3;
7827 + }
7828 +#endif
7829 +
7830 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7831 + if ((save & 0xFFC00000U) == 0x05000000U &&
7832 + (call & 0xFFFFE000U) == 0x85C0A000U &&
7833 + nop == 0x01000000U)
7834 + {
7835 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7836 + regs->u_regs[UREG_G2] = addr + 4;
7837 + addr = (save & 0x003FFFFFU) << 10;
7838 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
7839 + regs->pc = addr;
7840 + regs->npc = addr+4;
7841 + return 3;
7842 + }
7843 + }
7844 + } while (0);
7845 +
7846 + do { /* PaX: unpatched PLT emulation step 2 */
7847 + unsigned int save, call, nop;
7848 +
7849 + err = get_user(save, (unsigned int *)(regs->pc-4));
7850 + err |= get_user(call, (unsigned int *)regs->pc);
7851 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
7852 + if (err)
7853 + break;
7854 +
7855 + if (save == 0x9DE3BFA8U &&
7856 + (call & 0xC0000000U) == 0x40000000U &&
7857 + nop == 0x01000000U)
7858 + {
7859 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
7860 +
7861 + regs->u_regs[UREG_RETPC] = regs->pc;
7862 + regs->pc = dl_resolve;
7863 + regs->npc = dl_resolve+4;
7864 + return 3;
7865 + }
7866 + } while (0);
7867 +#endif
7868 +
7869 + return 1;
7870 +}
7871 +
7872 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7873 +{
7874 + unsigned long i;
7875 +
7876 + printk(KERN_ERR "PAX: bytes at PC: ");
7877 + for (i = 0; i < 8; i++) {
7878 + unsigned int c;
7879 + if (get_user(c, (unsigned int *)pc+i))
7880 + printk(KERN_CONT "???????? ");
7881 + else
7882 + printk(KERN_CONT "%08x ", c);
7883 + }
7884 + printk("\n");
7885 +}
7886 +#endif
7887 +
7888 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
7889 int text_fault)
7890 {
7891 @@ -230,6 +504,24 @@ good_area:
7892 if (!(vma->vm_flags & VM_WRITE))
7893 goto bad_area;
7894 } else {
7895 +
7896 +#ifdef CONFIG_PAX_PAGEEXEC
7897 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
7898 + up_read(&mm->mmap_sem);
7899 + switch (pax_handle_fetch_fault(regs)) {
7900 +
7901 +#ifdef CONFIG_PAX_EMUPLT
7902 + case 2:
7903 + case 3:
7904 + return;
7905 +#endif
7906 +
7907 + }
7908 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
7909 + do_group_exit(SIGKILL);
7910 + }
7911 +#endif
7912 +
7913 /* Allow reads even for write-only mappings */
7914 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
7915 goto bad_area;
7916 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
7917 index 097aee7..5ca6697 100644
7918 --- a/arch/sparc/mm/fault_64.c
7919 +++ b/arch/sparc/mm/fault_64.c
7920 @@ -21,6 +21,9 @@
7921 #include <linux/kprobes.h>
7922 #include <linux/kdebug.h>
7923 #include <linux/percpu.h>
7924 +#include <linux/slab.h>
7925 +#include <linux/pagemap.h>
7926 +#include <linux/compiler.h>
7927
7928 #include <asm/page.h>
7929 #include <asm/pgtable.h>
7930 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
7931 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
7932 regs->tpc);
7933 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
7934 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
7935 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
7936 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
7937 dump_stack();
7938 unhandled_fault(regs->tpc, current, regs);
7939 @@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
7940 show_regs(regs);
7941 }
7942
7943 +#ifdef CONFIG_PAX_PAGEEXEC
7944 +#ifdef CONFIG_PAX_DLRESOLVE
7945 +static void pax_emuplt_close(struct vm_area_struct *vma)
7946 +{
7947 + vma->vm_mm->call_dl_resolve = 0UL;
7948 +}
7949 +
7950 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
7951 +{
7952 + unsigned int *kaddr;
7953 +
7954 + vmf->page = alloc_page(GFP_HIGHUSER);
7955 + if (!vmf->page)
7956 + return VM_FAULT_OOM;
7957 +
7958 + kaddr = kmap(vmf->page);
7959 + memset(kaddr, 0, PAGE_SIZE);
7960 + kaddr[0] = 0x9DE3BFA8U; /* save */
7961 + flush_dcache_page(vmf->page);
7962 + kunmap(vmf->page);
7963 + return VM_FAULT_MAJOR;
7964 +}
7965 +
7966 +static const struct vm_operations_struct pax_vm_ops = {
7967 + .close = pax_emuplt_close,
7968 + .fault = pax_emuplt_fault
7969 +};
7970 +
7971 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
7972 +{
7973 + int ret;
7974 +
7975 + INIT_LIST_HEAD(&vma->anon_vma_chain);
7976 + vma->vm_mm = current->mm;
7977 + vma->vm_start = addr;
7978 + vma->vm_end = addr + PAGE_SIZE;
7979 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
7980 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
7981 + vma->vm_ops = &pax_vm_ops;
7982 +
7983 + ret = insert_vm_struct(current->mm, vma);
7984 + if (ret)
7985 + return ret;
7986 +
7987 + ++current->mm->total_vm;
7988 + return 0;
7989 +}
7990 +#endif
7991 +
7992 +/*
7993 + * PaX: decide what to do with offenders (regs->tpc = fault address)
7994 + *
7995 + * returns 1 when task should be killed
7996 + * 2 when patched PLT trampoline was detected
7997 + * 3 when unpatched PLT trampoline was detected
7998 + */
7999 +static int pax_handle_fetch_fault(struct pt_regs *regs)
8000 +{
8001 +
8002 +#ifdef CONFIG_PAX_EMUPLT
8003 + int err;
8004 +
8005 + do { /* PaX: patched PLT emulation #1 */
8006 + unsigned int sethi1, sethi2, jmpl;
8007 +
8008 + err = get_user(sethi1, (unsigned int *)regs->tpc);
8009 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
8010 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
8011 +
8012 + if (err)
8013 + break;
8014 +
8015 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
8016 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
8017 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
8018 + {
8019 + unsigned long addr;
8020 +
8021 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
8022 + addr = regs->u_regs[UREG_G1];
8023 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
8024 +
8025 + if (test_thread_flag(TIF_32BIT))
8026 + addr &= 0xFFFFFFFFUL;
8027 +
8028 + regs->tpc = addr;
8029 + regs->tnpc = addr+4;
8030 + return 2;
8031 + }
8032 + } while (0);
8033 +
8034 + do { /* PaX: patched PLT emulation #2 */
8035 + unsigned int ba;
8036 +
8037 + err = get_user(ba, (unsigned int *)regs->tpc);
8038 +
8039 + if (err)
8040 + break;
8041 +
8042 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
8043 + unsigned long addr;
8044 +
8045 + if ((ba & 0xFFC00000U) == 0x30800000U)
8046 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
8047 + else
8048 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
8049 +
8050 + if (test_thread_flag(TIF_32BIT))
8051 + addr &= 0xFFFFFFFFUL;
8052 +
8053 + regs->tpc = addr;
8054 + regs->tnpc = addr+4;
8055 + return 2;
8056 + }
8057 + } while (0);
8058 +
8059 + do { /* PaX: patched PLT emulation #3 */
8060 + unsigned int sethi, bajmpl, nop;
8061 +
8062 + err = get_user(sethi, (unsigned int *)regs->tpc);
8063 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
8064 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
8065 +
8066 + if (err)
8067 + break;
8068 +
8069 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8070 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
8071 + nop == 0x01000000U)
8072 + {
8073 + unsigned long addr;
8074 +
8075 + addr = (sethi & 0x003FFFFFU) << 10;
8076 + regs->u_regs[UREG_G1] = addr;
8077 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
8078 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
8079 + else
8080 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
8081 +
8082 + if (test_thread_flag(TIF_32BIT))
8083 + addr &= 0xFFFFFFFFUL;
8084 +
8085 + regs->tpc = addr;
8086 + regs->tnpc = addr+4;
8087 + return 2;
8088 + }
8089 + } while (0);
8090 +
8091 + do { /* PaX: patched PLT emulation #4 */
8092 + unsigned int sethi, mov1, call, mov2;
8093 +
8094 + err = get_user(sethi, (unsigned int *)regs->tpc);
8095 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
8096 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
8097 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
8098 +
8099 + if (err)
8100 + break;
8101 +
8102 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8103 + mov1 == 0x8210000FU &&
8104 + (call & 0xC0000000U) == 0x40000000U &&
8105 + mov2 == 0x9E100001U)
8106 + {
8107 + unsigned long addr;
8108 +
8109 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
8110 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
8111 +
8112 + if (test_thread_flag(TIF_32BIT))
8113 + addr &= 0xFFFFFFFFUL;
8114 +
8115 + regs->tpc = addr;
8116 + regs->tnpc = addr+4;
8117 + return 2;
8118 + }
8119 + } while (0);
8120 +
8121 + do { /* PaX: patched PLT emulation #5 */
8122 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
8123 +
8124 + err = get_user(sethi, (unsigned int *)regs->tpc);
8125 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
8126 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
8127 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
8128 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
8129 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
8130 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
8131 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
8132 +
8133 + if (err)
8134 + break;
8135 +
8136 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8137 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
8138 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
8139 + (or1 & 0xFFFFE000U) == 0x82106000U &&
8140 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
8141 + sllx == 0x83287020U &&
8142 + jmpl == 0x81C04005U &&
8143 + nop == 0x01000000U)
8144 + {
8145 + unsigned long addr;
8146 +
8147 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
8148 + regs->u_regs[UREG_G1] <<= 32;
8149 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
8150 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
8151 + regs->tpc = addr;
8152 + regs->tnpc = addr+4;
8153 + return 2;
8154 + }
8155 + } while (0);
8156 +
8157 + do { /* PaX: patched PLT emulation #6 */
8158 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
8159 +
8160 + err = get_user(sethi, (unsigned int *)regs->tpc);
8161 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
8162 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
8163 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
8164 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
8165 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
8166 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
8167 +
8168 + if (err)
8169 + break;
8170 +
8171 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8172 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
8173 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
8174 + sllx == 0x83287020U &&
8175 + (or & 0xFFFFE000U) == 0x8A116000U &&
8176 + jmpl == 0x81C04005U &&
8177 + nop == 0x01000000U)
8178 + {
8179 + unsigned long addr;
8180 +
8181 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
8182 + regs->u_regs[UREG_G1] <<= 32;
8183 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
8184 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
8185 + regs->tpc = addr;
8186 + regs->tnpc = addr+4;
8187 + return 2;
8188 + }
8189 + } while (0);
8190 +
8191 + do { /* PaX: unpatched PLT emulation step 1 */
8192 + unsigned int sethi, ba, nop;
8193 +
8194 + err = get_user(sethi, (unsigned int *)regs->tpc);
8195 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
8196 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
8197 +
8198 + if (err)
8199 + break;
8200 +
8201 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8202 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
8203 + nop == 0x01000000U)
8204 + {
8205 + unsigned long addr;
8206 + unsigned int save, call;
8207 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
8208 +
8209 + if ((ba & 0xFFC00000U) == 0x30800000U)
8210 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
8211 + else
8212 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
8213 +
8214 + if (test_thread_flag(TIF_32BIT))
8215 + addr &= 0xFFFFFFFFUL;
8216 +
8217 + err = get_user(save, (unsigned int *)addr);
8218 + err |= get_user(call, (unsigned int *)(addr+4));
8219 + err |= get_user(nop, (unsigned int *)(addr+8));
8220 + if (err)
8221 + break;
8222 +
8223 +#ifdef CONFIG_PAX_DLRESOLVE
8224 + if (save == 0x9DE3BFA8U &&
8225 + (call & 0xC0000000U) == 0x40000000U &&
8226 + nop == 0x01000000U)
8227 + {
8228 + struct vm_area_struct *vma;
8229 + unsigned long call_dl_resolve;
8230 +
8231 + down_read(&current->mm->mmap_sem);
8232 + call_dl_resolve = current->mm->call_dl_resolve;
8233 + up_read(&current->mm->mmap_sem);
8234 + if (likely(call_dl_resolve))
8235 + goto emulate;
8236 +
8237 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
8238 +
8239 + down_write(&current->mm->mmap_sem);
8240 + if (current->mm->call_dl_resolve) {
8241 + call_dl_resolve = current->mm->call_dl_resolve;
8242 + up_write(&current->mm->mmap_sem);
8243 + if (vma)
8244 + kmem_cache_free(vm_area_cachep, vma);
8245 + goto emulate;
8246 + }
8247 +
8248 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
8249 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
8250 + up_write(&current->mm->mmap_sem);
8251 + if (vma)
8252 + kmem_cache_free(vm_area_cachep, vma);
8253 + return 1;
8254 + }
8255 +
8256 + if (pax_insert_vma(vma, call_dl_resolve)) {
8257 + up_write(&current->mm->mmap_sem);
8258 + kmem_cache_free(vm_area_cachep, vma);
8259 + return 1;
8260 + }
8261 +
8262 + current->mm->call_dl_resolve = call_dl_resolve;
8263 + up_write(&current->mm->mmap_sem);
8264 +
8265 +emulate:
8266 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8267 + regs->tpc = call_dl_resolve;
8268 + regs->tnpc = addr+4;
8269 + return 3;
8270 + }
8271 +#endif
8272 +
8273 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
8274 + if ((save & 0xFFC00000U) == 0x05000000U &&
8275 + (call & 0xFFFFE000U) == 0x85C0A000U &&
8276 + nop == 0x01000000U)
8277 + {
8278 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8279 + regs->u_regs[UREG_G2] = addr + 4;
8280 + addr = (save & 0x003FFFFFU) << 10;
8281 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
8282 +
8283 + if (test_thread_flag(TIF_32BIT))
8284 + addr &= 0xFFFFFFFFUL;
8285 +
8286 + regs->tpc = addr;
8287 + regs->tnpc = addr+4;
8288 + return 3;
8289 + }
8290 +
8291 + /* PaX: 64-bit PLT stub */
8292 + err = get_user(sethi1, (unsigned int *)addr);
8293 + err |= get_user(sethi2, (unsigned int *)(addr+4));
8294 + err |= get_user(or1, (unsigned int *)(addr+8));
8295 + err |= get_user(or2, (unsigned int *)(addr+12));
8296 + err |= get_user(sllx, (unsigned int *)(addr+16));
8297 + err |= get_user(add, (unsigned int *)(addr+20));
8298 + err |= get_user(jmpl, (unsigned int *)(addr+24));
8299 + err |= get_user(nop, (unsigned int *)(addr+28));
8300 + if (err)
8301 + break;
8302 +
8303 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
8304 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
8305 + (or1 & 0xFFFFE000U) == 0x88112000U &&
8306 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
8307 + sllx == 0x89293020U &&
8308 + add == 0x8A010005U &&
8309 + jmpl == 0x89C14000U &&
8310 + nop == 0x01000000U)
8311 + {
8312 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8313 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
8314 + regs->u_regs[UREG_G4] <<= 32;
8315 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
8316 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
8317 + regs->u_regs[UREG_G4] = addr + 24;
8318 + addr = regs->u_regs[UREG_G5];
8319 + regs->tpc = addr;
8320 + regs->tnpc = addr+4;
8321 + return 3;
8322 + }
8323 + }
8324 + } while (0);
8325 +
8326 +#ifdef CONFIG_PAX_DLRESOLVE
8327 + do { /* PaX: unpatched PLT emulation step 2 */
8328 + unsigned int save, call, nop;
8329 +
8330 + err = get_user(save, (unsigned int *)(regs->tpc-4));
8331 + err |= get_user(call, (unsigned int *)regs->tpc);
8332 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
8333 + if (err)
8334 + break;
8335 +
8336 + if (save == 0x9DE3BFA8U &&
8337 + (call & 0xC0000000U) == 0x40000000U &&
8338 + nop == 0x01000000U)
8339 + {
8340 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
8341 +
8342 + if (test_thread_flag(TIF_32BIT))
8343 + dl_resolve &= 0xFFFFFFFFUL;
8344 +
8345 + regs->u_regs[UREG_RETPC] = regs->tpc;
8346 + regs->tpc = dl_resolve;
8347 + regs->tnpc = dl_resolve+4;
8348 + return 3;
8349 + }
8350 + } while (0);
8351 +#endif
8352 +
8353 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
8354 + unsigned int sethi, ba, nop;
8355 +
8356 + err = get_user(sethi, (unsigned int *)regs->tpc);
8357 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
8358 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
8359 +
8360 + if (err)
8361 + break;
8362 +
8363 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8364 + (ba & 0xFFF00000U) == 0x30600000U &&
8365 + nop == 0x01000000U)
8366 + {
8367 + unsigned long addr;
8368 +
8369 + addr = (sethi & 0x003FFFFFU) << 10;
8370 + regs->u_regs[UREG_G1] = addr;
8371 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
8372 +
8373 + if (test_thread_flag(TIF_32BIT))
8374 + addr &= 0xFFFFFFFFUL;
8375 +
8376 + regs->tpc = addr;
8377 + regs->tnpc = addr+4;
8378 + return 2;
8379 + }
8380 + } while (0);
8381 +
8382 +#endif
8383 +
8384 + return 1;
8385 +}
8386 +
8387 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8388 +{
8389 + unsigned long i;
8390 +
8391 + printk(KERN_ERR "PAX: bytes at PC: ");
8392 + for (i = 0; i < 8; i++) {
8393 + unsigned int c;
8394 + if (get_user(c, (unsigned int *)pc+i))
8395 + printk(KERN_CONT "???????? ");
8396 + else
8397 + printk(KERN_CONT "%08x ", c);
8398 + }
8399 + printk("\n");
8400 +}
8401 +#endif
8402 +
8403 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
8404 {
8405 struct mm_struct *mm = current->mm;
8406 @@ -341,6 +804,29 @@ retry:
8407 if (!vma)
8408 goto bad_area;
8409
8410 +#ifdef CONFIG_PAX_PAGEEXEC
8411 + /* PaX: detect ITLB misses on non-exec pages */
8412 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
8413 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
8414 + {
8415 + if (address != regs->tpc)
8416 + goto good_area;
8417 +
8418 + up_read(&mm->mmap_sem);
8419 + switch (pax_handle_fetch_fault(regs)) {
8420 +
8421 +#ifdef CONFIG_PAX_EMUPLT
8422 + case 2:
8423 + case 3:
8424 + return;
8425 +#endif
8426 +
8427 + }
8428 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
8429 + do_group_exit(SIGKILL);
8430 + }
8431 +#endif
8432 +
8433 /* Pure DTLB misses do not tell us whether the fault causing
8434 * load/store/atomic was a write or not, it only says that there
8435 * was no match. So in such a case we (carefully) read the
8436 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
8437 index f76f83d..ee0d859 100644
8438 --- a/arch/sparc/mm/hugetlbpage.c
8439 +++ b/arch/sparc/mm/hugetlbpage.c
8440 @@ -34,6 +34,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
8441 struct vm_area_struct * vma;
8442 unsigned long task_size = TASK_SIZE;
8443 unsigned long start_addr;
8444 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8445
8446 if (test_thread_flag(TIF_32BIT))
8447 task_size = STACK_TOP32;
8448 @@ -67,7 +68,7 @@ full_search:
8449 }
8450 return -ENOMEM;
8451 }
8452 - if (likely(!vma || addr + len <= vma->vm_start)) {
8453 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
8454 /*
8455 * Remember the place where we stopped the search:
8456 */
8457 @@ -90,6 +91,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8458 struct vm_area_struct *vma;
8459 struct mm_struct *mm = current->mm;
8460 unsigned long addr = addr0;
8461 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8462
8463 /* This should only ever run for 32-bit processes. */
8464 BUG_ON(!test_thread_flag(TIF_32BIT));
8465 @@ -106,7 +108,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8466 /* make sure it can fit in the remaining address space */
8467 if (likely(addr > len)) {
8468 vma = find_vma(mm, addr-len);
8469 - if (!vma || addr <= vma->vm_start) {
8470 + if (check_heap_stack_gap(vma, addr - len, len, offset)) {
8471 /* remember the address as a hint for next time */
8472 return (mm->free_area_cache = addr-len);
8473 }
8474 @@ -115,16 +117,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8475 if (unlikely(mm->mmap_base < len))
8476 goto bottomup;
8477
8478 - addr = (mm->mmap_base-len) & HPAGE_MASK;
8479 + addr = mm->mmap_base - len;
8480
8481 do {
8482 + addr &= HPAGE_MASK;
8483 /*
8484 * Lookup failure means no vma is above this address,
8485 * else if new region fits below vma->vm_start,
8486 * return with success:
8487 */
8488 vma = find_vma(mm, addr);
8489 - if (likely(!vma || addr+len <= vma->vm_start)) {
8490 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
8491 /* remember the address as a hint for next time */
8492 return (mm->free_area_cache = addr);
8493 }
8494 @@ -134,8 +137,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8495 mm->cached_hole_size = vma->vm_start - addr;
8496
8497 /* try just below the current vma->vm_start */
8498 - addr = (vma->vm_start-len) & HPAGE_MASK;
8499 - } while (likely(len < vma->vm_start));
8500 + addr = skip_heap_stack_gap(vma, len, offset);
8501 + } while (!IS_ERR_VALUE(addr));
8502
8503 bottomup:
8504 /*
8505 @@ -163,6 +166,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
8506 struct mm_struct *mm = current->mm;
8507 struct vm_area_struct *vma;
8508 unsigned long task_size = TASK_SIZE;
8509 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8510
8511 if (test_thread_flag(TIF_32BIT))
8512 task_size = STACK_TOP32;
8513 @@ -181,8 +185,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
8514 if (addr) {
8515 addr = ALIGN(addr, HPAGE_SIZE);
8516 vma = find_vma(mm, addr);
8517 - if (task_size - len >= addr &&
8518 - (!vma || addr + len <= vma->vm_start))
8519 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8520 return addr;
8521 }
8522 if (mm->get_unmapped_area == arch_get_unmapped_area)
8523 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
8524 index f4500c6..889656c 100644
8525 --- a/arch/tile/include/asm/atomic_64.h
8526 +++ b/arch/tile/include/asm/atomic_64.h
8527 @@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
8528
8529 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8530
8531 +#define atomic64_read_unchecked(v) atomic64_read(v)
8532 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8533 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8534 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8535 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8536 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
8537 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8538 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
8539 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8540 +
8541 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
8542 #define smp_mb__before_atomic_dec() smp_mb()
8543 #define smp_mb__after_atomic_dec() smp_mb()
8544 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
8545 index a9a5299..0fce79e 100644
8546 --- a/arch/tile/include/asm/cache.h
8547 +++ b/arch/tile/include/asm/cache.h
8548 @@ -15,11 +15,12 @@
8549 #ifndef _ASM_TILE_CACHE_H
8550 #define _ASM_TILE_CACHE_H
8551
8552 +#include <linux/const.h>
8553 #include <arch/chip.h>
8554
8555 /* bytes per L1 data cache line */
8556 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
8557 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8558 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8559
8560 /* bytes per L2 cache line */
8561 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
8562 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
8563 index 9ab078a..d6635c2 100644
8564 --- a/arch/tile/include/asm/uaccess.h
8565 +++ b/arch/tile/include/asm/uaccess.h
8566 @@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
8567 const void __user *from,
8568 unsigned long n)
8569 {
8570 - int sz = __compiletime_object_size(to);
8571 + size_t sz = __compiletime_object_size(to);
8572
8573 - if (likely(sz == -1 || sz >= n))
8574 + if (likely(sz == (size_t)-1 || sz >= n))
8575 n = _copy_from_user(to, from, n);
8576 else
8577 copy_from_user_overflow();
8578 diff --git a/arch/um/Makefile b/arch/um/Makefile
8579 index 133f7de..1d6f2f1 100644
8580 --- a/arch/um/Makefile
8581 +++ b/arch/um/Makefile
8582 @@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
8583 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
8584 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
8585
8586 +ifdef CONSTIFY_PLUGIN
8587 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
8588 +endif
8589 +
8590 #This will adjust *FLAGS accordingly to the platform.
8591 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
8592
8593 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
8594 index 19e1bdd..3665b77 100644
8595 --- a/arch/um/include/asm/cache.h
8596 +++ b/arch/um/include/asm/cache.h
8597 @@ -1,6 +1,7 @@
8598 #ifndef __UM_CACHE_H
8599 #define __UM_CACHE_H
8600
8601 +#include <linux/const.h>
8602
8603 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
8604 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
8605 @@ -12,6 +13,6 @@
8606 # define L1_CACHE_SHIFT 5
8607 #endif
8608
8609 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8610 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8611
8612 #endif
8613 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
8614 index 2e0a6b1..a64d0f5 100644
8615 --- a/arch/um/include/asm/kmap_types.h
8616 +++ b/arch/um/include/asm/kmap_types.h
8617 @@ -8,6 +8,6 @@
8618
8619 /* No more #include "asm/arch/kmap_types.h" ! */
8620
8621 -#define KM_TYPE_NR 14
8622 +#define KM_TYPE_NR 15
8623
8624 #endif
8625 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
8626 index 5ff53d9..5850cdf 100644
8627 --- a/arch/um/include/asm/page.h
8628 +++ b/arch/um/include/asm/page.h
8629 @@ -14,6 +14,9 @@
8630 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
8631 #define PAGE_MASK (~(PAGE_SIZE-1))
8632
8633 +#define ktla_ktva(addr) (addr)
8634 +#define ktva_ktla(addr) (addr)
8635 +
8636 #ifndef __ASSEMBLY__
8637
8638 struct page;
8639 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
8640 index 0032f92..cd151e0 100644
8641 --- a/arch/um/include/asm/pgtable-3level.h
8642 +++ b/arch/um/include/asm/pgtable-3level.h
8643 @@ -58,6 +58,7 @@
8644 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
8645 #define pud_populate(mm, pud, pmd) \
8646 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
8647 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8648
8649 #ifdef CONFIG_64BIT
8650 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
8651 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
8652 index b6d699c..df7ac1d 100644
8653 --- a/arch/um/kernel/process.c
8654 +++ b/arch/um/kernel/process.c
8655 @@ -387,22 +387,6 @@ int singlestepping(void * t)
8656 return 2;
8657 }
8658
8659 -/*
8660 - * Only x86 and x86_64 have an arch_align_stack().
8661 - * All other arches have "#define arch_align_stack(x) (x)"
8662 - * in their asm/system.h
8663 - * As this is included in UML from asm-um/system-generic.h,
8664 - * we can use it to behave as the subarch does.
8665 - */
8666 -#ifndef arch_align_stack
8667 -unsigned long arch_align_stack(unsigned long sp)
8668 -{
8669 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8670 - sp -= get_random_int() % 8192;
8671 - return sp & ~0xf;
8672 -}
8673 -#endif
8674 -
8675 unsigned long get_wchan(struct task_struct *p)
8676 {
8677 unsigned long stack_page, sp, ip;
8678 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
8679 index ad8f795..2c7eec6 100644
8680 --- a/arch/unicore32/include/asm/cache.h
8681 +++ b/arch/unicore32/include/asm/cache.h
8682 @@ -12,8 +12,10 @@
8683 #ifndef __UNICORE_CACHE_H__
8684 #define __UNICORE_CACHE_H__
8685
8686 -#define L1_CACHE_SHIFT (5)
8687 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8688 +#include <linux/const.h>
8689 +
8690 +#define L1_CACHE_SHIFT 5
8691 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8692
8693 /*
8694 * Memory returned by kmalloc() may be used for DMA, so we must make
8695 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
8696 index 46c3bff..b82f26b 100644
8697 --- a/arch/x86/Kconfig
8698 +++ b/arch/x86/Kconfig
8699 @@ -241,7 +241,7 @@ config X86_HT
8700
8701 config X86_32_LAZY_GS
8702 def_bool y
8703 - depends on X86_32 && !CC_STACKPROTECTOR
8704 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
8705
8706 config ARCH_HWEIGHT_CFLAGS
8707 string
8708 @@ -1033,6 +1033,7 @@ config MICROCODE_OLD_INTERFACE
8709
8710 config X86_MSR
8711 tristate "/dev/cpu/*/msr - Model-specific register support"
8712 + depends on !GRKERNSEC_KMEM
8713 ---help---
8714 This device gives privileged processes access to the x86
8715 Model-Specific Registers (MSRs). It is a character device with
8716 @@ -1056,7 +1057,7 @@ choice
8717
8718 config NOHIGHMEM
8719 bool "off"
8720 - depends on !X86_NUMAQ
8721 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
8722 ---help---
8723 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
8724 However, the address space of 32-bit x86 processors is only 4
8725 @@ -1093,7 +1094,7 @@ config NOHIGHMEM
8726
8727 config HIGHMEM4G
8728 bool "4GB"
8729 - depends on !X86_NUMAQ
8730 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
8731 ---help---
8732 Select this if you have a 32-bit processor and between 1 and 4
8733 gigabytes of physical RAM.
8734 @@ -1147,7 +1148,7 @@ config PAGE_OFFSET
8735 hex
8736 default 0xB0000000 if VMSPLIT_3G_OPT
8737 default 0x80000000 if VMSPLIT_2G
8738 - default 0x78000000 if VMSPLIT_2G_OPT
8739 + default 0x70000000 if VMSPLIT_2G_OPT
8740 default 0x40000000 if VMSPLIT_1G
8741 default 0xC0000000
8742 depends on X86_32
8743 @@ -1548,6 +1549,7 @@ config SECCOMP
8744
8745 config CC_STACKPROTECTOR
8746 bool "Enable -fstack-protector buffer overflow detection"
8747 + depends on X86_64 || !PAX_MEMORY_UDEREF
8748 ---help---
8749 This option turns on the -fstack-protector GCC feature. This
8750 feature puts, at the beginning of functions, a canary value on
8751 @@ -1605,6 +1607,7 @@ config KEXEC_JUMP
8752 config PHYSICAL_START
8753 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
8754 default "0x1000000"
8755 + range 0x400000 0x40000000
8756 ---help---
8757 This gives the physical address where the kernel is loaded.
8758
8759 @@ -1668,6 +1671,7 @@ config X86_NEED_RELOCS
8760 config PHYSICAL_ALIGN
8761 hex "Alignment value to which kernel should be aligned" if X86_32
8762 default "0x1000000"
8763 + range 0x400000 0x1000000 if PAX_KERNEXEC
8764 range 0x2000 0x1000000
8765 ---help---
8766 This value puts the alignment restrictions on physical address
8767 @@ -1699,9 +1703,10 @@ config HOTPLUG_CPU
8768 Say N if you want to disable CPU hotplug.
8769
8770 config COMPAT_VDSO
8771 - def_bool y
8772 + def_bool n
8773 prompt "Compat VDSO support"
8774 depends on X86_32 || IA32_EMULATION
8775 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
8776 ---help---
8777 Map the 32-bit VDSO to the predictable old-style address too.
8778
8779 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
8780 index f3b86d0..17fd30f 100644
8781 --- a/arch/x86/Kconfig.cpu
8782 +++ b/arch/x86/Kconfig.cpu
8783 @@ -335,7 +335,7 @@ config X86_PPRO_FENCE
8784
8785 config X86_F00F_BUG
8786 def_bool y
8787 - depends on M586MMX || M586TSC || M586 || M486 || M386
8788 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
8789
8790 config X86_INVD_BUG
8791 def_bool y
8792 @@ -359,7 +359,7 @@ config X86_POPAD_OK
8793
8794 config X86_ALIGNMENT_16
8795 def_bool y
8796 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
8797 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
8798
8799 config X86_INTEL_USERCOPY
8800 def_bool y
8801 @@ -405,7 +405,7 @@ config X86_CMPXCHG64
8802 # generates cmov.
8803 config X86_CMOV
8804 def_bool y
8805 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
8806 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
8807
8808 config X86_MINIMUM_CPU_FAMILY
8809 int
8810 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
8811 index b322f12..652d0d9 100644
8812 --- a/arch/x86/Kconfig.debug
8813 +++ b/arch/x86/Kconfig.debug
8814 @@ -84,7 +84,7 @@ config X86_PTDUMP
8815 config DEBUG_RODATA
8816 bool "Write protect kernel read-only data structures"
8817 default y
8818 - depends on DEBUG_KERNEL
8819 + depends on DEBUG_KERNEL && BROKEN
8820 ---help---
8821 Mark the kernel read-only data as write-protected in the pagetables,
8822 in order to catch accidental (and incorrect) writes to such const
8823 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
8824
8825 config DEBUG_SET_MODULE_RONX
8826 bool "Set loadable kernel module data as NX and text as RO"
8827 - depends on MODULES
8828 + depends on MODULES && BROKEN
8829 ---help---
8830 This option helps catch unintended modifications to loadable
8831 kernel module's text and read-only data. It also prevents execution
8832 @@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
8833
8834 config DEBUG_STRICT_USER_COPY_CHECKS
8835 bool "Strict copy size checks"
8836 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
8837 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
8838 ---help---
8839 Enabling this option turns a certain set of sanity checks for user
8840 copy operations into compile time failures.
8841 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
8842 index 05afcca..b6ecb51 100644
8843 --- a/arch/x86/Makefile
8844 +++ b/arch/x86/Makefile
8845 @@ -50,6 +50,7 @@ else
8846 UTS_MACHINE := x86_64
8847 CHECKFLAGS += -D__x86_64__ -m64
8848
8849 + biarch := $(call cc-option,-m64)
8850 KBUILD_AFLAGS += -m64
8851 KBUILD_CFLAGS += -m64
8852
8853 @@ -229,3 +230,12 @@ define archhelp
8854 echo ' FDARGS="..." arguments for the booted kernel'
8855 echo ' FDINITRD=file initrd for the booted kernel'
8856 endef
8857 +
8858 +define OLD_LD
8859 +
8860 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
8861 +*** Please upgrade your binutils to 2.18 or newer
8862 +endef
8863 +
8864 +archprepare:
8865 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
8866 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
8867 index ccce0ed..fd9da25 100644
8868 --- a/arch/x86/boot/Makefile
8869 +++ b/arch/x86/boot/Makefile
8870 @@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
8871 $(call cc-option, -fno-stack-protector) \
8872 $(call cc-option, -mpreferred-stack-boundary=2)
8873 KBUILD_CFLAGS += $(call cc-option, -m32)
8874 +ifdef CONSTIFY_PLUGIN
8875 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
8876 +endif
8877 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
8878 GCOV_PROFILE := n
8879
8880 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
8881 index 878e4b9..20537ab 100644
8882 --- a/arch/x86/boot/bitops.h
8883 +++ b/arch/x86/boot/bitops.h
8884 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
8885 u8 v;
8886 const u32 *p = (const u32 *)addr;
8887
8888 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
8889 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
8890 return v;
8891 }
8892
8893 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
8894
8895 static inline void set_bit(int nr, void *addr)
8896 {
8897 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
8898 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
8899 }
8900
8901 #endif /* BOOT_BITOPS_H */
8902 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
8903 index 18997e5..83d9c67 100644
8904 --- a/arch/x86/boot/boot.h
8905 +++ b/arch/x86/boot/boot.h
8906 @@ -85,7 +85,7 @@ static inline void io_delay(void)
8907 static inline u16 ds(void)
8908 {
8909 u16 seg;
8910 - asm("movw %%ds,%0" : "=rm" (seg));
8911 + asm volatile("movw %%ds,%0" : "=rm" (seg));
8912 return seg;
8913 }
8914
8915 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
8916 static inline int memcmp(const void *s1, const void *s2, size_t len)
8917 {
8918 u8 diff;
8919 - asm("repe; cmpsb; setnz %0"
8920 + asm volatile("repe; cmpsb; setnz %0"
8921 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
8922 return diff;
8923 }
8924 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
8925 index 8a84501..b2d165f 100644
8926 --- a/arch/x86/boot/compressed/Makefile
8927 +++ b/arch/x86/boot/compressed/Makefile
8928 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
8929 KBUILD_CFLAGS += $(cflags-y)
8930 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
8931 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
8932 +ifdef CONSTIFY_PLUGIN
8933 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
8934 +endif
8935
8936 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
8937 GCOV_PROFILE := n
8938 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
8939 index ccae7e2..8ac70be 100644
8940 --- a/arch/x86/boot/compressed/eboot.c
8941 +++ b/arch/x86/boot/compressed/eboot.c
8942 @@ -144,7 +144,6 @@ again:
8943 *addr = max_addr;
8944 }
8945
8946 -free_pool:
8947 efi_call_phys1(sys_table->boottime->free_pool, map);
8948
8949 fail:
8950 @@ -208,7 +207,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
8951 if (i == map_size / desc_size)
8952 status = EFI_NOT_FOUND;
8953
8954 -free_pool:
8955 efi_call_phys1(sys_table->boottime->free_pool, map);
8956 fail:
8957 return status;
8958 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
8959 index ccb2f4a..e49b20e 100644
8960 --- a/arch/x86/boot/compressed/head_32.S
8961 +++ b/arch/x86/boot/compressed/head_32.S
8962 @@ -118,7 +118,7 @@ preferred_addr:
8963 notl %eax
8964 andl %eax, %ebx
8965 #else
8966 - movl $LOAD_PHYSICAL_ADDR, %ebx
8967 + movl $____LOAD_PHYSICAL_ADDR, %ebx
8968 #endif
8969
8970 /* Target address to relocate to for decompression */
8971 @@ -204,7 +204,7 @@ relocated:
8972 * and where it was actually loaded.
8973 */
8974 movl %ebp, %ebx
8975 - subl $LOAD_PHYSICAL_ADDR, %ebx
8976 + subl $____LOAD_PHYSICAL_ADDR, %ebx
8977 jz 2f /* Nothing to be done if loaded at compiled addr. */
8978 /*
8979 * Process relocations.
8980 @@ -212,8 +212,7 @@ relocated:
8981
8982 1: subl $4, %edi
8983 movl (%edi), %ecx
8984 - testl %ecx, %ecx
8985 - jz 2f
8986 + jecxz 2f
8987 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
8988 jmp 1b
8989 2:
8990 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
8991 index 2c4b171..e1fa5b1 100644
8992 --- a/arch/x86/boot/compressed/head_64.S
8993 +++ b/arch/x86/boot/compressed/head_64.S
8994 @@ -91,7 +91,7 @@ ENTRY(startup_32)
8995 notl %eax
8996 andl %eax, %ebx
8997 #else
8998 - movl $LOAD_PHYSICAL_ADDR, %ebx
8999 + movl $____LOAD_PHYSICAL_ADDR, %ebx
9000 #endif
9001
9002 /* Target address to relocate to for decompression */
9003 @@ -273,7 +273,7 @@ preferred_addr:
9004 notq %rax
9005 andq %rax, %rbp
9006 #else
9007 - movq $LOAD_PHYSICAL_ADDR, %rbp
9008 + movq $____LOAD_PHYSICAL_ADDR, %rbp
9009 #endif
9010
9011 /* Target address to relocate to for decompression */
9012 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
9013 index 88f7ff6..ed695dd 100644
9014 --- a/arch/x86/boot/compressed/misc.c
9015 +++ b/arch/x86/boot/compressed/misc.c
9016 @@ -303,7 +303,7 @@ static void parse_elf(void *output)
9017 case PT_LOAD:
9018 #ifdef CONFIG_RELOCATABLE
9019 dest = output;
9020 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
9021 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
9022 #else
9023 dest = (void *)(phdr->p_paddr);
9024 #endif
9025 @@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
9026 error("Destination address too large");
9027 #endif
9028 #ifndef CONFIG_RELOCATABLE
9029 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
9030 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
9031 error("Wrong destination address");
9032 #endif
9033
9034 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
9035 index 4d3ff03..e4972ff 100644
9036 --- a/arch/x86/boot/cpucheck.c
9037 +++ b/arch/x86/boot/cpucheck.c
9038 @@ -74,7 +74,7 @@ static int has_fpu(void)
9039 u16 fcw = -1, fsw = -1;
9040 u32 cr0;
9041
9042 - asm("movl %%cr0,%0" : "=r" (cr0));
9043 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
9044 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
9045 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
9046 asm volatile("movl %0,%%cr0" : : "r" (cr0));
9047 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
9048 {
9049 u32 f0, f1;
9050
9051 - asm("pushfl ; "
9052 + asm volatile("pushfl ; "
9053 "pushfl ; "
9054 "popl %0 ; "
9055 "movl %0,%1 ; "
9056 @@ -115,7 +115,7 @@ static void get_flags(void)
9057 set_bit(X86_FEATURE_FPU, cpu.flags);
9058
9059 if (has_eflag(X86_EFLAGS_ID)) {
9060 - asm("cpuid"
9061 + asm volatile("cpuid"
9062 : "=a" (max_intel_level),
9063 "=b" (cpu_vendor[0]),
9064 "=d" (cpu_vendor[1]),
9065 @@ -124,7 +124,7 @@ static void get_flags(void)
9066
9067 if (max_intel_level >= 0x00000001 &&
9068 max_intel_level <= 0x0000ffff) {
9069 - asm("cpuid"
9070 + asm volatile("cpuid"
9071 : "=a" (tfms),
9072 "=c" (cpu.flags[4]),
9073 "=d" (cpu.flags[0])
9074 @@ -136,7 +136,7 @@ static void get_flags(void)
9075 cpu.model += ((tfms >> 16) & 0xf) << 4;
9076 }
9077
9078 - asm("cpuid"
9079 + asm volatile("cpuid"
9080 : "=a" (max_amd_level)
9081 : "a" (0x80000000)
9082 : "ebx", "ecx", "edx");
9083 @@ -144,7 +144,7 @@ static void get_flags(void)
9084 if (max_amd_level >= 0x80000001 &&
9085 max_amd_level <= 0x8000ffff) {
9086 u32 eax = 0x80000001;
9087 - asm("cpuid"
9088 + asm volatile("cpuid"
9089 : "+a" (eax),
9090 "=c" (cpu.flags[6]),
9091 "=d" (cpu.flags[1])
9092 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
9093 u32 ecx = MSR_K7_HWCR;
9094 u32 eax, edx;
9095
9096 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9097 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9098 eax &= ~(1 << 15);
9099 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9100 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9101
9102 get_flags(); /* Make sure it really did something */
9103 err = check_flags();
9104 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
9105 u32 ecx = MSR_VIA_FCR;
9106 u32 eax, edx;
9107
9108 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9109 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9110 eax |= (1<<1)|(1<<7);
9111 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9112 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9113
9114 set_bit(X86_FEATURE_CX8, cpu.flags);
9115 err = check_flags();
9116 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
9117 u32 eax, edx;
9118 u32 level = 1;
9119
9120 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9121 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
9122 - asm("cpuid"
9123 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9124 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
9125 + asm volatile("cpuid"
9126 : "+a" (level), "=d" (cpu.flags[0])
9127 : : "ecx", "ebx");
9128 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9129 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9130
9131 err = check_flags();
9132 }
9133 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
9134 index 8c132a6..13e5c96 100644
9135 --- a/arch/x86/boot/header.S
9136 +++ b/arch/x86/boot/header.S
9137 @@ -387,10 +387,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
9138 # single linked list of
9139 # struct setup_data
9140
9141 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
9142 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
9143
9144 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
9145 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
9146 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
9147 +#else
9148 #define VO_INIT_SIZE (VO__end - VO__text)
9149 +#endif
9150 #if ZO_INIT_SIZE > VO_INIT_SIZE
9151 #define INIT_SIZE ZO_INIT_SIZE
9152 #else
9153 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
9154 index db75d07..8e6d0af 100644
9155 --- a/arch/x86/boot/memory.c
9156 +++ b/arch/x86/boot/memory.c
9157 @@ -19,7 +19,7 @@
9158
9159 static int detect_memory_e820(void)
9160 {
9161 - int count = 0;
9162 + unsigned int count = 0;
9163 struct biosregs ireg, oreg;
9164 struct e820entry *desc = boot_params.e820_map;
9165 static struct e820entry buf; /* static so it is zeroed */
9166 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
9167 index 11e8c6e..fdbb1ed 100644
9168 --- a/arch/x86/boot/video-vesa.c
9169 +++ b/arch/x86/boot/video-vesa.c
9170 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
9171
9172 boot_params.screen_info.vesapm_seg = oreg.es;
9173 boot_params.screen_info.vesapm_off = oreg.di;
9174 + boot_params.screen_info.vesapm_size = oreg.cx;
9175 }
9176
9177 /*
9178 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
9179 index 43eda28..5ab5fdb 100644
9180 --- a/arch/x86/boot/video.c
9181 +++ b/arch/x86/boot/video.c
9182 @@ -96,7 +96,7 @@ static void store_mode_params(void)
9183 static unsigned int get_entry(void)
9184 {
9185 char entry_buf[4];
9186 - int i, len = 0;
9187 + unsigned int i, len = 0;
9188 int key;
9189 unsigned int v;
9190
9191 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
9192 index 5b577d5..3c1fed4 100644
9193 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
9194 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
9195 @@ -8,6 +8,8 @@
9196 * including this sentence is retained in full.
9197 */
9198
9199 +#include <asm/alternative-asm.h>
9200 +
9201 .extern crypto_ft_tab
9202 .extern crypto_it_tab
9203 .extern crypto_fl_tab
9204 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
9205 je B192; \
9206 leaq 32(r9),r9;
9207
9208 +#define ret pax_force_retaddr 0, 1; ret
9209 +
9210 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
9211 movq r1,r2; \
9212 movq r3,r4; \
9213 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
9214 index 3470624..201259d 100644
9215 --- a/arch/x86/crypto/aesni-intel_asm.S
9216 +++ b/arch/x86/crypto/aesni-intel_asm.S
9217 @@ -31,6 +31,7 @@
9218
9219 #include <linux/linkage.h>
9220 #include <asm/inst.h>
9221 +#include <asm/alternative-asm.h>
9222
9223 #ifdef __x86_64__
9224 .data
9225 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
9226 pop %r14
9227 pop %r13
9228 pop %r12
9229 + pax_force_retaddr 0, 1
9230 ret
9231 +ENDPROC(aesni_gcm_dec)
9232
9233
9234 /*****************************************************************************
9235 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
9236 pop %r14
9237 pop %r13
9238 pop %r12
9239 + pax_force_retaddr 0, 1
9240 ret
9241 +ENDPROC(aesni_gcm_enc)
9242
9243 #endif
9244
9245 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
9246 pxor %xmm1, %xmm0
9247 movaps %xmm0, (TKEYP)
9248 add $0x10, TKEYP
9249 + pax_force_retaddr_bts
9250 ret
9251
9252 .align 4
9253 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
9254 shufps $0b01001110, %xmm2, %xmm1
9255 movaps %xmm1, 0x10(TKEYP)
9256 add $0x20, TKEYP
9257 + pax_force_retaddr_bts
9258 ret
9259
9260 .align 4
9261 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
9262
9263 movaps %xmm0, (TKEYP)
9264 add $0x10, TKEYP
9265 + pax_force_retaddr_bts
9266 ret
9267
9268 .align 4
9269 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
9270 pxor %xmm1, %xmm2
9271 movaps %xmm2, (TKEYP)
9272 add $0x10, TKEYP
9273 + pax_force_retaddr_bts
9274 ret
9275
9276 /*
9277 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
9278 #ifndef __x86_64__
9279 popl KEYP
9280 #endif
9281 + pax_force_retaddr 0, 1
9282 ret
9283 +ENDPROC(aesni_set_key)
9284
9285 /*
9286 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
9287 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
9288 popl KLEN
9289 popl KEYP
9290 #endif
9291 + pax_force_retaddr 0, 1
9292 ret
9293 +ENDPROC(aesni_enc)
9294
9295 /*
9296 * _aesni_enc1: internal ABI
9297 @@ -1959,6 +1972,7 @@ _aesni_enc1:
9298 AESENC KEY STATE
9299 movaps 0x70(TKEYP), KEY
9300 AESENCLAST KEY STATE
9301 + pax_force_retaddr_bts
9302 ret
9303
9304 /*
9305 @@ -2067,6 +2081,7 @@ _aesni_enc4:
9306 AESENCLAST KEY STATE2
9307 AESENCLAST KEY STATE3
9308 AESENCLAST KEY STATE4
9309 + pax_force_retaddr_bts
9310 ret
9311
9312 /*
9313 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
9314 popl KLEN
9315 popl KEYP
9316 #endif
9317 + pax_force_retaddr 0, 1
9318 ret
9319 +ENDPROC(aesni_dec)
9320
9321 /*
9322 * _aesni_dec1: internal ABI
9323 @@ -2146,6 +2163,7 @@ _aesni_dec1:
9324 AESDEC KEY STATE
9325 movaps 0x70(TKEYP), KEY
9326 AESDECLAST KEY STATE
9327 + pax_force_retaddr_bts
9328 ret
9329
9330 /*
9331 @@ -2254,6 +2272,7 @@ _aesni_dec4:
9332 AESDECLAST KEY STATE2
9333 AESDECLAST KEY STATE3
9334 AESDECLAST KEY STATE4
9335 + pax_force_retaddr_bts
9336 ret
9337
9338 /*
9339 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
9340 popl KEYP
9341 popl LEN
9342 #endif
9343 + pax_force_retaddr 0, 1
9344 ret
9345 +ENDPROC(aesni_ecb_enc)
9346
9347 /*
9348 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
9349 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
9350 popl KEYP
9351 popl LEN
9352 #endif
9353 + pax_force_retaddr 0, 1
9354 ret
9355 +ENDPROC(aesni_ecb_dec)
9356
9357 /*
9358 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
9359 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
9360 popl LEN
9361 popl IVP
9362 #endif
9363 + pax_force_retaddr 0, 1
9364 ret
9365 +ENDPROC(aesni_cbc_enc)
9366
9367 /*
9368 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
9369 @@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
9370 popl LEN
9371 popl IVP
9372 #endif
9373 + pax_force_retaddr 0, 1
9374 ret
9375 +ENDPROC(aesni_cbc_dec)
9376
9377 #ifdef __x86_64__
9378 .align 16
9379 @@ -2526,6 +2553,7 @@ _aesni_inc_init:
9380 mov $1, TCTR_LOW
9381 MOVQ_R64_XMM TCTR_LOW INC
9382 MOVQ_R64_XMM CTR TCTR_LOW
9383 + pax_force_retaddr_bts
9384 ret
9385
9386 /*
9387 @@ -2554,6 +2582,7 @@ _aesni_inc:
9388 .Linc_low:
9389 movaps CTR, IV
9390 PSHUFB_XMM BSWAP_MASK IV
9391 + pax_force_retaddr_bts
9392 ret
9393
9394 /*
9395 @@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
9396 .Lctr_enc_ret:
9397 movups IV, (IVP)
9398 .Lctr_enc_just_ret:
9399 + pax_force_retaddr 0, 1
9400 ret
9401 +ENDPROC(aesni_ctr_enc)
9402 #endif
9403 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
9404 index 391d245..67f35c2 100644
9405 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
9406 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
9407 @@ -20,6 +20,8 @@
9408 *
9409 */
9410
9411 +#include <asm/alternative-asm.h>
9412 +
9413 .file "blowfish-x86_64-asm.S"
9414 .text
9415
9416 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
9417 jnz __enc_xor;
9418
9419 write_block();
9420 + pax_force_retaddr 0, 1
9421 ret;
9422 __enc_xor:
9423 xor_block();
9424 + pax_force_retaddr 0, 1
9425 ret;
9426
9427 .align 8
9428 @@ -188,6 +192,7 @@ blowfish_dec_blk:
9429
9430 movq %r11, %rbp;
9431
9432 + pax_force_retaddr 0, 1
9433 ret;
9434
9435 /**********************************************************************
9436 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
9437
9438 popq %rbx;
9439 popq %rbp;
9440 + pax_force_retaddr 0, 1
9441 ret;
9442
9443 __enc_xor4:
9444 @@ -349,6 +355,7 @@ __enc_xor4:
9445
9446 popq %rbx;
9447 popq %rbp;
9448 + pax_force_retaddr 0, 1
9449 ret;
9450
9451 .align 8
9452 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
9453 popq %rbx;
9454 popq %rbp;
9455
9456 + pax_force_retaddr 0, 1
9457 ret;
9458
9459 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
9460 index 0b33743..7a56206 100644
9461 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
9462 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
9463 @@ -20,6 +20,8 @@
9464 *
9465 */
9466
9467 +#include <asm/alternative-asm.h>
9468 +
9469 .file "camellia-x86_64-asm_64.S"
9470 .text
9471
9472 @@ -229,12 +231,14 @@ __enc_done:
9473 enc_outunpack(mov, RT1);
9474
9475 movq RRBP, %rbp;
9476 + pax_force_retaddr 0, 1
9477 ret;
9478
9479 __enc_xor:
9480 enc_outunpack(xor, RT1);
9481
9482 movq RRBP, %rbp;
9483 + pax_force_retaddr 0, 1
9484 ret;
9485
9486 .global camellia_dec_blk;
9487 @@ -275,6 +279,7 @@ __dec_rounds16:
9488 dec_outunpack();
9489
9490 movq RRBP, %rbp;
9491 + pax_force_retaddr 0, 1
9492 ret;
9493
9494 /**********************************************************************
9495 @@ -468,6 +473,7 @@ __enc2_done:
9496
9497 movq RRBP, %rbp;
9498 popq %rbx;
9499 + pax_force_retaddr 0, 1
9500 ret;
9501
9502 __enc2_xor:
9503 @@ -475,6 +481,7 @@ __enc2_xor:
9504
9505 movq RRBP, %rbp;
9506 popq %rbx;
9507 + pax_force_retaddr 0, 1
9508 ret;
9509
9510 .global camellia_dec_blk_2way;
9511 @@ -517,4 +524,5 @@ __dec2_rounds16:
9512
9513 movq RRBP, %rbp;
9514 movq RXOR, %rbx;
9515 + pax_force_retaddr 0, 1
9516 ret;
9517 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
9518 index a41a3aa..bdf5753 100644
9519 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
9520 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
9521 @@ -23,6 +23,8 @@
9522 *
9523 */
9524
9525 +#include <asm/alternative-asm.h>
9526 +
9527 .file "cast5-avx-x86_64-asm_64.S"
9528
9529 .extern cast5_s1
9530 @@ -293,6 +295,7 @@ __skip_enc:
9531 leaq 3*(2*4*4)(%r11), %rax;
9532 outunpack_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
9533
9534 + pax_force_retaddr 0, 1
9535 ret;
9536
9537 __enc_xor16:
9538 @@ -303,6 +306,7 @@ __enc_xor16:
9539 leaq 3*(2*4*4)(%r11), %rax;
9540 outunpack_xor_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
9541
9542 + pax_force_retaddr 0, 1
9543 ret;
9544
9545 .align 16
9546 @@ -369,6 +373,7 @@ __dec_tail:
9547 leaq 3*(2*4*4)(%r11), %rax;
9548 outunpack_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
9549
9550 + pax_force_retaddr 0, 1
9551 ret;
9552
9553 __skip_dec:
9554 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
9555 index 218d283..819e6da 100644
9556 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
9557 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
9558 @@ -23,6 +23,8 @@
9559 *
9560 */
9561
9562 +#include <asm/alternative-asm.h>
9563 +
9564 .file "cast6-avx-x86_64-asm_64.S"
9565
9566 .extern cast6_s1
9567 @@ -324,12 +326,14 @@ __cast6_enc_blk_8way:
9568 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
9569 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
9570
9571 + pax_force_retaddr 0, 1
9572 ret;
9573
9574 __enc_xor8:
9575 outunpack_xor_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
9576 outunpack_xor_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
9577
9578 + pax_force_retaddr 0, 1
9579 ret;
9580
9581 .align 16
9582 @@ -380,4 +384,5 @@ cast6_dec_blk_8way:
9583 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
9584 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
9585
9586 + pax_force_retaddr 0, 1
9587 ret;
9588 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
9589 index 6214a9b..1f4fc9a 100644
9590 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
9591 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
9592 @@ -1,3 +1,5 @@
9593 +#include <asm/alternative-asm.h>
9594 +
9595 # enter ECRYPT_encrypt_bytes
9596 .text
9597 .p2align 5
9598 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
9599 add %r11,%rsp
9600 mov %rdi,%rax
9601 mov %rsi,%rdx
9602 + pax_force_retaddr 0, 1
9603 ret
9604 # bytesatleast65:
9605 ._bytesatleast65:
9606 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
9607 add %r11,%rsp
9608 mov %rdi,%rax
9609 mov %rsi,%rdx
9610 + pax_force_retaddr
9611 ret
9612 # enter ECRYPT_ivsetup
9613 .text
9614 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
9615 add %r11,%rsp
9616 mov %rdi,%rax
9617 mov %rsi,%rdx
9618 + pax_force_retaddr
9619 ret
9620 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
9621 index 504106b..4e50951 100644
9622 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
9623 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
9624 @@ -24,6 +24,8 @@
9625 *
9626 */
9627
9628 +#include <asm/alternative-asm.h>
9629 +
9630 .file "serpent-avx-x86_64-asm_64.S"
9631 .text
9632
9633 @@ -638,12 +640,14 @@ __serpent_enc_blk_8way_avx:
9634 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9635 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9636
9637 + pax_force_retaddr
9638 ret;
9639
9640 __enc_xor8:
9641 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9642 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9643
9644 + pax_force_retaddr
9645 ret;
9646
9647 .align 8
9648 @@ -701,4 +705,5 @@ serpent_dec_blk_8way_avx:
9649 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
9650 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
9651
9652 + pax_force_retaddr
9653 ret;
9654 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
9655 index 3ee1ff0..cbc568b 100644
9656 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
9657 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
9658 @@ -24,6 +24,8 @@
9659 *
9660 */
9661
9662 +#include <asm/alternative-asm.h>
9663 +
9664 .file "serpent-sse2-x86_64-asm_64.S"
9665 .text
9666
9667 @@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
9668 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9669 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9670
9671 + pax_force_retaddr
9672 ret;
9673
9674 __enc_xor8:
9675 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9676 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9677
9678 + pax_force_retaddr
9679 ret;
9680
9681 .align 8
9682 @@ -755,4 +759,5 @@ serpent_dec_blk_8way:
9683 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
9684 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
9685
9686 + pax_force_retaddr
9687 ret;
9688 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
9689 index 49d6987..df66bd4 100644
9690 --- a/arch/x86/crypto/sha1_ssse3_asm.S
9691 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
9692 @@ -28,6 +28,8 @@
9693 * (at your option) any later version.
9694 */
9695
9696 +#include <asm/alternative-asm.h>
9697 +
9698 #define CTX %rdi // arg1
9699 #define BUF %rsi // arg2
9700 #define CNT %rdx // arg3
9701 @@ -104,6 +106,7 @@
9702 pop %r12
9703 pop %rbp
9704 pop %rbx
9705 + pax_force_retaddr 0, 1
9706 ret
9707
9708 .size \name, .-\name
9709 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
9710 index 1585abb..1ff9d9b 100644
9711 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
9712 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
9713 @@ -23,6 +23,8 @@
9714 *
9715 */
9716
9717 +#include <asm/alternative-asm.h>
9718 +
9719 .file "twofish-avx-x86_64-asm_64.S"
9720 .text
9721
9722 @@ -303,12 +305,14 @@ __twofish_enc_blk_8way:
9723 outunpack_blocks(%r11, RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
9724 outunpack_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
9725
9726 + pax_force_retaddr 0, 1
9727 ret;
9728
9729 __enc_xor8:
9730 outunpack_xor_blocks(%r11, RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
9731 outunpack_xor_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
9732
9733 + pax_force_retaddr 0, 1
9734 ret;
9735
9736 .align 8
9737 @@ -354,4 +358,5 @@ twofish_dec_blk_8way:
9738 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
9739 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
9740
9741 + pax_force_retaddr 0, 1
9742 ret;
9743 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
9744 index 5b012a2..36d5364 100644
9745 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
9746 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
9747 @@ -20,6 +20,8 @@
9748 *
9749 */
9750
9751 +#include <asm/alternative-asm.h>
9752 +
9753 .file "twofish-x86_64-asm-3way.S"
9754 .text
9755
9756 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
9757 popq %r13;
9758 popq %r14;
9759 popq %r15;
9760 + pax_force_retaddr 0, 1
9761 ret;
9762
9763 __enc_xor3:
9764 @@ -271,6 +274,7 @@ __enc_xor3:
9765 popq %r13;
9766 popq %r14;
9767 popq %r15;
9768 + pax_force_retaddr 0, 1
9769 ret;
9770
9771 .global twofish_dec_blk_3way
9772 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
9773 popq %r13;
9774 popq %r14;
9775 popq %r15;
9776 + pax_force_retaddr 0, 1
9777 ret;
9778
9779 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
9780 index 7bcf3fc..f53832f 100644
9781 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
9782 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
9783 @@ -21,6 +21,7 @@
9784 .text
9785
9786 #include <asm/asm-offsets.h>
9787 +#include <asm/alternative-asm.h>
9788
9789 #define a_offset 0
9790 #define b_offset 4
9791 @@ -268,6 +269,7 @@ twofish_enc_blk:
9792
9793 popq R1
9794 movq $1,%rax
9795 + pax_force_retaddr 0, 1
9796 ret
9797
9798 twofish_dec_blk:
9799 @@ -319,4 +321,5 @@ twofish_dec_blk:
9800
9801 popq R1
9802 movq $1,%rax
9803 + pax_force_retaddr 0, 1
9804 ret
9805 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
9806 index 07b3a68..bd2a388 100644
9807 --- a/arch/x86/ia32/ia32_aout.c
9808 +++ b/arch/x86/ia32/ia32_aout.c
9809 @@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
9810 unsigned long dump_start, dump_size;
9811 struct user32 dump;
9812
9813 + memset(&dump, 0, sizeof(dump));
9814 +
9815 fs = get_fs();
9816 set_fs(KERNEL_DS);
9817 has_dumped = 1;
9818 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
9819 index efc6a95..95abfe2 100644
9820 --- a/arch/x86/ia32/ia32_signal.c
9821 +++ b/arch/x86/ia32/ia32_signal.c
9822 @@ -163,8 +163,8 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
9823 }
9824 seg = get_fs();
9825 set_fs(KERNEL_DS);
9826 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
9827 - (stack_t __force __user *) &uoss, regs->sp);
9828 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
9829 + (stack_t __force_user *) &uoss, regs->sp);
9830 set_fs(seg);
9831 if (ret >= 0 && uoss_ptr) {
9832 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
9833 @@ -396,7 +396,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
9834 sp -= frame_size;
9835 /* Align the stack pointer according to the i386 ABI,
9836 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
9837 - sp = ((sp + 4) & -16ul) - 4;
9838 + sp = ((sp - 12) & -16ul) - 4;
9839 return (void __user *) sp;
9840 }
9841
9842 @@ -454,7 +454,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
9843 * These are actually not used anymore, but left because some
9844 * gdb versions depend on them as a marker.
9845 */
9846 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
9847 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
9848 } put_user_catch(err);
9849
9850 if (err)
9851 @@ -496,7 +496,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
9852 0xb8,
9853 __NR_ia32_rt_sigreturn,
9854 0x80cd,
9855 - 0,
9856 + 0
9857 };
9858
9859 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
9860 @@ -522,16 +522,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
9861
9862 if (ka->sa.sa_flags & SA_RESTORER)
9863 restorer = ka->sa.sa_restorer;
9864 + else if (current->mm->context.vdso)
9865 + /* Return stub is in 32bit vsyscall page */
9866 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
9867 else
9868 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
9869 - rt_sigreturn);
9870 + restorer = &frame->retcode;
9871 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
9872
9873 /*
9874 * Not actually used anymore, but left because some gdb
9875 * versions need it.
9876 */
9877 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
9878 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
9879 } put_user_catch(err);
9880
9881 err |= copy_siginfo_to_user32(&frame->info, info);
9882 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
9883 index e7fa545..9e6fe1a 100644
9884 --- a/arch/x86/ia32/ia32entry.S
9885 +++ b/arch/x86/ia32/ia32entry.S
9886 @@ -15,8 +15,10 @@
9887 #include <asm/irqflags.h>
9888 #include <asm/asm.h>
9889 #include <asm/smap.h>
9890 +#include <asm/pgtable.h>
9891 #include <linux/linkage.h>
9892 #include <linux/err.h>
9893 +#include <asm/alternative-asm.h>
9894
9895 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
9896 #include <linux/elf-em.h>
9897 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
9898 ENDPROC(native_irq_enable_sysexit)
9899 #endif
9900
9901 + .macro pax_enter_kernel_user
9902 + pax_set_fptr_mask
9903 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9904 + call pax_enter_kernel_user
9905 +#endif
9906 + .endm
9907 +
9908 + .macro pax_exit_kernel_user
9909 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9910 + call pax_exit_kernel_user
9911 +#endif
9912 +#ifdef CONFIG_PAX_RANDKSTACK
9913 + pushq %rax
9914 + pushq %r11
9915 + call pax_randomize_kstack
9916 + popq %r11
9917 + popq %rax
9918 +#endif
9919 + .endm
9920 +
9921 +.macro pax_erase_kstack
9922 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
9923 + call pax_erase_kstack
9924 +#endif
9925 +.endm
9926 +
9927 /*
9928 * 32bit SYSENTER instruction entry.
9929 *
9930 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
9931 CFI_REGISTER rsp,rbp
9932 SWAPGS_UNSAFE_STACK
9933 movq PER_CPU_VAR(kernel_stack), %rsp
9934 - addq $(KERNEL_STACK_OFFSET),%rsp
9935 - /*
9936 - * No need to follow this irqs on/off section: the syscall
9937 - * disabled irqs, here we enable it straight after entry:
9938 - */
9939 - ENABLE_INTERRUPTS(CLBR_NONE)
9940 movl %ebp,%ebp /* zero extension */
9941 pushq_cfi $__USER32_DS
9942 /*CFI_REL_OFFSET ss,0*/
9943 @@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
9944 CFI_REL_OFFSET rsp,0
9945 pushfq_cfi
9946 /*CFI_REL_OFFSET rflags,0*/
9947 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
9948 - CFI_REGISTER rip,r10
9949 + orl $X86_EFLAGS_IF,(%rsp)
9950 + GET_THREAD_INFO(%r11)
9951 + movl TI_sysenter_return(%r11), %r11d
9952 + CFI_REGISTER rip,r11
9953 pushq_cfi $__USER32_CS
9954 /*CFI_REL_OFFSET cs,0*/
9955 movl %eax, %eax
9956 - pushq_cfi %r10
9957 + pushq_cfi %r11
9958 CFI_REL_OFFSET rip,0
9959 pushq_cfi %rax
9960 cld
9961 SAVE_ARGS 0,1,0
9962 + pax_enter_kernel_user
9963 +
9964 +#ifdef CONFIG_PAX_RANDKSTACK
9965 + pax_erase_kstack
9966 +#endif
9967 +
9968 + /*
9969 + * No need to follow this irqs on/off section: the syscall
9970 + * disabled irqs, here we enable it straight after entry:
9971 + */
9972 + ENABLE_INTERRUPTS(CLBR_NONE)
9973 /* no need to do an access_ok check here because rbp has been
9974 32bit zero extended */
9975 +
9976 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9977 + mov $PAX_USER_SHADOW_BASE,%r11
9978 + add %r11,%rbp
9979 +#endif
9980 +
9981 ASM_STAC
9982 1: movl (%rbp),%ebp
9983 _ASM_EXTABLE(1b,ia32_badarg)
9984 ASM_CLAC
9985 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9986 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9987 + GET_THREAD_INFO(%r11)
9988 + orl $TS_COMPAT,TI_status(%r11)
9989 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
9990 CFI_REMEMBER_STATE
9991 jnz sysenter_tracesys
9992 cmpq $(IA32_NR_syscalls-1),%rax
9993 @@ -162,12 +204,15 @@ sysenter_do_call:
9994 sysenter_dispatch:
9995 call *ia32_sys_call_table(,%rax,8)
9996 movq %rax,RAX-ARGOFFSET(%rsp)
9997 + GET_THREAD_INFO(%r11)
9998 DISABLE_INTERRUPTS(CLBR_NONE)
9999 TRACE_IRQS_OFF
10000 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10001 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
10002 jnz sysexit_audit
10003 sysexit_from_sys_call:
10004 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10005 + pax_exit_kernel_user
10006 + pax_erase_kstack
10007 + andl $~TS_COMPAT,TI_status(%r11)
10008 /* clear IF, that popfq doesn't enable interrupts early */
10009 andl $~0x200,EFLAGS-R11(%rsp)
10010 movl RIP-R11(%rsp),%edx /* User %eip */
10011 @@ -193,6 +238,9 @@ sysexit_from_sys_call:
10012 movl %eax,%esi /* 2nd arg: syscall number */
10013 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
10014 call __audit_syscall_entry
10015 +
10016 + pax_erase_kstack
10017 +
10018 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
10019 cmpq $(IA32_NR_syscalls-1),%rax
10020 ja ia32_badsys
10021 @@ -204,7 +252,7 @@ sysexit_from_sys_call:
10022 .endm
10023
10024 .macro auditsys_exit exit
10025 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10026 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
10027 jnz ia32_ret_from_sys_call
10028 TRACE_IRQS_ON
10029 ENABLE_INTERRUPTS(CLBR_NONE)
10030 @@ -215,11 +263,12 @@ sysexit_from_sys_call:
10031 1: setbe %al /* 1 if error, 0 if not */
10032 movzbl %al,%edi /* zero-extend that into %edi */
10033 call __audit_syscall_exit
10034 + GET_THREAD_INFO(%r11)
10035 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
10036 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
10037 DISABLE_INTERRUPTS(CLBR_NONE)
10038 TRACE_IRQS_OFF
10039 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10040 + testl %edi,TI_flags(%r11)
10041 jz \exit
10042 CLEAR_RREGS -ARGOFFSET
10043 jmp int_with_check
10044 @@ -237,7 +286,7 @@ sysexit_audit:
10045
10046 sysenter_tracesys:
10047 #ifdef CONFIG_AUDITSYSCALL
10048 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10049 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
10050 jz sysenter_auditsys
10051 #endif
10052 SAVE_REST
10053 @@ -249,6 +298,9 @@ sysenter_tracesys:
10054 RESTORE_REST
10055 cmpq $(IA32_NR_syscalls-1),%rax
10056 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
10057 +
10058 + pax_erase_kstack
10059 +
10060 jmp sysenter_do_call
10061 CFI_ENDPROC
10062 ENDPROC(ia32_sysenter_target)
10063 @@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
10064 ENTRY(ia32_cstar_target)
10065 CFI_STARTPROC32 simple
10066 CFI_SIGNAL_FRAME
10067 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
10068 + CFI_DEF_CFA rsp,0
10069 CFI_REGISTER rip,rcx
10070 /*CFI_REGISTER rflags,r11*/
10071 SWAPGS_UNSAFE_STACK
10072 movl %esp,%r8d
10073 CFI_REGISTER rsp,r8
10074 movq PER_CPU_VAR(kernel_stack),%rsp
10075 + SAVE_ARGS 8*6,0,0
10076 + pax_enter_kernel_user
10077 +
10078 +#ifdef CONFIG_PAX_RANDKSTACK
10079 + pax_erase_kstack
10080 +#endif
10081 +
10082 /*
10083 * No need to follow this irqs on/off section: the syscall
10084 * disabled irqs and here we enable it straight after entry:
10085 */
10086 ENABLE_INTERRUPTS(CLBR_NONE)
10087 - SAVE_ARGS 8,0,0
10088 movl %eax,%eax /* zero extension */
10089 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
10090 movq %rcx,RIP-ARGOFFSET(%rsp)
10091 @@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
10092 /* no need to do an access_ok check here because r8 has been
10093 32bit zero extended */
10094 /* hardware stack frame is complete now */
10095 +
10096 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10097 + mov $PAX_USER_SHADOW_BASE,%r11
10098 + add %r11,%r8
10099 +#endif
10100 +
10101 ASM_STAC
10102 1: movl (%r8),%r9d
10103 _ASM_EXTABLE(1b,ia32_badarg)
10104 ASM_CLAC
10105 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10106 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10107 + GET_THREAD_INFO(%r11)
10108 + orl $TS_COMPAT,TI_status(%r11)
10109 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
10110 CFI_REMEMBER_STATE
10111 jnz cstar_tracesys
10112 cmpq $IA32_NR_syscalls-1,%rax
10113 @@ -319,12 +384,15 @@ cstar_do_call:
10114 cstar_dispatch:
10115 call *ia32_sys_call_table(,%rax,8)
10116 movq %rax,RAX-ARGOFFSET(%rsp)
10117 + GET_THREAD_INFO(%r11)
10118 DISABLE_INTERRUPTS(CLBR_NONE)
10119 TRACE_IRQS_OFF
10120 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10121 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
10122 jnz sysretl_audit
10123 sysretl_from_sys_call:
10124 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10125 + pax_exit_kernel_user
10126 + pax_erase_kstack
10127 + andl $~TS_COMPAT,TI_status(%r11)
10128 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
10129 movl RIP-ARGOFFSET(%rsp),%ecx
10130 CFI_REGISTER rip,rcx
10131 @@ -352,7 +420,7 @@ sysretl_audit:
10132
10133 cstar_tracesys:
10134 #ifdef CONFIG_AUDITSYSCALL
10135 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10136 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
10137 jz cstar_auditsys
10138 #endif
10139 xchgl %r9d,%ebp
10140 @@ -366,6 +434,9 @@ cstar_tracesys:
10141 xchgl %ebp,%r9d
10142 cmpq $(IA32_NR_syscalls-1),%rax
10143 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
10144 +
10145 + pax_erase_kstack
10146 +
10147 jmp cstar_do_call
10148 END(ia32_cstar_target)
10149
10150 @@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
10151 CFI_REL_OFFSET rip,RIP-RIP
10152 PARAVIRT_ADJUST_EXCEPTION_FRAME
10153 SWAPGS
10154 - /*
10155 - * No need to follow this irqs on/off section: the syscall
10156 - * disabled irqs and here we enable it straight after entry:
10157 - */
10158 - ENABLE_INTERRUPTS(CLBR_NONE)
10159 movl %eax,%eax
10160 pushq_cfi %rax
10161 cld
10162 /* note the registers are not zero extended to the sf.
10163 this could be a problem. */
10164 SAVE_ARGS 0,1,0
10165 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10166 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10167 + pax_enter_kernel_user
10168 +
10169 +#ifdef CONFIG_PAX_RANDKSTACK
10170 + pax_erase_kstack
10171 +#endif
10172 +
10173 + /*
10174 + * No need to follow this irqs on/off section: the syscall
10175 + * disabled irqs and here we enable it straight after entry:
10176 + */
10177 + ENABLE_INTERRUPTS(CLBR_NONE)
10178 + GET_THREAD_INFO(%r11)
10179 + orl $TS_COMPAT,TI_status(%r11)
10180 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
10181 jnz ia32_tracesys
10182 cmpq $(IA32_NR_syscalls-1),%rax
10183 ja ia32_badsys
10184 @@ -442,6 +520,9 @@ ia32_tracesys:
10185 RESTORE_REST
10186 cmpq $(IA32_NR_syscalls-1),%rax
10187 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
10188 +
10189 + pax_erase_kstack
10190 +
10191 jmp ia32_do_call
10192 END(ia32_syscall)
10193
10194 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
10195 index 86d68d1..f9960fe 100644
10196 --- a/arch/x86/ia32/sys_ia32.c
10197 +++ b/arch/x86/ia32/sys_ia32.c
10198 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
10199 */
10200 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
10201 {
10202 - typeof(ubuf->st_uid) uid = 0;
10203 - typeof(ubuf->st_gid) gid = 0;
10204 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
10205 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
10206 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
10207 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
10208 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
10209 @@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
10210 mm_segment_t old_fs = get_fs();
10211
10212 set_fs(KERNEL_DS);
10213 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
10214 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
10215 set_fs(old_fs);
10216 if (put_compat_timespec(&t, interval))
10217 return -EFAULT;
10218 @@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
10219 mm_segment_t old_fs = get_fs();
10220
10221 set_fs(KERNEL_DS);
10222 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
10223 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
10224 set_fs(old_fs);
10225 if (!ret) {
10226 switch (_NSIG_WORDS) {
10227 @@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
10228 if (copy_siginfo_from_user32(&info, uinfo))
10229 return -EFAULT;
10230 set_fs(KERNEL_DS);
10231 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
10232 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
10233 set_fs(old_fs);
10234 return ret;
10235 }
10236 @@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
10237 return -EFAULT;
10238
10239 set_fs(KERNEL_DS);
10240 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
10241 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
10242 count);
10243 set_fs(old_fs);
10244
10245 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
10246 index 372231c..a5aa1a1 100644
10247 --- a/arch/x86/include/asm/alternative-asm.h
10248 +++ b/arch/x86/include/asm/alternative-asm.h
10249 @@ -18,6 +18,45 @@
10250 .endm
10251 #endif
10252
10253 +#ifdef KERNEXEC_PLUGIN
10254 + .macro pax_force_retaddr_bts rip=0
10255 + btsq $63,\rip(%rsp)
10256 + .endm
10257 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
10258 + .macro pax_force_retaddr rip=0, reload=0
10259 + btsq $63,\rip(%rsp)
10260 + .endm
10261 + .macro pax_force_fptr ptr
10262 + btsq $63,\ptr
10263 + .endm
10264 + .macro pax_set_fptr_mask
10265 + .endm
10266 +#endif
10267 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
10268 + .macro pax_force_retaddr rip=0, reload=0
10269 + .if \reload
10270 + pax_set_fptr_mask
10271 + .endif
10272 + orq %r10,\rip(%rsp)
10273 + .endm
10274 + .macro pax_force_fptr ptr
10275 + orq %r10,\ptr
10276 + .endm
10277 + .macro pax_set_fptr_mask
10278 + movabs $0x8000000000000000,%r10
10279 + .endm
10280 +#endif
10281 +#else
10282 + .macro pax_force_retaddr rip=0, reload=0
10283 + .endm
10284 + .macro pax_force_fptr ptr
10285 + .endm
10286 + .macro pax_force_retaddr_bts rip=0
10287 + .endm
10288 + .macro pax_set_fptr_mask
10289 + .endm
10290 +#endif
10291 +
10292 .macro altinstruction_entry orig alt feature orig_len alt_len
10293 .long \orig - .
10294 .long \alt - .
10295 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
10296 index 58ed6d9..f1cbe58 100644
10297 --- a/arch/x86/include/asm/alternative.h
10298 +++ b/arch/x86/include/asm/alternative.h
10299 @@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
10300 ".pushsection .discard,\"aw\",@progbits\n" \
10301 DISCARD_ENTRY(1) \
10302 ".popsection\n" \
10303 - ".pushsection .altinstr_replacement, \"ax\"\n" \
10304 + ".pushsection .altinstr_replacement, \"a\"\n" \
10305 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
10306 ".popsection"
10307
10308 @@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
10309 DISCARD_ENTRY(1) \
10310 DISCARD_ENTRY(2) \
10311 ".popsection\n" \
10312 - ".pushsection .altinstr_replacement, \"ax\"\n" \
10313 + ".pushsection .altinstr_replacement, \"a\"\n" \
10314 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
10315 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
10316 ".popsection"
10317 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
10318 index 3388034..ba52312 100644
10319 --- a/arch/x86/include/asm/apic.h
10320 +++ b/arch/x86/include/asm/apic.h
10321 @@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
10322
10323 #ifdef CONFIG_X86_LOCAL_APIC
10324
10325 -extern unsigned int apic_verbosity;
10326 +extern int apic_verbosity;
10327 extern int local_apic_timer_c2_ok;
10328
10329 extern int disable_apic;
10330 @@ -391,7 +391,7 @@ struct apic {
10331 */
10332 int (*x86_32_numa_cpu_node)(int cpu);
10333 #endif
10334 -};
10335 +} __do_const;
10336
10337 /*
10338 * Pointer to the local APIC driver in use on this system (there's
10339 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
10340 index 20370c6..a2eb9b0 100644
10341 --- a/arch/x86/include/asm/apm.h
10342 +++ b/arch/x86/include/asm/apm.h
10343 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
10344 __asm__ __volatile__(APM_DO_ZERO_SEGS
10345 "pushl %%edi\n\t"
10346 "pushl %%ebp\n\t"
10347 - "lcall *%%cs:apm_bios_entry\n\t"
10348 + "lcall *%%ss:apm_bios_entry\n\t"
10349 "setc %%al\n\t"
10350 "popl %%ebp\n\t"
10351 "popl %%edi\n\t"
10352 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
10353 __asm__ __volatile__(APM_DO_ZERO_SEGS
10354 "pushl %%edi\n\t"
10355 "pushl %%ebp\n\t"
10356 - "lcall *%%cs:apm_bios_entry\n\t"
10357 + "lcall *%%ss:apm_bios_entry\n\t"
10358 "setc %%bl\n\t"
10359 "popl %%ebp\n\t"
10360 "popl %%edi\n\t"
10361 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
10362 index b6c3b82..b4c077a 100644
10363 --- a/arch/x86/include/asm/atomic.h
10364 +++ b/arch/x86/include/asm/atomic.h
10365 @@ -22,7 +22,18 @@
10366 */
10367 static inline int atomic_read(const atomic_t *v)
10368 {
10369 - return (*(volatile int *)&(v)->counter);
10370 + return (*(volatile const int *)&(v)->counter);
10371 +}
10372 +
10373 +/**
10374 + * atomic_read_unchecked - read atomic variable
10375 + * @v: pointer of type atomic_unchecked_t
10376 + *
10377 + * Atomically reads the value of @v.
10378 + */
10379 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
10380 +{
10381 + return (*(volatile const int *)&(v)->counter);
10382 }
10383
10384 /**
10385 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
10386 }
10387
10388 /**
10389 + * atomic_set_unchecked - set atomic variable
10390 + * @v: pointer of type atomic_unchecked_t
10391 + * @i: required value
10392 + *
10393 + * Atomically sets the value of @v to @i.
10394 + */
10395 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
10396 +{
10397 + v->counter = i;
10398 +}
10399 +
10400 +/**
10401 * atomic_add - add integer to atomic variable
10402 * @i: integer value to add
10403 * @v: pointer of type atomic_t
10404 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
10405 */
10406 static inline void atomic_add(int i, atomic_t *v)
10407 {
10408 - asm volatile(LOCK_PREFIX "addl %1,%0"
10409 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
10410 +
10411 +#ifdef CONFIG_PAX_REFCOUNT
10412 + "jno 0f\n"
10413 + LOCK_PREFIX "subl %1,%0\n"
10414 + "int $4\n0:\n"
10415 + _ASM_EXTABLE(0b, 0b)
10416 +#endif
10417 +
10418 + : "+m" (v->counter)
10419 + : "ir" (i));
10420 +}
10421 +
10422 +/**
10423 + * atomic_add_unchecked - add integer to atomic variable
10424 + * @i: integer value to add
10425 + * @v: pointer of type atomic_unchecked_t
10426 + *
10427 + * Atomically adds @i to @v.
10428 + */
10429 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
10430 +{
10431 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
10432 : "+m" (v->counter)
10433 : "ir" (i));
10434 }
10435 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
10436 */
10437 static inline void atomic_sub(int i, atomic_t *v)
10438 {
10439 - asm volatile(LOCK_PREFIX "subl %1,%0"
10440 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
10441 +
10442 +#ifdef CONFIG_PAX_REFCOUNT
10443 + "jno 0f\n"
10444 + LOCK_PREFIX "addl %1,%0\n"
10445 + "int $4\n0:\n"
10446 + _ASM_EXTABLE(0b, 0b)
10447 +#endif
10448 +
10449 + : "+m" (v->counter)
10450 + : "ir" (i));
10451 +}
10452 +
10453 +/**
10454 + * atomic_sub_unchecked - subtract integer from atomic variable
10455 + * @i: integer value to subtract
10456 + * @v: pointer of type atomic_unchecked_t
10457 + *
10458 + * Atomically subtracts @i from @v.
10459 + */
10460 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
10461 +{
10462 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
10463 : "+m" (v->counter)
10464 : "ir" (i));
10465 }
10466 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
10467 {
10468 unsigned char c;
10469
10470 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
10471 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
10472 +
10473 +#ifdef CONFIG_PAX_REFCOUNT
10474 + "jno 0f\n"
10475 + LOCK_PREFIX "addl %2,%0\n"
10476 + "int $4\n0:\n"
10477 + _ASM_EXTABLE(0b, 0b)
10478 +#endif
10479 +
10480 + "sete %1\n"
10481 : "+m" (v->counter), "=qm" (c)
10482 : "ir" (i) : "memory");
10483 return c;
10484 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
10485 */
10486 static inline void atomic_inc(atomic_t *v)
10487 {
10488 - asm volatile(LOCK_PREFIX "incl %0"
10489 + asm volatile(LOCK_PREFIX "incl %0\n"
10490 +
10491 +#ifdef CONFIG_PAX_REFCOUNT
10492 + "jno 0f\n"
10493 + LOCK_PREFIX "decl %0\n"
10494 + "int $4\n0:\n"
10495 + _ASM_EXTABLE(0b, 0b)
10496 +#endif
10497 +
10498 + : "+m" (v->counter));
10499 +}
10500 +
10501 +/**
10502 + * atomic_inc_unchecked - increment atomic variable
10503 + * @v: pointer of type atomic_unchecked_t
10504 + *
10505 + * Atomically increments @v by 1.
10506 + */
10507 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
10508 +{
10509 + asm volatile(LOCK_PREFIX "incl %0\n"
10510 : "+m" (v->counter));
10511 }
10512
10513 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
10514 */
10515 static inline void atomic_dec(atomic_t *v)
10516 {
10517 - asm volatile(LOCK_PREFIX "decl %0"
10518 + asm volatile(LOCK_PREFIX "decl %0\n"
10519 +
10520 +#ifdef CONFIG_PAX_REFCOUNT
10521 + "jno 0f\n"
10522 + LOCK_PREFIX "incl %0\n"
10523 + "int $4\n0:\n"
10524 + _ASM_EXTABLE(0b, 0b)
10525 +#endif
10526 +
10527 + : "+m" (v->counter));
10528 +}
10529 +
10530 +/**
10531 + * atomic_dec_unchecked - decrement atomic variable
10532 + * @v: pointer of type atomic_unchecked_t
10533 + *
10534 + * Atomically decrements @v by 1.
10535 + */
10536 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
10537 +{
10538 + asm volatile(LOCK_PREFIX "decl %0\n"
10539 : "+m" (v->counter));
10540 }
10541
10542 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
10543 {
10544 unsigned char c;
10545
10546 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
10547 + asm volatile(LOCK_PREFIX "decl %0\n"
10548 +
10549 +#ifdef CONFIG_PAX_REFCOUNT
10550 + "jno 0f\n"
10551 + LOCK_PREFIX "incl %0\n"
10552 + "int $4\n0:\n"
10553 + _ASM_EXTABLE(0b, 0b)
10554 +#endif
10555 +
10556 + "sete %1\n"
10557 : "+m" (v->counter), "=qm" (c)
10558 : : "memory");
10559 return c != 0;
10560 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
10561 {
10562 unsigned char c;
10563
10564 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
10565 + asm volatile(LOCK_PREFIX "incl %0\n"
10566 +
10567 +#ifdef CONFIG_PAX_REFCOUNT
10568 + "jno 0f\n"
10569 + LOCK_PREFIX "decl %0\n"
10570 + "int $4\n0:\n"
10571 + _ASM_EXTABLE(0b, 0b)
10572 +#endif
10573 +
10574 + "sete %1\n"
10575 + : "+m" (v->counter), "=qm" (c)
10576 + : : "memory");
10577 + return c != 0;
10578 +}
10579 +
10580 +/**
10581 + * atomic_inc_and_test_unchecked - increment and test
10582 + * @v: pointer of type atomic_unchecked_t
10583 + *
10584 + * Atomically increments @v by 1
10585 + * and returns true if the result is zero, or false for all
10586 + * other cases.
10587 + */
10588 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
10589 +{
10590 + unsigned char c;
10591 +
10592 + asm volatile(LOCK_PREFIX "incl %0\n"
10593 + "sete %1\n"
10594 : "+m" (v->counter), "=qm" (c)
10595 : : "memory");
10596 return c != 0;
10597 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
10598 {
10599 unsigned char c;
10600
10601 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
10602 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
10603 +
10604 +#ifdef CONFIG_PAX_REFCOUNT
10605 + "jno 0f\n"
10606 + LOCK_PREFIX "subl %2,%0\n"
10607 + "int $4\n0:\n"
10608 + _ASM_EXTABLE(0b, 0b)
10609 +#endif
10610 +
10611 + "sets %1\n"
10612 : "+m" (v->counter), "=qm" (c)
10613 : "ir" (i) : "memory");
10614 return c;
10615 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
10616 goto no_xadd;
10617 #endif
10618 /* Modern 486+ processor */
10619 - return i + xadd(&v->counter, i);
10620 + return i + xadd_check_overflow(&v->counter, i);
10621
10622 #ifdef CONFIG_M386
10623 no_xadd: /* Legacy 386 processor */
10624 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
10625 }
10626
10627 /**
10628 + * atomic_add_return_unchecked - add integer and return
10629 + * @i: integer value to add
10630 + * @v: pointer of type atomic_unchecked_t
10631 + *
10632 + * Atomically adds @i to @v and returns @i + @v
10633 + */
10634 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
10635 +{
10636 +#ifdef CONFIG_M386
10637 + int __i;
10638 + unsigned long flags;
10639 + if (unlikely(boot_cpu_data.x86 <= 3))
10640 + goto no_xadd;
10641 +#endif
10642 + /* Modern 486+ processor */
10643 + return i + xadd(&v->counter, i);
10644 +
10645 +#ifdef CONFIG_M386
10646 +no_xadd: /* Legacy 386 processor */
10647 + raw_local_irq_save(flags);
10648 + __i = atomic_read_unchecked(v);
10649 + atomic_set_unchecked(v, i + __i);
10650 + raw_local_irq_restore(flags);
10651 + return i + __i;
10652 +#endif
10653 +}
10654 +
10655 +/**
10656 * atomic_sub_return - subtract integer and return
10657 * @v: pointer of type atomic_t
10658 * @i: integer value to subtract
10659 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
10660 }
10661
10662 #define atomic_inc_return(v) (atomic_add_return(1, v))
10663 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
10664 +{
10665 + return atomic_add_return_unchecked(1, v);
10666 +}
10667 #define atomic_dec_return(v) (atomic_sub_return(1, v))
10668
10669 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
10670 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
10671 return cmpxchg(&v->counter, old, new);
10672 }
10673
10674 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
10675 +{
10676 + return cmpxchg(&v->counter, old, new);
10677 +}
10678 +
10679 static inline int atomic_xchg(atomic_t *v, int new)
10680 {
10681 return xchg(&v->counter, new);
10682 }
10683
10684 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
10685 +{
10686 + return xchg(&v->counter, new);
10687 +}
10688 +
10689 /**
10690 * __atomic_add_unless - add unless the number is already a given value
10691 * @v: pointer of type atomic_t
10692 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
10693 */
10694 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10695 {
10696 - int c, old;
10697 + int c, old, new;
10698 c = atomic_read(v);
10699 for (;;) {
10700 - if (unlikely(c == (u)))
10701 + if (unlikely(c == u))
10702 break;
10703 - old = atomic_cmpxchg((v), c, c + (a));
10704 +
10705 + asm volatile("addl %2,%0\n"
10706 +
10707 +#ifdef CONFIG_PAX_REFCOUNT
10708 + "jno 0f\n"
10709 + "subl %2,%0\n"
10710 + "int $4\n0:\n"
10711 + _ASM_EXTABLE(0b, 0b)
10712 +#endif
10713 +
10714 + : "=r" (new)
10715 + : "0" (c), "ir" (a));
10716 +
10717 + old = atomic_cmpxchg(v, c, new);
10718 if (likely(old == c))
10719 break;
10720 c = old;
10721 @@ -241,6 +458,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10722 }
10723
10724 /**
10725 + * atomic_inc_not_zero_hint - increment if not null
10726 + * @v: pointer of type atomic_t
10727 + * @hint: probable value of the atomic before the increment
10728 + *
10729 + * This version of atomic_inc_not_zero() gives a hint of probable
10730 + * value of the atomic. This helps processor to not read the memory
10731 + * before doing the atomic read/modify/write cycle, lowering
10732 + * number of bus transactions on some arches.
10733 + *
10734 + * Returns: 0 if increment was not done, 1 otherwise.
10735 + */
10736 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
10737 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
10738 +{
10739 + int val, c = hint, new;
10740 +
10741 + /* sanity test, should be removed by compiler if hint is a constant */
10742 + if (!hint)
10743 + return __atomic_add_unless(v, 1, 0);
10744 +
10745 + do {
10746 + asm volatile("incl %0\n"
10747 +
10748 +#ifdef CONFIG_PAX_REFCOUNT
10749 + "jno 0f\n"
10750 + "decl %0\n"
10751 + "int $4\n0:\n"
10752 + _ASM_EXTABLE(0b, 0b)
10753 +#endif
10754 +
10755 + : "=r" (new)
10756 + : "0" (c));
10757 +
10758 + val = atomic_cmpxchg(v, c, new);
10759 + if (val == c)
10760 + return 1;
10761 + c = val;
10762 + } while (c);
10763 +
10764 + return 0;
10765 +}
10766 +
10767 +/**
10768 * atomic_inc_short - increment of a short integer
10769 * @v: pointer to type int
10770 *
10771 @@ -269,14 +529,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
10772 #endif
10773
10774 /* These are x86-specific, used by some header files */
10775 -#define atomic_clear_mask(mask, addr) \
10776 - asm volatile(LOCK_PREFIX "andl %0,%1" \
10777 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
10778 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
10779 +{
10780 + asm volatile(LOCK_PREFIX "andl %1,%0"
10781 + : "+m" (v->counter)
10782 + : "r" (~(mask))
10783 + : "memory");
10784 +}
10785
10786 -#define atomic_set_mask(mask, addr) \
10787 - asm volatile(LOCK_PREFIX "orl %0,%1" \
10788 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
10789 - : "memory")
10790 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
10791 +{
10792 + asm volatile(LOCK_PREFIX "andl %1,%0"
10793 + : "+m" (v->counter)
10794 + : "r" (~(mask))
10795 + : "memory");
10796 +}
10797 +
10798 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
10799 +{
10800 + asm volatile(LOCK_PREFIX "orl %1,%0"
10801 + : "+m" (v->counter)
10802 + : "r" (mask)
10803 + : "memory");
10804 +}
10805 +
10806 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
10807 +{
10808 + asm volatile(LOCK_PREFIX "orl %1,%0"
10809 + : "+m" (v->counter)
10810 + : "r" (mask)
10811 + : "memory");
10812 +}
10813
10814 /* Atomic operations are already serializing on x86 */
10815 #define smp_mb__before_atomic_dec() barrier()
10816 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
10817 index b154de7..aadebd8 100644
10818 --- a/arch/x86/include/asm/atomic64_32.h
10819 +++ b/arch/x86/include/asm/atomic64_32.h
10820 @@ -12,6 +12,14 @@ typedef struct {
10821 u64 __aligned(8) counter;
10822 } atomic64_t;
10823
10824 +#ifdef CONFIG_PAX_REFCOUNT
10825 +typedef struct {
10826 + u64 __aligned(8) counter;
10827 +} atomic64_unchecked_t;
10828 +#else
10829 +typedef atomic64_t atomic64_unchecked_t;
10830 +#endif
10831 +
10832 #define ATOMIC64_INIT(val) { (val) }
10833
10834 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
10835 @@ -37,21 +45,31 @@ typedef struct {
10836 ATOMIC64_DECL_ONE(sym##_386)
10837
10838 ATOMIC64_DECL_ONE(add_386);
10839 +ATOMIC64_DECL_ONE(add_unchecked_386);
10840 ATOMIC64_DECL_ONE(sub_386);
10841 +ATOMIC64_DECL_ONE(sub_unchecked_386);
10842 ATOMIC64_DECL_ONE(inc_386);
10843 +ATOMIC64_DECL_ONE(inc_unchecked_386);
10844 ATOMIC64_DECL_ONE(dec_386);
10845 +ATOMIC64_DECL_ONE(dec_unchecked_386);
10846 #endif
10847
10848 #define alternative_atomic64(f, out, in...) \
10849 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
10850
10851 ATOMIC64_DECL(read);
10852 +ATOMIC64_DECL(read_unchecked);
10853 ATOMIC64_DECL(set);
10854 +ATOMIC64_DECL(set_unchecked);
10855 ATOMIC64_DECL(xchg);
10856 ATOMIC64_DECL(add_return);
10857 +ATOMIC64_DECL(add_return_unchecked);
10858 ATOMIC64_DECL(sub_return);
10859 +ATOMIC64_DECL(sub_return_unchecked);
10860 ATOMIC64_DECL(inc_return);
10861 +ATOMIC64_DECL(inc_return_unchecked);
10862 ATOMIC64_DECL(dec_return);
10863 +ATOMIC64_DECL(dec_return_unchecked);
10864 ATOMIC64_DECL(dec_if_positive);
10865 ATOMIC64_DECL(inc_not_zero);
10866 ATOMIC64_DECL(add_unless);
10867 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
10868 }
10869
10870 /**
10871 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
10872 + * @p: pointer to type atomic64_unchecked_t
10873 + * @o: expected value
10874 + * @n: new value
10875 + *
10876 + * Atomically sets @v to @n if it was equal to @o and returns
10877 + * the old value.
10878 + */
10879 +
10880 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
10881 +{
10882 + return cmpxchg64(&v->counter, o, n);
10883 +}
10884 +
10885 +/**
10886 * atomic64_xchg - xchg atomic64 variable
10887 * @v: pointer to type atomic64_t
10888 * @n: value to assign
10889 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
10890 }
10891
10892 /**
10893 + * atomic64_set_unchecked - set atomic64 variable
10894 + * @v: pointer to type atomic64_unchecked_t
10895 + * @n: value to assign
10896 + *
10897 + * Atomically sets the value of @v to @n.
10898 + */
10899 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
10900 +{
10901 + unsigned high = (unsigned)(i >> 32);
10902 + unsigned low = (unsigned)i;
10903 + alternative_atomic64(set, /* no output */,
10904 + "S" (v), "b" (low), "c" (high)
10905 + : "eax", "edx", "memory");
10906 +}
10907 +
10908 +/**
10909 * atomic64_read - read atomic64 variable
10910 * @v: pointer to type atomic64_t
10911 *
10912 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
10913 }
10914
10915 /**
10916 + * atomic64_read_unchecked - read atomic64 variable
10917 + * @v: pointer to type atomic64_unchecked_t
10918 + *
10919 + * Atomically reads the value of @v and returns it.
10920 + */
10921 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
10922 +{
10923 + long long r;
10924 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
10925 + return r;
10926 + }
10927 +
10928 +/**
10929 * atomic64_add_return - add and return
10930 * @i: integer value to add
10931 * @v: pointer to type atomic64_t
10932 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
10933 return i;
10934 }
10935
10936 +/**
10937 + * atomic64_add_return_unchecked - add and return
10938 + * @i: integer value to add
10939 + * @v: pointer to type atomic64_unchecked_t
10940 + *
10941 + * Atomically adds @i to @v and returns @i + *@v
10942 + */
10943 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
10944 +{
10945 + alternative_atomic64(add_return_unchecked,
10946 + ASM_OUTPUT2("+A" (i), "+c" (v)),
10947 + ASM_NO_INPUT_CLOBBER("memory"));
10948 + return i;
10949 +}
10950 +
10951 /*
10952 * Other variants with different arithmetic operators:
10953 */
10954 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
10955 return a;
10956 }
10957
10958 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10959 +{
10960 + long long a;
10961 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
10962 + "S" (v) : "memory", "ecx");
10963 + return a;
10964 +}
10965 +
10966 static inline long long atomic64_dec_return(atomic64_t *v)
10967 {
10968 long long a;
10969 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
10970 }
10971
10972 /**
10973 + * atomic64_add_unchecked - add integer to atomic64 variable
10974 + * @i: integer value to add
10975 + * @v: pointer to type atomic64_unchecked_t
10976 + *
10977 + * Atomically adds @i to @v.
10978 + */
10979 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
10980 +{
10981 + __alternative_atomic64(add_unchecked, add_return_unchecked,
10982 + ASM_OUTPUT2("+A" (i), "+c" (v)),
10983 + ASM_NO_INPUT_CLOBBER("memory"));
10984 + return i;
10985 +}
10986 +
10987 +/**
10988 * atomic64_sub - subtract the atomic64 variable
10989 * @i: integer value to subtract
10990 * @v: pointer to type atomic64_t
10991 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
10992 index 0e1cbfc..5623683 100644
10993 --- a/arch/x86/include/asm/atomic64_64.h
10994 +++ b/arch/x86/include/asm/atomic64_64.h
10995 @@ -18,7 +18,19 @@
10996 */
10997 static inline long atomic64_read(const atomic64_t *v)
10998 {
10999 - return (*(volatile long *)&(v)->counter);
11000 + return (*(volatile const long *)&(v)->counter);
11001 +}
11002 +
11003 +/**
11004 + * atomic64_read_unchecked - read atomic64 variable
11005 + * @v: pointer of type atomic64_unchecked_t
11006 + *
11007 + * Atomically reads the value of @v.
11008 + * Doesn't imply a read memory barrier.
11009 + */
11010 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
11011 +{
11012 + return (*(volatile const long *)&(v)->counter);
11013 }
11014
11015 /**
11016 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
11017 }
11018
11019 /**
11020 + * atomic64_set_unchecked - set atomic64 variable
11021 + * @v: pointer to type atomic64_unchecked_t
11022 + * @i: required value
11023 + *
11024 + * Atomically sets the value of @v to @i.
11025 + */
11026 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
11027 +{
11028 + v->counter = i;
11029 +}
11030 +
11031 +/**
11032 * atomic64_add - add integer to atomic64 variable
11033 * @i: integer value to add
11034 * @v: pointer to type atomic64_t
11035 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
11036 */
11037 static inline void atomic64_add(long i, atomic64_t *v)
11038 {
11039 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
11040 +
11041 +#ifdef CONFIG_PAX_REFCOUNT
11042 + "jno 0f\n"
11043 + LOCK_PREFIX "subq %1,%0\n"
11044 + "int $4\n0:\n"
11045 + _ASM_EXTABLE(0b, 0b)
11046 +#endif
11047 +
11048 + : "=m" (v->counter)
11049 + : "er" (i), "m" (v->counter));
11050 +}
11051 +
11052 +/**
11053 + * atomic64_add_unchecked - add integer to atomic64 variable
11054 + * @i: integer value to add
11055 + * @v: pointer to type atomic64_unchecked_t
11056 + *
11057 + * Atomically adds @i to @v.
11058 + */
11059 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
11060 +{
11061 asm volatile(LOCK_PREFIX "addq %1,%0"
11062 : "=m" (v->counter)
11063 : "er" (i), "m" (v->counter));
11064 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
11065 */
11066 static inline void atomic64_sub(long i, atomic64_t *v)
11067 {
11068 - asm volatile(LOCK_PREFIX "subq %1,%0"
11069 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
11070 +
11071 +#ifdef CONFIG_PAX_REFCOUNT
11072 + "jno 0f\n"
11073 + LOCK_PREFIX "addq %1,%0\n"
11074 + "int $4\n0:\n"
11075 + _ASM_EXTABLE(0b, 0b)
11076 +#endif
11077 +
11078 + : "=m" (v->counter)
11079 + : "er" (i), "m" (v->counter));
11080 +}
11081 +
11082 +/**
11083 + * atomic64_sub_unchecked - subtract the atomic64 variable
11084 + * @i: integer value to subtract
11085 + * @v: pointer to type atomic64_unchecked_t
11086 + *
11087 + * Atomically subtracts @i from @v.
11088 + */
11089 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
11090 +{
11091 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
11092 : "=m" (v->counter)
11093 : "er" (i), "m" (v->counter));
11094 }
11095 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
11096 {
11097 unsigned char c;
11098
11099 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
11100 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
11101 +
11102 +#ifdef CONFIG_PAX_REFCOUNT
11103 + "jno 0f\n"
11104 + LOCK_PREFIX "addq %2,%0\n"
11105 + "int $4\n0:\n"
11106 + _ASM_EXTABLE(0b, 0b)
11107 +#endif
11108 +
11109 + "sete %1\n"
11110 : "=m" (v->counter), "=qm" (c)
11111 : "er" (i), "m" (v->counter) : "memory");
11112 return c;
11113 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
11114 */
11115 static inline void atomic64_inc(atomic64_t *v)
11116 {
11117 + asm volatile(LOCK_PREFIX "incq %0\n"
11118 +
11119 +#ifdef CONFIG_PAX_REFCOUNT
11120 + "jno 0f\n"
11121 + LOCK_PREFIX "decq %0\n"
11122 + "int $4\n0:\n"
11123 + _ASM_EXTABLE(0b, 0b)
11124 +#endif
11125 +
11126 + : "=m" (v->counter)
11127 + : "m" (v->counter));
11128 +}
11129 +
11130 +/**
11131 + * atomic64_inc_unchecked - increment atomic64 variable
11132 + * @v: pointer to type atomic64_unchecked_t
11133 + *
11134 + * Atomically increments @v by 1.
11135 + */
11136 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
11137 +{
11138 asm volatile(LOCK_PREFIX "incq %0"
11139 : "=m" (v->counter)
11140 : "m" (v->counter));
11141 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
11142 */
11143 static inline void atomic64_dec(atomic64_t *v)
11144 {
11145 - asm volatile(LOCK_PREFIX "decq %0"
11146 + asm volatile(LOCK_PREFIX "decq %0\n"
11147 +
11148 +#ifdef CONFIG_PAX_REFCOUNT
11149 + "jno 0f\n"
11150 + LOCK_PREFIX "incq %0\n"
11151 + "int $4\n0:\n"
11152 + _ASM_EXTABLE(0b, 0b)
11153 +#endif
11154 +
11155 + : "=m" (v->counter)
11156 + : "m" (v->counter));
11157 +}
11158 +
11159 +/**
11160 + * atomic64_dec_unchecked - decrement atomic64 variable
11161 + * @v: pointer to type atomic64_t
11162 + *
11163 + * Atomically decrements @v by 1.
11164 + */
11165 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
11166 +{
11167 + asm volatile(LOCK_PREFIX "decq %0\n"
11168 : "=m" (v->counter)
11169 : "m" (v->counter));
11170 }
11171 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
11172 {
11173 unsigned char c;
11174
11175 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
11176 + asm volatile(LOCK_PREFIX "decq %0\n"
11177 +
11178 +#ifdef CONFIG_PAX_REFCOUNT
11179 + "jno 0f\n"
11180 + LOCK_PREFIX "incq %0\n"
11181 + "int $4\n0:\n"
11182 + _ASM_EXTABLE(0b, 0b)
11183 +#endif
11184 +
11185 + "sete %1\n"
11186 : "=m" (v->counter), "=qm" (c)
11187 : "m" (v->counter) : "memory");
11188 return c != 0;
11189 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
11190 {
11191 unsigned char c;
11192
11193 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
11194 + asm volatile(LOCK_PREFIX "incq %0\n"
11195 +
11196 +#ifdef CONFIG_PAX_REFCOUNT
11197 + "jno 0f\n"
11198 + LOCK_PREFIX "decq %0\n"
11199 + "int $4\n0:\n"
11200 + _ASM_EXTABLE(0b, 0b)
11201 +#endif
11202 +
11203 + "sete %1\n"
11204 : "=m" (v->counter), "=qm" (c)
11205 : "m" (v->counter) : "memory");
11206 return c != 0;
11207 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
11208 {
11209 unsigned char c;
11210
11211 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
11212 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
11213 +
11214 +#ifdef CONFIG_PAX_REFCOUNT
11215 + "jno 0f\n"
11216 + LOCK_PREFIX "subq %2,%0\n"
11217 + "int $4\n0:\n"
11218 + _ASM_EXTABLE(0b, 0b)
11219 +#endif
11220 +
11221 + "sets %1\n"
11222 : "=m" (v->counter), "=qm" (c)
11223 : "er" (i), "m" (v->counter) : "memory");
11224 return c;
11225 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
11226 */
11227 static inline long atomic64_add_return(long i, atomic64_t *v)
11228 {
11229 + return i + xadd_check_overflow(&v->counter, i);
11230 +}
11231 +
11232 +/**
11233 + * atomic64_add_return_unchecked - add and return
11234 + * @i: integer value to add
11235 + * @v: pointer to type atomic64_unchecked_t
11236 + *
11237 + * Atomically adds @i to @v and returns @i + @v
11238 + */
11239 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
11240 +{
11241 return i + xadd(&v->counter, i);
11242 }
11243
11244 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
11245 }
11246
11247 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
11248 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
11249 +{
11250 + return atomic64_add_return_unchecked(1, v);
11251 +}
11252 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
11253
11254 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
11255 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
11256 return cmpxchg(&v->counter, old, new);
11257 }
11258
11259 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
11260 +{
11261 + return cmpxchg(&v->counter, old, new);
11262 +}
11263 +
11264 static inline long atomic64_xchg(atomic64_t *v, long new)
11265 {
11266 return xchg(&v->counter, new);
11267 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
11268 */
11269 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
11270 {
11271 - long c, old;
11272 + long c, old, new;
11273 c = atomic64_read(v);
11274 for (;;) {
11275 - if (unlikely(c == (u)))
11276 + if (unlikely(c == u))
11277 break;
11278 - old = atomic64_cmpxchg((v), c, c + (a));
11279 +
11280 + asm volatile("add %2,%0\n"
11281 +
11282 +#ifdef CONFIG_PAX_REFCOUNT
11283 + "jno 0f\n"
11284 + "sub %2,%0\n"
11285 + "int $4\n0:\n"
11286 + _ASM_EXTABLE(0b, 0b)
11287 +#endif
11288 +
11289 + : "=r" (new)
11290 + : "0" (c), "ir" (a));
11291 +
11292 + old = atomic64_cmpxchg(v, c, new);
11293 if (likely(old == c))
11294 break;
11295 c = old;
11296 }
11297 - return c != (u);
11298 + return c != u;
11299 }
11300
11301 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11302 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
11303 index 6dfd019..0c6699f 100644
11304 --- a/arch/x86/include/asm/bitops.h
11305 +++ b/arch/x86/include/asm/bitops.h
11306 @@ -40,7 +40,7 @@
11307 * a mask operation on a byte.
11308 */
11309 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
11310 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
11311 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
11312 #define CONST_MASK(nr) (1 << ((nr) & 7))
11313
11314 /**
11315 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
11316 index b13fe63..0dab13a 100644
11317 --- a/arch/x86/include/asm/boot.h
11318 +++ b/arch/x86/include/asm/boot.h
11319 @@ -11,10 +11,15 @@
11320 #include <asm/pgtable_types.h>
11321
11322 /* Physical address where kernel should be loaded. */
11323 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
11324 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
11325 + (CONFIG_PHYSICAL_ALIGN - 1)) \
11326 & ~(CONFIG_PHYSICAL_ALIGN - 1))
11327
11328 +#ifndef __ASSEMBLY__
11329 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
11330 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
11331 +#endif
11332 +
11333 /* Minimum kernel alignment, as a power of two */
11334 #ifdef CONFIG_X86_64
11335 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
11336 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
11337 index 48f99f1..d78ebf9 100644
11338 --- a/arch/x86/include/asm/cache.h
11339 +++ b/arch/x86/include/asm/cache.h
11340 @@ -5,12 +5,13 @@
11341
11342 /* L1 cache line size */
11343 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
11344 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11345 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11346
11347 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
11348 +#define __read_only __attribute__((__section__(".data..read_only")))
11349
11350 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
11351 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
11352 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
11353
11354 #ifdef CONFIG_X86_VSMP
11355 #ifdef CONFIG_SMP
11356 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
11357 index 9863ee3..4a1f8e1 100644
11358 --- a/arch/x86/include/asm/cacheflush.h
11359 +++ b/arch/x86/include/asm/cacheflush.h
11360 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
11361 unsigned long pg_flags = pg->flags & _PGMT_MASK;
11362
11363 if (pg_flags == _PGMT_DEFAULT)
11364 - return -1;
11365 + return ~0UL;
11366 else if (pg_flags == _PGMT_WC)
11367 return _PAGE_CACHE_WC;
11368 else if (pg_flags == _PGMT_UC_MINUS)
11369 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
11370 index 46fc474..b02b0f9 100644
11371 --- a/arch/x86/include/asm/checksum_32.h
11372 +++ b/arch/x86/include/asm/checksum_32.h
11373 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
11374 int len, __wsum sum,
11375 int *src_err_ptr, int *dst_err_ptr);
11376
11377 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
11378 + int len, __wsum sum,
11379 + int *src_err_ptr, int *dst_err_ptr);
11380 +
11381 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
11382 + int len, __wsum sum,
11383 + int *src_err_ptr, int *dst_err_ptr);
11384 +
11385 /*
11386 * Note: when you get a NULL pointer exception here this means someone
11387 * passed in an incorrect kernel address to one of these functions.
11388 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
11389 int *err_ptr)
11390 {
11391 might_sleep();
11392 - return csum_partial_copy_generic((__force void *)src, dst,
11393 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
11394 len, sum, err_ptr, NULL);
11395 }
11396
11397 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
11398 {
11399 might_sleep();
11400 if (access_ok(VERIFY_WRITE, dst, len))
11401 - return csum_partial_copy_generic(src, (__force void *)dst,
11402 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
11403 len, sum, NULL, err_ptr);
11404
11405 if (len)
11406 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
11407 index 8d871ea..c1a0dc9 100644
11408 --- a/arch/x86/include/asm/cmpxchg.h
11409 +++ b/arch/x86/include/asm/cmpxchg.h
11410 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
11411 __compiletime_error("Bad argument size for cmpxchg");
11412 extern void __xadd_wrong_size(void)
11413 __compiletime_error("Bad argument size for xadd");
11414 +extern void __xadd_check_overflow_wrong_size(void)
11415 + __compiletime_error("Bad argument size for xadd_check_overflow");
11416 extern void __add_wrong_size(void)
11417 __compiletime_error("Bad argument size for add");
11418 +extern void __add_check_overflow_wrong_size(void)
11419 + __compiletime_error("Bad argument size for add_check_overflow");
11420
11421 /*
11422 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
11423 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
11424 __ret; \
11425 })
11426
11427 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
11428 + ({ \
11429 + __typeof__ (*(ptr)) __ret = (arg); \
11430 + switch (sizeof(*(ptr))) { \
11431 + case __X86_CASE_L: \
11432 + asm volatile (lock #op "l %0, %1\n" \
11433 + "jno 0f\n" \
11434 + "mov %0,%1\n" \
11435 + "int $4\n0:\n" \
11436 + _ASM_EXTABLE(0b, 0b) \
11437 + : "+r" (__ret), "+m" (*(ptr)) \
11438 + : : "memory", "cc"); \
11439 + break; \
11440 + case __X86_CASE_Q: \
11441 + asm volatile (lock #op "q %q0, %1\n" \
11442 + "jno 0f\n" \
11443 + "mov %0,%1\n" \
11444 + "int $4\n0:\n" \
11445 + _ASM_EXTABLE(0b, 0b) \
11446 + : "+r" (__ret), "+m" (*(ptr)) \
11447 + : : "memory", "cc"); \
11448 + break; \
11449 + default: \
11450 + __ ## op ## _check_overflow_wrong_size(); \
11451 + } \
11452 + __ret; \
11453 + })
11454 +
11455 /*
11456 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
11457 * Since this is generally used to protect other memory information, we
11458 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
11459 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
11460 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
11461
11462 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
11463 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
11464 +
11465 #define __add(ptr, inc, lock) \
11466 ({ \
11467 __typeof__ (*(ptr)) __ret = (inc); \
11468 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
11469 index 8c297aa..7a90f03 100644
11470 --- a/arch/x86/include/asm/cpufeature.h
11471 +++ b/arch/x86/include/asm/cpufeature.h
11472 @@ -205,7 +205,7 @@
11473 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
11474 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
11475 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
11476 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
11477 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
11478 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
11479 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
11480 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
11481 @@ -379,7 +379,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
11482 ".section .discard,\"aw\",@progbits\n"
11483 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
11484 ".previous\n"
11485 - ".section .altinstr_replacement,\"ax\"\n"
11486 + ".section .altinstr_replacement,\"a\"\n"
11487 "3: movb $1,%0\n"
11488 "4:\n"
11489 ".previous\n"
11490 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
11491 index 8bf1c06..f723dfd 100644
11492 --- a/arch/x86/include/asm/desc.h
11493 +++ b/arch/x86/include/asm/desc.h
11494 @@ -4,6 +4,7 @@
11495 #include <asm/desc_defs.h>
11496 #include <asm/ldt.h>
11497 #include <asm/mmu.h>
11498 +#include <asm/pgtable.h>
11499
11500 #include <linux/smp.h>
11501 #include <linux/percpu.h>
11502 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
11503
11504 desc->type = (info->read_exec_only ^ 1) << 1;
11505 desc->type |= info->contents << 2;
11506 + desc->type |= info->seg_not_present ^ 1;
11507
11508 desc->s = 1;
11509 desc->dpl = 0x3;
11510 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
11511 }
11512
11513 extern struct desc_ptr idt_descr;
11514 -extern gate_desc idt_table[];
11515 extern struct desc_ptr nmi_idt_descr;
11516 -extern gate_desc nmi_idt_table[];
11517 -
11518 -struct gdt_page {
11519 - struct desc_struct gdt[GDT_ENTRIES];
11520 -} __attribute__((aligned(PAGE_SIZE)));
11521 -
11522 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
11523 +extern gate_desc idt_table[256];
11524 +extern gate_desc nmi_idt_table[256];
11525
11526 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
11527 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
11528 {
11529 - return per_cpu(gdt_page, cpu).gdt;
11530 + return cpu_gdt_table[cpu];
11531 }
11532
11533 #ifdef CONFIG_X86_64
11534 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
11535 unsigned long base, unsigned dpl, unsigned flags,
11536 unsigned short seg)
11537 {
11538 - gate->a = (seg << 16) | (base & 0xffff);
11539 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
11540 + gate->gate.offset_low = base;
11541 + gate->gate.seg = seg;
11542 + gate->gate.reserved = 0;
11543 + gate->gate.type = type;
11544 + gate->gate.s = 0;
11545 + gate->gate.dpl = dpl;
11546 + gate->gate.p = 1;
11547 + gate->gate.offset_high = base >> 16;
11548 }
11549
11550 #endif
11551 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
11552
11553 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
11554 {
11555 + pax_open_kernel();
11556 memcpy(&idt[entry], gate, sizeof(*gate));
11557 + pax_close_kernel();
11558 }
11559
11560 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
11561 {
11562 + pax_open_kernel();
11563 memcpy(&ldt[entry], desc, 8);
11564 + pax_close_kernel();
11565 }
11566
11567 static inline void
11568 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
11569 default: size = sizeof(*gdt); break;
11570 }
11571
11572 + pax_open_kernel();
11573 memcpy(&gdt[entry], desc, size);
11574 + pax_close_kernel();
11575 }
11576
11577 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
11578 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
11579
11580 static inline void native_load_tr_desc(void)
11581 {
11582 + pax_open_kernel();
11583 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
11584 + pax_close_kernel();
11585 }
11586
11587 static inline void native_load_gdt(const struct desc_ptr *dtr)
11588 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
11589 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
11590 unsigned int i;
11591
11592 + pax_open_kernel();
11593 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
11594 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
11595 + pax_close_kernel();
11596 }
11597
11598 #define _LDT_empty(info) \
11599 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
11600 }
11601
11602 #ifdef CONFIG_X86_64
11603 -static inline void set_nmi_gate(int gate, void *addr)
11604 +static inline void set_nmi_gate(int gate, const void *addr)
11605 {
11606 gate_desc s;
11607
11608 @@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
11609 }
11610 #endif
11611
11612 -static inline void _set_gate(int gate, unsigned type, void *addr,
11613 +static inline void _set_gate(int gate, unsigned type, const void *addr,
11614 unsigned dpl, unsigned ist, unsigned seg)
11615 {
11616 gate_desc s;
11617 @@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
11618 * Pentium F0 0F bugfix can have resulted in the mapped
11619 * IDT being write-protected.
11620 */
11621 -static inline void set_intr_gate(unsigned int n, void *addr)
11622 +static inline void set_intr_gate(unsigned int n, const void *addr)
11623 {
11624 BUG_ON((unsigned)n > 0xFF);
11625 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
11626 @@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
11627 /*
11628 * This routine sets up an interrupt gate at directory privilege level 3.
11629 */
11630 -static inline void set_system_intr_gate(unsigned int n, void *addr)
11631 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
11632 {
11633 BUG_ON((unsigned)n > 0xFF);
11634 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
11635 }
11636
11637 -static inline void set_system_trap_gate(unsigned int n, void *addr)
11638 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
11639 {
11640 BUG_ON((unsigned)n > 0xFF);
11641 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
11642 }
11643
11644 -static inline void set_trap_gate(unsigned int n, void *addr)
11645 +static inline void set_trap_gate(unsigned int n, const void *addr)
11646 {
11647 BUG_ON((unsigned)n > 0xFF);
11648 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
11649 @@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
11650 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
11651 {
11652 BUG_ON((unsigned)n > 0xFF);
11653 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
11654 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
11655 }
11656
11657 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
11658 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
11659 {
11660 BUG_ON((unsigned)n > 0xFF);
11661 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
11662 }
11663
11664 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
11665 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
11666 {
11667 BUG_ON((unsigned)n > 0xFF);
11668 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
11669 }
11670
11671 +#ifdef CONFIG_X86_32
11672 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
11673 +{
11674 + struct desc_struct d;
11675 +
11676 + if (likely(limit))
11677 + limit = (limit - 1UL) >> PAGE_SHIFT;
11678 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
11679 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
11680 +}
11681 +#endif
11682 +
11683 #endif /* _ASM_X86_DESC_H */
11684 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
11685 index 278441f..b95a174 100644
11686 --- a/arch/x86/include/asm/desc_defs.h
11687 +++ b/arch/x86/include/asm/desc_defs.h
11688 @@ -31,6 +31,12 @@ struct desc_struct {
11689 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
11690 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
11691 };
11692 + struct {
11693 + u16 offset_low;
11694 + u16 seg;
11695 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
11696 + unsigned offset_high: 16;
11697 + } gate;
11698 };
11699 } __attribute__((packed));
11700
11701 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
11702 index 3778256..c5d4fce 100644
11703 --- a/arch/x86/include/asm/e820.h
11704 +++ b/arch/x86/include/asm/e820.h
11705 @@ -69,7 +69,7 @@ struct e820map {
11706 #define ISA_START_ADDRESS 0xa0000
11707 #define ISA_END_ADDRESS 0x100000
11708
11709 -#define BIOS_BEGIN 0x000a0000
11710 +#define BIOS_BEGIN 0x000c0000
11711 #define BIOS_END 0x00100000
11712
11713 #define BIOS_ROM_BASE 0xffe00000
11714 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
11715 index 5939f44..f8845f6 100644
11716 --- a/arch/x86/include/asm/elf.h
11717 +++ b/arch/x86/include/asm/elf.h
11718 @@ -243,7 +243,25 @@ extern int force_personality32;
11719 the loader. We need to make sure that it is out of the way of the program
11720 that it will "exec", and that there is sufficient room for the brk. */
11721
11722 +#ifdef CONFIG_PAX_SEGMEXEC
11723 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
11724 +#else
11725 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
11726 +#endif
11727 +
11728 +#ifdef CONFIG_PAX_ASLR
11729 +#ifdef CONFIG_X86_32
11730 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
11731 +
11732 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
11733 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
11734 +#else
11735 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
11736 +
11737 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
11738 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
11739 +#endif
11740 +#endif
11741
11742 /* This yields a mask that user programs can use to figure out what
11743 instruction set this CPU supports. This could be done in user space,
11744 @@ -296,16 +314,12 @@ do { \
11745
11746 #define ARCH_DLINFO \
11747 do { \
11748 - if (vdso_enabled) \
11749 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
11750 - (unsigned long)current->mm->context.vdso); \
11751 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
11752 } while (0)
11753
11754 #define ARCH_DLINFO_X32 \
11755 do { \
11756 - if (vdso_enabled) \
11757 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
11758 - (unsigned long)current->mm->context.vdso); \
11759 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
11760 } while (0)
11761
11762 #define AT_SYSINFO 32
11763 @@ -320,7 +334,7 @@ else \
11764
11765 #endif /* !CONFIG_X86_32 */
11766
11767 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
11768 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
11769
11770 #define VDSO_ENTRY \
11771 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
11772 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
11773 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
11774 #define compat_arch_setup_additional_pages syscall32_setup_pages
11775
11776 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
11777 -#define arch_randomize_brk arch_randomize_brk
11778 -
11779 /*
11780 * True on X86_32 or when emulating IA32 on X86_64
11781 */
11782 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
11783 index 75ce3f4..882e801 100644
11784 --- a/arch/x86/include/asm/emergency-restart.h
11785 +++ b/arch/x86/include/asm/emergency-restart.h
11786 @@ -13,6 +13,6 @@ enum reboot_type {
11787
11788 extern enum reboot_type reboot_type;
11789
11790 -extern void machine_emergency_restart(void);
11791 +extern void machine_emergency_restart(void) __noreturn;
11792
11793 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
11794 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
11795 index 41ab26e..a88c9e6 100644
11796 --- a/arch/x86/include/asm/fpu-internal.h
11797 +++ b/arch/x86/include/asm/fpu-internal.h
11798 @@ -126,7 +126,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
11799 ({ \
11800 int err; \
11801 asm volatile(ASM_STAC "\n" \
11802 - "1:" #insn "\n\t" \
11803 + "1:" \
11804 + __copyuser_seg \
11805 + #insn "\n\t" \
11806 "2: " ASM_CLAC "\n" \
11807 ".section .fixup,\"ax\"\n" \
11808 "3: movl $-1,%[err]\n" \
11809 @@ -299,7 +301,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
11810 "emms\n\t" /* clear stack tags */
11811 "fildl %P[addr]", /* set F?P to defined value */
11812 X86_FEATURE_FXSAVE_LEAK,
11813 - [addr] "m" (tsk->thread.fpu.has_fpu));
11814 + [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
11815
11816 return fpu_restore_checking(&tsk->thread.fpu);
11817 }
11818 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
11819 index f373046..02653e2 100644
11820 --- a/arch/x86/include/asm/futex.h
11821 +++ b/arch/x86/include/asm/futex.h
11822 @@ -12,6 +12,7 @@
11823 #include <asm/smap.h>
11824
11825 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
11826 + typecheck(u32 __user *, uaddr); \
11827 asm volatile("\t" ASM_STAC "\n" \
11828 "1:\t" insn "\n" \
11829 "2:\t" ASM_CLAC "\n" \
11830 @@ -20,15 +21,16 @@
11831 "\tjmp\t2b\n" \
11832 "\t.previous\n" \
11833 _ASM_EXTABLE(1b, 3b) \
11834 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
11835 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
11836 : "i" (-EFAULT), "0" (oparg), "1" (0))
11837
11838 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
11839 + typecheck(u32 __user *, uaddr); \
11840 asm volatile("\t" ASM_STAC "\n" \
11841 "1:\tmovl %2, %0\n" \
11842 "\tmovl\t%0, %3\n" \
11843 "\t" insn "\n" \
11844 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
11845 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
11846 "\tjnz\t1b\n" \
11847 "3:\t" ASM_CLAC "\n" \
11848 "\t.section .fixup,\"ax\"\n" \
11849 @@ -38,7 +40,7 @@
11850 _ASM_EXTABLE(1b, 4b) \
11851 _ASM_EXTABLE(2b, 4b) \
11852 : "=&a" (oldval), "=&r" (ret), \
11853 - "+m" (*uaddr), "=&r" (tem) \
11854 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
11855 : "r" (oparg), "i" (-EFAULT), "1" (0))
11856
11857 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
11858 @@ -65,10 +67,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
11859
11860 switch (op) {
11861 case FUTEX_OP_SET:
11862 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
11863 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
11864 break;
11865 case FUTEX_OP_ADD:
11866 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
11867 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
11868 uaddr, oparg);
11869 break;
11870 case FUTEX_OP_OR:
11871 @@ -128,14 +130,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
11872 return -EFAULT;
11873
11874 asm volatile("\t" ASM_STAC "\n"
11875 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
11876 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
11877 "2:\t" ASM_CLAC "\n"
11878 "\t.section .fixup, \"ax\"\n"
11879 "3:\tmov %3, %0\n"
11880 "\tjmp 2b\n"
11881 "\t.previous\n"
11882 _ASM_EXTABLE(1b, 3b)
11883 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
11884 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
11885 : "i" (-EFAULT), "r" (newval), "1" (oldval)
11886 : "memory"
11887 );
11888 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
11889 index eb92a6e..b98b2f4 100644
11890 --- a/arch/x86/include/asm/hw_irq.h
11891 +++ b/arch/x86/include/asm/hw_irq.h
11892 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
11893 extern void enable_IO_APIC(void);
11894
11895 /* Statistics */
11896 -extern atomic_t irq_err_count;
11897 -extern atomic_t irq_mis_count;
11898 +extern atomic_unchecked_t irq_err_count;
11899 +extern atomic_unchecked_t irq_mis_count;
11900
11901 /* EISA */
11902 extern void eisa_set_level_irq(unsigned int irq);
11903 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
11904 index d8e8eef..15b1179 100644
11905 --- a/arch/x86/include/asm/io.h
11906 +++ b/arch/x86/include/asm/io.h
11907 @@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
11908 return ioremap_nocache(offset, size);
11909 }
11910
11911 -extern void iounmap(volatile void __iomem *addr);
11912 +extern void iounmap(const volatile void __iomem *addr);
11913
11914 extern void set_iounmap_nonlazy(void);
11915
11916 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
11917
11918 #include <linux/vmalloc.h>
11919
11920 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
11921 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
11922 +{
11923 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
11924 +}
11925 +
11926 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
11927 +{
11928 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
11929 +}
11930 +
11931 /*
11932 * Convert a virtual cached pointer to an uncached pointer
11933 */
11934 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
11935 index bba3cf8..06bc8da 100644
11936 --- a/arch/x86/include/asm/irqflags.h
11937 +++ b/arch/x86/include/asm/irqflags.h
11938 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
11939 sti; \
11940 sysexit
11941
11942 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
11943 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
11944 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
11945 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
11946 +
11947 #else
11948 #define INTERRUPT_RETURN iret
11949 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
11950 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
11951 index d3ddd17..c9fb0cc 100644
11952 --- a/arch/x86/include/asm/kprobes.h
11953 +++ b/arch/x86/include/asm/kprobes.h
11954 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
11955 #define RELATIVEJUMP_SIZE 5
11956 #define RELATIVECALL_OPCODE 0xe8
11957 #define RELATIVE_ADDR_SIZE 4
11958 -#define MAX_STACK_SIZE 64
11959 -#define MIN_STACK_SIZE(ADDR) \
11960 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
11961 - THREAD_SIZE - (unsigned long)(ADDR))) \
11962 - ? (MAX_STACK_SIZE) \
11963 - : (((unsigned long)current_thread_info()) + \
11964 - THREAD_SIZE - (unsigned long)(ADDR)))
11965 +#define MAX_STACK_SIZE 64UL
11966 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
11967
11968 #define flush_insn_slot(p) do { } while (0)
11969
11970 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
11971 index b2e11f4..f293e2e 100644
11972 --- a/arch/x86/include/asm/kvm_host.h
11973 +++ b/arch/x86/include/asm/kvm_host.h
11974 @@ -707,7 +707,7 @@ struct kvm_x86_ops {
11975 int (*check_intercept)(struct kvm_vcpu *vcpu,
11976 struct x86_instruction_info *info,
11977 enum x86_intercept_stage stage);
11978 -};
11979 +} __do_const;
11980
11981 struct kvm_arch_async_pf {
11982 u32 token;
11983 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
11984 index c8bed0d..85c03fd 100644
11985 --- a/arch/x86/include/asm/local.h
11986 +++ b/arch/x86/include/asm/local.h
11987 @@ -10,33 +10,97 @@ typedef struct {
11988 atomic_long_t a;
11989 } local_t;
11990
11991 +typedef struct {
11992 + atomic_long_unchecked_t a;
11993 +} local_unchecked_t;
11994 +
11995 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
11996
11997 #define local_read(l) atomic_long_read(&(l)->a)
11998 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
11999 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
12000 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
12001
12002 static inline void local_inc(local_t *l)
12003 {
12004 - asm volatile(_ASM_INC "%0"
12005 + asm volatile(_ASM_INC "%0\n"
12006 +
12007 +#ifdef CONFIG_PAX_REFCOUNT
12008 + "jno 0f\n"
12009 + _ASM_DEC "%0\n"
12010 + "int $4\n0:\n"
12011 + _ASM_EXTABLE(0b, 0b)
12012 +#endif
12013 +
12014 + : "+m" (l->a.counter));
12015 +}
12016 +
12017 +static inline void local_inc_unchecked(local_unchecked_t *l)
12018 +{
12019 + asm volatile(_ASM_INC "%0\n"
12020 : "+m" (l->a.counter));
12021 }
12022
12023 static inline void local_dec(local_t *l)
12024 {
12025 - asm volatile(_ASM_DEC "%0"
12026 + asm volatile(_ASM_DEC "%0\n"
12027 +
12028 +#ifdef CONFIG_PAX_REFCOUNT
12029 + "jno 0f\n"
12030 + _ASM_INC "%0\n"
12031 + "int $4\n0:\n"
12032 + _ASM_EXTABLE(0b, 0b)
12033 +#endif
12034 +
12035 + : "+m" (l->a.counter));
12036 +}
12037 +
12038 +static inline void local_dec_unchecked(local_unchecked_t *l)
12039 +{
12040 + asm volatile(_ASM_DEC "%0\n"
12041 : "+m" (l->a.counter));
12042 }
12043
12044 static inline void local_add(long i, local_t *l)
12045 {
12046 - asm volatile(_ASM_ADD "%1,%0"
12047 + asm volatile(_ASM_ADD "%1,%0\n"
12048 +
12049 +#ifdef CONFIG_PAX_REFCOUNT
12050 + "jno 0f\n"
12051 + _ASM_SUB "%1,%0\n"
12052 + "int $4\n0:\n"
12053 + _ASM_EXTABLE(0b, 0b)
12054 +#endif
12055 +
12056 + : "+m" (l->a.counter)
12057 + : "ir" (i));
12058 +}
12059 +
12060 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
12061 +{
12062 + asm volatile(_ASM_ADD "%1,%0\n"
12063 : "+m" (l->a.counter)
12064 : "ir" (i));
12065 }
12066
12067 static inline void local_sub(long i, local_t *l)
12068 {
12069 - asm volatile(_ASM_SUB "%1,%0"
12070 + asm volatile(_ASM_SUB "%1,%0\n"
12071 +
12072 +#ifdef CONFIG_PAX_REFCOUNT
12073 + "jno 0f\n"
12074 + _ASM_ADD "%1,%0\n"
12075 + "int $4\n0:\n"
12076 + _ASM_EXTABLE(0b, 0b)
12077 +#endif
12078 +
12079 + : "+m" (l->a.counter)
12080 + : "ir" (i));
12081 +}
12082 +
12083 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
12084 +{
12085 + asm volatile(_ASM_SUB "%1,%0\n"
12086 : "+m" (l->a.counter)
12087 : "ir" (i));
12088 }
12089 @@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
12090 {
12091 unsigned char c;
12092
12093 - asm volatile(_ASM_SUB "%2,%0; sete %1"
12094 + asm volatile(_ASM_SUB "%2,%0\n"
12095 +
12096 +#ifdef CONFIG_PAX_REFCOUNT
12097 + "jno 0f\n"
12098 + _ASM_ADD "%2,%0\n"
12099 + "int $4\n0:\n"
12100 + _ASM_EXTABLE(0b, 0b)
12101 +#endif
12102 +
12103 + "sete %1\n"
12104 : "+m" (l->a.counter), "=qm" (c)
12105 : "ir" (i) : "memory");
12106 return c;
12107 @@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
12108 {
12109 unsigned char c;
12110
12111 - asm volatile(_ASM_DEC "%0; sete %1"
12112 + asm volatile(_ASM_DEC "%0\n"
12113 +
12114 +#ifdef CONFIG_PAX_REFCOUNT
12115 + "jno 0f\n"
12116 + _ASM_INC "%0\n"
12117 + "int $4\n0:\n"
12118 + _ASM_EXTABLE(0b, 0b)
12119 +#endif
12120 +
12121 + "sete %1\n"
12122 : "+m" (l->a.counter), "=qm" (c)
12123 : : "memory");
12124 return c != 0;
12125 @@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
12126 {
12127 unsigned char c;
12128
12129 - asm volatile(_ASM_INC "%0; sete %1"
12130 + asm volatile(_ASM_INC "%0\n"
12131 +
12132 +#ifdef CONFIG_PAX_REFCOUNT
12133 + "jno 0f\n"
12134 + _ASM_DEC "%0\n"
12135 + "int $4\n0:\n"
12136 + _ASM_EXTABLE(0b, 0b)
12137 +#endif
12138 +
12139 + "sete %1\n"
12140 : "+m" (l->a.counter), "=qm" (c)
12141 : : "memory");
12142 return c != 0;
12143 @@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
12144 {
12145 unsigned char c;
12146
12147 - asm volatile(_ASM_ADD "%2,%0; sets %1"
12148 + asm volatile(_ASM_ADD "%2,%0\n"
12149 +
12150 +#ifdef CONFIG_PAX_REFCOUNT
12151 + "jno 0f\n"
12152 + _ASM_SUB "%2,%0\n"
12153 + "int $4\n0:\n"
12154 + _ASM_EXTABLE(0b, 0b)
12155 +#endif
12156 +
12157 + "sets %1\n"
12158 : "+m" (l->a.counter), "=qm" (c)
12159 : "ir" (i) : "memory");
12160 return c;
12161 @@ -132,7 +232,15 @@ static inline long local_add_return(long i, local_t *l)
12162 #endif
12163 /* Modern 486+ processor */
12164 __i = i;
12165 - asm volatile(_ASM_XADD "%0, %1;"
12166 + asm volatile(_ASM_XADD "%0, %1\n"
12167 +
12168 +#ifdef CONFIG_PAX_REFCOUNT
12169 + "jno 0f\n"
12170 + _ASM_MOV "%0,%1\n"
12171 + "int $4\n0:\n"
12172 + _ASM_EXTABLE(0b, 0b)
12173 +#endif
12174 +
12175 : "+r" (i), "+m" (l->a.counter)
12176 : : "memory");
12177 return i + __i;
12178 @@ -147,6 +255,38 @@ no_xadd: /* Legacy 386 processor */
12179 #endif
12180 }
12181
12182 +/**
12183 + * local_add_return_unchecked - add and return
12184 + * @i: integer value to add
12185 + * @l: pointer to type local_unchecked_t
12186 + *
12187 + * Atomically adds @i to @l and returns @i + @l
12188 + */
12189 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
12190 +{
12191 + long __i;
12192 +#ifdef CONFIG_M386
12193 + unsigned long flags;
12194 + if (unlikely(boot_cpu_data.x86 <= 3))
12195 + goto no_xadd;
12196 +#endif
12197 + /* Modern 486+ processor */
12198 + __i = i;
12199 + asm volatile(_ASM_XADD "%0, %1\n"
12200 + : "+r" (i), "+m" (l->a.counter)
12201 + : : "memory");
12202 + return i + __i;
12203 +
12204 +#ifdef CONFIG_M386
12205 +no_xadd: /* Legacy 386 processor */
12206 + local_irq_save(flags);
12207 + __i = local_read_unchecked(l);
12208 + local_set_unchecked(l, i + __i);
12209 + local_irq_restore(flags);
12210 + return i + __i;
12211 +#endif
12212 +}
12213 +
12214 static inline long local_sub_return(long i, local_t *l)
12215 {
12216 return local_add_return(-i, l);
12217 @@ -157,6 +297,8 @@ static inline long local_sub_return(long i, local_t *l)
12218
12219 #define local_cmpxchg(l, o, n) \
12220 (cmpxchg_local(&((l)->a.counter), (o), (n)))
12221 +#define local_cmpxchg_unchecked(l, o, n) \
12222 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
12223 /* Always has a lock prefix */
12224 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
12225
12226 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
12227 index 593e51d..fa69c9a 100644
12228 --- a/arch/x86/include/asm/mman.h
12229 +++ b/arch/x86/include/asm/mman.h
12230 @@ -5,4 +5,14 @@
12231
12232 #include <asm-generic/mman.h>
12233
12234 +#ifdef __KERNEL__
12235 +#ifndef __ASSEMBLY__
12236 +#ifdef CONFIG_X86_32
12237 +#define arch_mmap_check i386_mmap_check
12238 +int i386_mmap_check(unsigned long addr, unsigned long len,
12239 + unsigned long flags);
12240 +#endif
12241 +#endif
12242 +#endif
12243 +
12244 #endif /* _ASM_X86_MMAN_H */
12245 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
12246 index 5f55e69..e20bfb1 100644
12247 --- a/arch/x86/include/asm/mmu.h
12248 +++ b/arch/x86/include/asm/mmu.h
12249 @@ -9,7 +9,7 @@
12250 * we put the segment information here.
12251 */
12252 typedef struct {
12253 - void *ldt;
12254 + struct desc_struct *ldt;
12255 int size;
12256
12257 #ifdef CONFIG_X86_64
12258 @@ -18,7 +18,19 @@ typedef struct {
12259 #endif
12260
12261 struct mutex lock;
12262 - void *vdso;
12263 + unsigned long vdso;
12264 +
12265 +#ifdef CONFIG_X86_32
12266 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
12267 + unsigned long user_cs_base;
12268 + unsigned long user_cs_limit;
12269 +
12270 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
12271 + cpumask_t cpu_user_cs_mask;
12272 +#endif
12273 +
12274 +#endif
12275 +#endif
12276 } mm_context_t;
12277
12278 #ifdef CONFIG_SMP
12279 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
12280 index cdbf367..adb37ac 100644
12281 --- a/arch/x86/include/asm/mmu_context.h
12282 +++ b/arch/x86/include/asm/mmu_context.h
12283 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
12284
12285 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
12286 {
12287 +
12288 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12289 + unsigned int i;
12290 + pgd_t *pgd;
12291 +
12292 + pax_open_kernel();
12293 + pgd = get_cpu_pgd(smp_processor_id());
12294 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
12295 + set_pgd_batched(pgd+i, native_make_pgd(0));
12296 + pax_close_kernel();
12297 +#endif
12298 +
12299 #ifdef CONFIG_SMP
12300 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
12301 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
12302 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
12303 struct task_struct *tsk)
12304 {
12305 unsigned cpu = smp_processor_id();
12306 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12307 + int tlbstate = TLBSTATE_OK;
12308 +#endif
12309
12310 if (likely(prev != next)) {
12311 #ifdef CONFIG_SMP
12312 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12313 + tlbstate = this_cpu_read(cpu_tlbstate.state);
12314 +#endif
12315 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
12316 this_cpu_write(cpu_tlbstate.active_mm, next);
12317 #endif
12318 cpumask_set_cpu(cpu, mm_cpumask(next));
12319
12320 /* Re-load page tables */
12321 +#ifdef CONFIG_PAX_PER_CPU_PGD
12322 + pax_open_kernel();
12323 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
12324 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
12325 + pax_close_kernel();
12326 + load_cr3(get_cpu_pgd(cpu));
12327 +#else
12328 load_cr3(next->pgd);
12329 +#endif
12330
12331 /* stop flush ipis for the previous mm */
12332 cpumask_clear_cpu(cpu, mm_cpumask(prev));
12333 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
12334 */
12335 if (unlikely(prev->context.ldt != next->context.ldt))
12336 load_LDT_nolock(&next->context);
12337 - }
12338 +
12339 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
12340 + if (!(__supported_pte_mask & _PAGE_NX)) {
12341 + smp_mb__before_clear_bit();
12342 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
12343 + smp_mb__after_clear_bit();
12344 + cpu_set(cpu, next->context.cpu_user_cs_mask);
12345 + }
12346 +#endif
12347 +
12348 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12349 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
12350 + prev->context.user_cs_limit != next->context.user_cs_limit))
12351 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
12352 #ifdef CONFIG_SMP
12353 + else if (unlikely(tlbstate != TLBSTATE_OK))
12354 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
12355 +#endif
12356 +#endif
12357 +
12358 + }
12359 else {
12360 +
12361 +#ifdef CONFIG_PAX_PER_CPU_PGD
12362 + pax_open_kernel();
12363 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
12364 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
12365 + pax_close_kernel();
12366 + load_cr3(get_cpu_pgd(cpu));
12367 +#endif
12368 +
12369 +#ifdef CONFIG_SMP
12370 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
12371 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
12372
12373 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
12374 * tlb flush IPI delivery. We must reload CR3
12375 * to make sure to use no freed page tables.
12376 */
12377 +
12378 +#ifndef CONFIG_PAX_PER_CPU_PGD
12379 load_cr3(next->pgd);
12380 +#endif
12381 +
12382 load_LDT_nolock(&next->context);
12383 +
12384 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
12385 + if (!(__supported_pte_mask & _PAGE_NX))
12386 + cpu_set(cpu, next->context.cpu_user_cs_mask);
12387 +#endif
12388 +
12389 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12390 +#ifdef CONFIG_PAX_PAGEEXEC
12391 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
12392 +#endif
12393 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
12394 +#endif
12395 +
12396 }
12397 +#endif
12398 }
12399 -#endif
12400 }
12401
12402 #define activate_mm(prev, next) \
12403 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
12404 index 9eae775..c914fea 100644
12405 --- a/arch/x86/include/asm/module.h
12406 +++ b/arch/x86/include/asm/module.h
12407 @@ -5,6 +5,7 @@
12408
12409 #ifdef CONFIG_X86_64
12410 /* X86_64 does not define MODULE_PROC_FAMILY */
12411 +#define MODULE_PROC_FAMILY ""
12412 #elif defined CONFIG_M386
12413 #define MODULE_PROC_FAMILY "386 "
12414 #elif defined CONFIG_M486
12415 @@ -59,8 +60,20 @@
12416 #error unknown processor family
12417 #endif
12418
12419 -#ifdef CONFIG_X86_32
12420 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
12421 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
12422 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
12423 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
12424 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
12425 +#else
12426 +#define MODULE_PAX_KERNEXEC ""
12427 #endif
12428
12429 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12430 +#define MODULE_PAX_UDEREF "UDEREF "
12431 +#else
12432 +#define MODULE_PAX_UDEREF ""
12433 +#endif
12434 +
12435 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
12436 +
12437 #endif /* _ASM_X86_MODULE_H */
12438 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
12439 index 320f7bb..e89f8f8 100644
12440 --- a/arch/x86/include/asm/page_64_types.h
12441 +++ b/arch/x86/include/asm/page_64_types.h
12442 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
12443
12444 /* duplicated to the one in bootmem.h */
12445 extern unsigned long max_pfn;
12446 -extern unsigned long phys_base;
12447 +extern const unsigned long phys_base;
12448
12449 extern unsigned long __phys_addr(unsigned long);
12450 #define __phys_reloc_hide(x) (x)
12451 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
12452 index a0facf3..c017b15 100644
12453 --- a/arch/x86/include/asm/paravirt.h
12454 +++ b/arch/x86/include/asm/paravirt.h
12455 @@ -632,6 +632,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
12456 val);
12457 }
12458
12459 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
12460 +{
12461 + pgdval_t val = native_pgd_val(pgd);
12462 +
12463 + if (sizeof(pgdval_t) > sizeof(long))
12464 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
12465 + val, (u64)val >> 32);
12466 + else
12467 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
12468 + val);
12469 +}
12470 +
12471 static inline void pgd_clear(pgd_t *pgdp)
12472 {
12473 set_pgd(pgdp, __pgd(0));
12474 @@ -713,6 +725,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
12475 pv_mmu_ops.set_fixmap(idx, phys, flags);
12476 }
12477
12478 +#ifdef CONFIG_PAX_KERNEXEC
12479 +static inline unsigned long pax_open_kernel(void)
12480 +{
12481 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
12482 +}
12483 +
12484 +static inline unsigned long pax_close_kernel(void)
12485 +{
12486 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
12487 +}
12488 +#else
12489 +static inline unsigned long pax_open_kernel(void) { return 0; }
12490 +static inline unsigned long pax_close_kernel(void) { return 0; }
12491 +#endif
12492 +
12493 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
12494
12495 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
12496 @@ -929,7 +956,7 @@ extern void default_banner(void);
12497
12498 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
12499 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
12500 -#define PARA_INDIRECT(addr) *%cs:addr
12501 +#define PARA_INDIRECT(addr) *%ss:addr
12502 #endif
12503
12504 #define INTERRUPT_RETURN \
12505 @@ -1004,6 +1031,21 @@ extern void default_banner(void);
12506 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
12507 CLBR_NONE, \
12508 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
12509 +
12510 +#define GET_CR0_INTO_RDI \
12511 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
12512 + mov %rax,%rdi
12513 +
12514 +#define SET_RDI_INTO_CR0 \
12515 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
12516 +
12517 +#define GET_CR3_INTO_RDI \
12518 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
12519 + mov %rax,%rdi
12520 +
12521 +#define SET_RDI_INTO_CR3 \
12522 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
12523 +
12524 #endif /* CONFIG_X86_32 */
12525
12526 #endif /* __ASSEMBLY__ */
12527 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
12528 index 142236e..57cf5ea 100644
12529 --- a/arch/x86/include/asm/paravirt_types.h
12530 +++ b/arch/x86/include/asm/paravirt_types.h
12531 @@ -312,6 +312,7 @@ struct pv_mmu_ops {
12532 struct paravirt_callee_save make_pud;
12533
12534 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
12535 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
12536 #endif /* PAGETABLE_LEVELS == 4 */
12537 #endif /* PAGETABLE_LEVELS >= 3 */
12538
12539 @@ -323,6 +324,12 @@ struct pv_mmu_ops {
12540 an mfn. We can tell which is which from the index. */
12541 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
12542 phys_addr_t phys, pgprot_t flags);
12543 +
12544 +#ifdef CONFIG_PAX_KERNEXEC
12545 + unsigned long (*pax_open_kernel)(void);
12546 + unsigned long (*pax_close_kernel)(void);
12547 +#endif
12548 +
12549 };
12550
12551 struct arch_spinlock;
12552 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
12553 index b4389a4..7024269 100644
12554 --- a/arch/x86/include/asm/pgalloc.h
12555 +++ b/arch/x86/include/asm/pgalloc.h
12556 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
12557 pmd_t *pmd, pte_t *pte)
12558 {
12559 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
12560 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
12561 +}
12562 +
12563 +static inline void pmd_populate_user(struct mm_struct *mm,
12564 + pmd_t *pmd, pte_t *pte)
12565 +{
12566 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
12567 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
12568 }
12569
12570 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
12571
12572 #ifdef CONFIG_X86_PAE
12573 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
12574 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
12575 +{
12576 + pud_populate(mm, pudp, pmd);
12577 +}
12578 #else /* !CONFIG_X86_PAE */
12579 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
12580 {
12581 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
12582 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
12583 }
12584 +
12585 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
12586 +{
12587 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
12588 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
12589 +}
12590 #endif /* CONFIG_X86_PAE */
12591
12592 #if PAGETABLE_LEVELS > 3
12593 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
12594 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
12595 }
12596
12597 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
12598 +{
12599 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
12600 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
12601 +}
12602 +
12603 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
12604 {
12605 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
12606 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
12607 index f2b489c..4f7e2e5 100644
12608 --- a/arch/x86/include/asm/pgtable-2level.h
12609 +++ b/arch/x86/include/asm/pgtable-2level.h
12610 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
12611
12612 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
12613 {
12614 + pax_open_kernel();
12615 *pmdp = pmd;
12616 + pax_close_kernel();
12617 }
12618
12619 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
12620 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
12621 index 4cc9f2b..5fd9226 100644
12622 --- a/arch/x86/include/asm/pgtable-3level.h
12623 +++ b/arch/x86/include/asm/pgtable-3level.h
12624 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
12625
12626 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
12627 {
12628 + pax_open_kernel();
12629 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
12630 + pax_close_kernel();
12631 }
12632
12633 static inline void native_set_pud(pud_t *pudp, pud_t pud)
12634 {
12635 + pax_open_kernel();
12636 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
12637 + pax_close_kernel();
12638 }
12639
12640 /*
12641 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
12642 index a1f780d..a3eb32f 100644
12643 --- a/arch/x86/include/asm/pgtable.h
12644 +++ b/arch/x86/include/asm/pgtable.h
12645 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
12646
12647 #ifndef __PAGETABLE_PUD_FOLDED
12648 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
12649 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
12650 #define pgd_clear(pgd) native_pgd_clear(pgd)
12651 #endif
12652
12653 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
12654
12655 #define arch_end_context_switch(prev) do {} while(0)
12656
12657 +#define pax_open_kernel() native_pax_open_kernel()
12658 +#define pax_close_kernel() native_pax_close_kernel()
12659 #endif /* CONFIG_PARAVIRT */
12660
12661 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
12662 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
12663 +
12664 +#ifdef CONFIG_PAX_KERNEXEC
12665 +static inline unsigned long native_pax_open_kernel(void)
12666 +{
12667 + unsigned long cr0;
12668 +
12669 + preempt_disable();
12670 + barrier();
12671 + cr0 = read_cr0() ^ X86_CR0_WP;
12672 + BUG_ON(cr0 & X86_CR0_WP);
12673 + write_cr0(cr0);
12674 + return cr0 ^ X86_CR0_WP;
12675 +}
12676 +
12677 +static inline unsigned long native_pax_close_kernel(void)
12678 +{
12679 + unsigned long cr0;
12680 +
12681 + cr0 = read_cr0() ^ X86_CR0_WP;
12682 + BUG_ON(!(cr0 & X86_CR0_WP));
12683 + write_cr0(cr0);
12684 + barrier();
12685 + preempt_enable_no_resched();
12686 + return cr0 ^ X86_CR0_WP;
12687 +}
12688 +#else
12689 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
12690 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
12691 +#endif
12692 +
12693 /*
12694 * The following only work if pte_present() is true.
12695 * Undefined behaviour if not..
12696 */
12697 +static inline int pte_user(pte_t pte)
12698 +{
12699 + return pte_val(pte) & _PAGE_USER;
12700 +}
12701 +
12702 static inline int pte_dirty(pte_t pte)
12703 {
12704 return pte_flags(pte) & _PAGE_DIRTY;
12705 @@ -195,9 +235,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
12706 return pte_clear_flags(pte, _PAGE_RW);
12707 }
12708
12709 +static inline pte_t pte_mkread(pte_t pte)
12710 +{
12711 + return __pte(pte_val(pte) | _PAGE_USER);
12712 +}
12713 +
12714 static inline pte_t pte_mkexec(pte_t pte)
12715 {
12716 - return pte_clear_flags(pte, _PAGE_NX);
12717 +#ifdef CONFIG_X86_PAE
12718 + if (__supported_pte_mask & _PAGE_NX)
12719 + return pte_clear_flags(pte, _PAGE_NX);
12720 + else
12721 +#endif
12722 + return pte_set_flags(pte, _PAGE_USER);
12723 +}
12724 +
12725 +static inline pte_t pte_exprotect(pte_t pte)
12726 +{
12727 +#ifdef CONFIG_X86_PAE
12728 + if (__supported_pte_mask & _PAGE_NX)
12729 + return pte_set_flags(pte, _PAGE_NX);
12730 + else
12731 +#endif
12732 + return pte_clear_flags(pte, _PAGE_USER);
12733 }
12734
12735 static inline pte_t pte_mkdirty(pte_t pte)
12736 @@ -389,6 +449,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
12737 #endif
12738
12739 #ifndef __ASSEMBLY__
12740 +
12741 +#ifdef CONFIG_PAX_PER_CPU_PGD
12742 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
12743 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
12744 +{
12745 + return cpu_pgd[cpu];
12746 +}
12747 +#endif
12748 +
12749 #include <linux/mm_types.h>
12750
12751 static inline int pte_none(pte_t pte)
12752 @@ -565,7 +634,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
12753
12754 static inline int pgd_bad(pgd_t pgd)
12755 {
12756 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
12757 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
12758 }
12759
12760 static inline int pgd_none(pgd_t pgd)
12761 @@ -588,7 +657,12 @@ static inline int pgd_none(pgd_t pgd)
12762 * pgd_offset() returns a (pgd_t *)
12763 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
12764 */
12765 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
12766 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
12767 +
12768 +#ifdef CONFIG_PAX_PER_CPU_PGD
12769 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
12770 +#endif
12771 +
12772 /*
12773 * a shortcut which implies the use of the kernel's pgd, instead
12774 * of a process's
12775 @@ -599,6 +673,20 @@ static inline int pgd_none(pgd_t pgd)
12776 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
12777 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
12778
12779 +#ifdef CONFIG_X86_32
12780 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
12781 +#else
12782 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
12783 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
12784 +
12785 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12786 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
12787 +#else
12788 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
12789 +#endif
12790 +
12791 +#endif
12792 +
12793 #ifndef __ASSEMBLY__
12794
12795 extern int direct_gbpages;
12796 @@ -763,11 +851,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
12797 * dst and src can be on the same page, but the range must not overlap,
12798 * and must not cross a page boundary.
12799 */
12800 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
12801 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
12802 {
12803 - memcpy(dst, src, count * sizeof(pgd_t));
12804 + pax_open_kernel();
12805 + while (count--)
12806 + *dst++ = *src++;
12807 + pax_close_kernel();
12808 }
12809
12810 +#ifdef CONFIG_PAX_PER_CPU_PGD
12811 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
12812 +#endif
12813 +
12814 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12815 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
12816 +#else
12817 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
12818 +#endif
12819
12820 #include <asm-generic/pgtable.h>
12821 #endif /* __ASSEMBLY__ */
12822 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
12823 index 8faa215..a8a17ea 100644
12824 --- a/arch/x86/include/asm/pgtable_32.h
12825 +++ b/arch/x86/include/asm/pgtable_32.h
12826 @@ -25,9 +25,6 @@
12827 struct mm_struct;
12828 struct vm_area_struct;
12829
12830 -extern pgd_t swapper_pg_dir[1024];
12831 -extern pgd_t initial_page_table[1024];
12832 -
12833 static inline void pgtable_cache_init(void) { }
12834 static inline void check_pgt_cache(void) { }
12835 void paging_init(void);
12836 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
12837 # include <asm/pgtable-2level.h>
12838 #endif
12839
12840 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
12841 +extern pgd_t initial_page_table[PTRS_PER_PGD];
12842 +#ifdef CONFIG_X86_PAE
12843 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
12844 +#endif
12845 +
12846 #if defined(CONFIG_HIGHPTE)
12847 #define pte_offset_map(dir, address) \
12848 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
12849 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
12850 /* Clear a kernel PTE and flush it from the TLB */
12851 #define kpte_clear_flush(ptep, vaddr) \
12852 do { \
12853 + pax_open_kernel(); \
12854 pte_clear(&init_mm, (vaddr), (ptep)); \
12855 + pax_close_kernel(); \
12856 __flush_tlb_one((vaddr)); \
12857 } while (0)
12858
12859 @@ -75,6 +80,9 @@ do { \
12860
12861 #endif /* !__ASSEMBLY__ */
12862
12863 +#define HAVE_ARCH_UNMAPPED_AREA
12864 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
12865 +
12866 /*
12867 * kern_addr_valid() is (1) for FLATMEM and (0) for
12868 * SPARSEMEM and DISCONTIGMEM
12869 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
12870 index ed5903b..c7fe163 100644
12871 --- a/arch/x86/include/asm/pgtable_32_types.h
12872 +++ b/arch/x86/include/asm/pgtable_32_types.h
12873 @@ -8,7 +8,7 @@
12874 */
12875 #ifdef CONFIG_X86_PAE
12876 # include <asm/pgtable-3level_types.h>
12877 -# define PMD_SIZE (1UL << PMD_SHIFT)
12878 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
12879 # define PMD_MASK (~(PMD_SIZE - 1))
12880 #else
12881 # include <asm/pgtable-2level_types.h>
12882 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
12883 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
12884 #endif
12885
12886 +#ifdef CONFIG_PAX_KERNEXEC
12887 +#ifndef __ASSEMBLY__
12888 +extern unsigned char MODULES_EXEC_VADDR[];
12889 +extern unsigned char MODULES_EXEC_END[];
12890 +#endif
12891 +#include <asm/boot.h>
12892 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
12893 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
12894 +#else
12895 +#define ktla_ktva(addr) (addr)
12896 +#define ktva_ktla(addr) (addr)
12897 +#endif
12898 +
12899 #define MODULES_VADDR VMALLOC_START
12900 #define MODULES_END VMALLOC_END
12901 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
12902 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
12903 index 47356f9..deb94a2 100644
12904 --- a/arch/x86/include/asm/pgtable_64.h
12905 +++ b/arch/x86/include/asm/pgtable_64.h
12906 @@ -16,10 +16,14 @@
12907
12908 extern pud_t level3_kernel_pgt[512];
12909 extern pud_t level3_ident_pgt[512];
12910 +extern pud_t level3_vmalloc_start_pgt[512];
12911 +extern pud_t level3_vmalloc_end_pgt[512];
12912 +extern pud_t level3_vmemmap_pgt[512];
12913 +extern pud_t level2_vmemmap_pgt[512];
12914 extern pmd_t level2_kernel_pgt[512];
12915 extern pmd_t level2_fixmap_pgt[512];
12916 -extern pmd_t level2_ident_pgt[512];
12917 -extern pgd_t init_level4_pgt[];
12918 +extern pmd_t level2_ident_pgt[512*2];
12919 +extern pgd_t init_level4_pgt[512];
12920
12921 #define swapper_pg_dir init_level4_pgt
12922
12923 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
12924
12925 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
12926 {
12927 + pax_open_kernel();
12928 *pmdp = pmd;
12929 + pax_close_kernel();
12930 }
12931
12932 static inline void native_pmd_clear(pmd_t *pmd)
12933 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
12934
12935 static inline void native_set_pud(pud_t *pudp, pud_t pud)
12936 {
12937 + pax_open_kernel();
12938 *pudp = pud;
12939 + pax_close_kernel();
12940 }
12941
12942 static inline void native_pud_clear(pud_t *pud)
12943 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
12944
12945 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
12946 {
12947 + pax_open_kernel();
12948 + *pgdp = pgd;
12949 + pax_close_kernel();
12950 +}
12951 +
12952 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
12953 +{
12954 *pgdp = pgd;
12955 }
12956
12957 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
12958 index 766ea16..5b96cb3 100644
12959 --- a/arch/x86/include/asm/pgtable_64_types.h
12960 +++ b/arch/x86/include/asm/pgtable_64_types.h
12961 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
12962 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
12963 #define MODULES_END _AC(0xffffffffff000000, UL)
12964 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
12965 +#define MODULES_EXEC_VADDR MODULES_VADDR
12966 +#define MODULES_EXEC_END MODULES_END
12967 +
12968 +#define ktla_ktva(addr) (addr)
12969 +#define ktva_ktla(addr) (addr)
12970
12971 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
12972 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
12973 index ec8a1fc..7ccb593 100644
12974 --- a/arch/x86/include/asm/pgtable_types.h
12975 +++ b/arch/x86/include/asm/pgtable_types.h
12976 @@ -16,13 +16,12 @@
12977 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
12978 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
12979 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
12980 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
12981 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
12982 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
12983 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
12984 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
12985 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
12986 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
12987 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
12988 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
12989 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
12990 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
12991
12992 /* If _PAGE_BIT_PRESENT is clear, we use these: */
12993 @@ -40,7 +39,6 @@
12994 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
12995 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
12996 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
12997 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
12998 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
12999 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
13000 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
13001 @@ -57,8 +55,10 @@
13002
13003 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
13004 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
13005 -#else
13006 +#elif defined(CONFIG_KMEMCHECK)
13007 #define _PAGE_NX (_AT(pteval_t, 0))
13008 +#else
13009 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
13010 #endif
13011
13012 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
13013 @@ -96,6 +96,9 @@
13014 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
13015 _PAGE_ACCESSED)
13016
13017 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
13018 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
13019 +
13020 #define __PAGE_KERNEL_EXEC \
13021 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
13022 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
13023 @@ -106,7 +109,7 @@
13024 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
13025 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
13026 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
13027 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
13028 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
13029 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
13030 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
13031 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
13032 @@ -168,8 +171,8 @@
13033 * bits are combined, this will alow user to access the high address mapped
13034 * VDSO in the presence of CONFIG_COMPAT_VDSO
13035 */
13036 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
13037 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
13038 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
13039 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
13040 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
13041 #endif
13042
13043 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
13044 {
13045 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
13046 }
13047 +#endif
13048
13049 +#if PAGETABLE_LEVELS == 3
13050 +#include <asm-generic/pgtable-nopud.h>
13051 +#endif
13052 +
13053 +#if PAGETABLE_LEVELS == 2
13054 +#include <asm-generic/pgtable-nopmd.h>
13055 +#endif
13056 +
13057 +#ifndef __ASSEMBLY__
13058 #if PAGETABLE_LEVELS > 3
13059 typedef struct { pudval_t pud; } pud_t;
13060
13061 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
13062 return pud.pud;
13063 }
13064 #else
13065 -#include <asm-generic/pgtable-nopud.h>
13066 -
13067 static inline pudval_t native_pud_val(pud_t pud)
13068 {
13069 return native_pgd_val(pud.pgd);
13070 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
13071 return pmd.pmd;
13072 }
13073 #else
13074 -#include <asm-generic/pgtable-nopmd.h>
13075 -
13076 static inline pmdval_t native_pmd_val(pmd_t pmd)
13077 {
13078 return native_pgd_val(pmd.pud.pgd);
13079 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
13080
13081 extern pteval_t __supported_pte_mask;
13082 extern void set_nx(void);
13083 -extern int nx_enabled;
13084
13085 #define pgprot_writecombine pgprot_writecombine
13086 extern pgprot_t pgprot_writecombine(pgprot_t prot);
13087 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
13088 index ad1fc85..0b15fe1 100644
13089 --- a/arch/x86/include/asm/processor.h
13090 +++ b/arch/x86/include/asm/processor.h
13091 @@ -289,7 +289,7 @@ struct tss_struct {
13092
13093 } ____cacheline_aligned;
13094
13095 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
13096 +extern struct tss_struct init_tss[NR_CPUS];
13097
13098 /*
13099 * Save the original ist values for checking stack pointers during debugging
13100 @@ -818,11 +818,18 @@ static inline void spin_lock_prefetch(const void *x)
13101 */
13102 #define TASK_SIZE PAGE_OFFSET
13103 #define TASK_SIZE_MAX TASK_SIZE
13104 +
13105 +#ifdef CONFIG_PAX_SEGMEXEC
13106 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
13107 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
13108 +#else
13109 #define STACK_TOP TASK_SIZE
13110 -#define STACK_TOP_MAX STACK_TOP
13111 +#endif
13112 +
13113 +#define STACK_TOP_MAX TASK_SIZE
13114
13115 #define INIT_THREAD { \
13116 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
13117 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
13118 .vm86_info = NULL, \
13119 .sysenter_cs = __KERNEL_CS, \
13120 .io_bitmap_ptr = NULL, \
13121 @@ -836,7 +843,7 @@ static inline void spin_lock_prefetch(const void *x)
13122 */
13123 #define INIT_TSS { \
13124 .x86_tss = { \
13125 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
13126 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
13127 .ss0 = __KERNEL_DS, \
13128 .ss1 = __KERNEL_CS, \
13129 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
13130 @@ -847,11 +854,7 @@ static inline void spin_lock_prefetch(const void *x)
13131 extern unsigned long thread_saved_pc(struct task_struct *tsk);
13132
13133 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
13134 -#define KSTK_TOP(info) \
13135 -({ \
13136 - unsigned long *__ptr = (unsigned long *)(info); \
13137 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
13138 -})
13139 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
13140
13141 /*
13142 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
13143 @@ -866,7 +869,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
13144 #define task_pt_regs(task) \
13145 ({ \
13146 struct pt_regs *__regs__; \
13147 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
13148 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
13149 __regs__ - 1; \
13150 })
13151
13152 @@ -876,13 +879,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
13153 /*
13154 * User space process size. 47bits minus one guard page.
13155 */
13156 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
13157 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
13158
13159 /* This decides where the kernel will search for a free chunk of vm
13160 * space during mmap's.
13161 */
13162 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
13163 - 0xc0000000 : 0xFFFFe000)
13164 + 0xc0000000 : 0xFFFFf000)
13165
13166 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
13167 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
13168 @@ -893,11 +896,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
13169 #define STACK_TOP_MAX TASK_SIZE_MAX
13170
13171 #define INIT_THREAD { \
13172 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
13173 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
13174 }
13175
13176 #define INIT_TSS { \
13177 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
13178 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
13179 }
13180
13181 /*
13182 @@ -925,6 +928,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
13183 */
13184 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
13185
13186 +#ifdef CONFIG_PAX_SEGMEXEC
13187 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
13188 +#endif
13189 +
13190 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
13191
13192 /* Get/set a process' ability to use the timestamp counter instruction */
13193 @@ -985,12 +992,12 @@ extern bool cpu_has_amd_erratum(const int *);
13194 #define cpu_has_amd_erratum(x) (false)
13195 #endif /* CONFIG_CPU_SUP_AMD */
13196
13197 -extern unsigned long arch_align_stack(unsigned long sp);
13198 +#define arch_align_stack(x) ((x) & ~0xfUL)
13199 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
13200
13201 void default_idle(void);
13202 bool set_pm_idle_to_default(void);
13203
13204 -void stop_this_cpu(void *dummy);
13205 +void stop_this_cpu(void *dummy) __noreturn;
13206
13207 #endif /* _ASM_X86_PROCESSOR_H */
13208 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
13209 index 19f16eb..b50624b 100644
13210 --- a/arch/x86/include/asm/ptrace.h
13211 +++ b/arch/x86/include/asm/ptrace.h
13212 @@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
13213 }
13214
13215 /*
13216 - * user_mode_vm(regs) determines whether a register set came from user mode.
13217 + * user_mode(regs) determines whether a register set came from user mode.
13218 * This is true if V8086 mode was enabled OR if the register set was from
13219 * protected mode with RPL-3 CS value. This tricky test checks that with
13220 * one comparison. Many places in the kernel can bypass this full check
13221 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
13222 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
13223 + * be used.
13224 */
13225 -static inline int user_mode(struct pt_regs *regs)
13226 +static inline int user_mode_novm(struct pt_regs *regs)
13227 {
13228 #ifdef CONFIG_X86_32
13229 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
13230 #else
13231 - return !!(regs->cs & 3);
13232 + return !!(regs->cs & SEGMENT_RPL_MASK);
13233 #endif
13234 }
13235
13236 -static inline int user_mode_vm(struct pt_regs *regs)
13237 +static inline int user_mode(struct pt_regs *regs)
13238 {
13239 #ifdef CONFIG_X86_32
13240 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
13241 USER_RPL;
13242 #else
13243 - return user_mode(regs);
13244 + return user_mode_novm(regs);
13245 #endif
13246 }
13247
13248 @@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
13249 #ifdef CONFIG_X86_64
13250 static inline bool user_64bit_mode(struct pt_regs *regs)
13251 {
13252 + unsigned long cs = regs->cs & 0xffff;
13253 #ifndef CONFIG_PARAVIRT
13254 /*
13255 * On non-paravirt systems, this is the only long mode CPL 3
13256 * selector. We do not allow long mode selectors in the LDT.
13257 */
13258 - return regs->cs == __USER_CS;
13259 + return cs == __USER_CS;
13260 #else
13261 /* Headers are too twisted for this to go in paravirt.h. */
13262 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
13263 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
13264 #endif
13265 }
13266 #endif
13267 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
13268 index fe1ec5b..dc5c3fe 100644
13269 --- a/arch/x86/include/asm/realmode.h
13270 +++ b/arch/x86/include/asm/realmode.h
13271 @@ -22,16 +22,14 @@ struct real_mode_header {
13272 #endif
13273 /* APM/BIOS reboot */
13274 u32 machine_real_restart_asm;
13275 -#ifdef CONFIG_X86_64
13276 u32 machine_real_restart_seg;
13277 -#endif
13278 };
13279
13280 /* This must match data at trampoline_32/64.S */
13281 struct trampoline_header {
13282 #ifdef CONFIG_X86_32
13283 u32 start;
13284 - u16 gdt_pad;
13285 + u16 boot_cs;
13286 u16 gdt_limit;
13287 u32 gdt_base;
13288 #else
13289 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
13290 index a82c4f1..f9c9696 100644
13291 --- a/arch/x86/include/asm/reboot.h
13292 +++ b/arch/x86/include/asm/reboot.h
13293 @@ -6,12 +6,12 @@
13294 struct pt_regs;
13295
13296 struct machine_ops {
13297 - void (*restart)(char *cmd);
13298 - void (*halt)(void);
13299 - void (*power_off)(void);
13300 + void (* __noreturn restart)(char *cmd);
13301 + void (* __noreturn halt)(void);
13302 + void (* __noreturn power_off)(void);
13303 void (*shutdown)(void);
13304 void (*crash_shutdown)(struct pt_regs *);
13305 - void (*emergency_restart)(void);
13306 + void (* __noreturn emergency_restart)(void);
13307 };
13308
13309 extern struct machine_ops machine_ops;
13310 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
13311 index 2dbe4a7..ce1db00 100644
13312 --- a/arch/x86/include/asm/rwsem.h
13313 +++ b/arch/x86/include/asm/rwsem.h
13314 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
13315 {
13316 asm volatile("# beginning down_read\n\t"
13317 LOCK_PREFIX _ASM_INC "(%1)\n\t"
13318 +
13319 +#ifdef CONFIG_PAX_REFCOUNT
13320 + "jno 0f\n"
13321 + LOCK_PREFIX _ASM_DEC "(%1)\n"
13322 + "int $4\n0:\n"
13323 + _ASM_EXTABLE(0b, 0b)
13324 +#endif
13325 +
13326 /* adds 0x00000001 */
13327 " jns 1f\n"
13328 " call call_rwsem_down_read_failed\n"
13329 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
13330 "1:\n\t"
13331 " mov %1,%2\n\t"
13332 " add %3,%2\n\t"
13333 +
13334 +#ifdef CONFIG_PAX_REFCOUNT
13335 + "jno 0f\n"
13336 + "sub %3,%2\n"
13337 + "int $4\n0:\n"
13338 + _ASM_EXTABLE(0b, 0b)
13339 +#endif
13340 +
13341 " jle 2f\n\t"
13342 LOCK_PREFIX " cmpxchg %2,%0\n\t"
13343 " jnz 1b\n\t"
13344 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
13345 long tmp;
13346 asm volatile("# beginning down_write\n\t"
13347 LOCK_PREFIX " xadd %1,(%2)\n\t"
13348 +
13349 +#ifdef CONFIG_PAX_REFCOUNT
13350 + "jno 0f\n"
13351 + "mov %1,(%2)\n"
13352 + "int $4\n0:\n"
13353 + _ASM_EXTABLE(0b, 0b)
13354 +#endif
13355 +
13356 /* adds 0xffff0001, returns the old value */
13357 " test %1,%1\n\t"
13358 /* was the count 0 before? */
13359 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
13360 long tmp;
13361 asm volatile("# beginning __up_read\n\t"
13362 LOCK_PREFIX " xadd %1,(%2)\n\t"
13363 +
13364 +#ifdef CONFIG_PAX_REFCOUNT
13365 + "jno 0f\n"
13366 + "mov %1,(%2)\n"
13367 + "int $4\n0:\n"
13368 + _ASM_EXTABLE(0b, 0b)
13369 +#endif
13370 +
13371 /* subtracts 1, returns the old value */
13372 " jns 1f\n\t"
13373 " call call_rwsem_wake\n" /* expects old value in %edx */
13374 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
13375 long tmp;
13376 asm volatile("# beginning __up_write\n\t"
13377 LOCK_PREFIX " xadd %1,(%2)\n\t"
13378 +
13379 +#ifdef CONFIG_PAX_REFCOUNT
13380 + "jno 0f\n"
13381 + "mov %1,(%2)\n"
13382 + "int $4\n0:\n"
13383 + _ASM_EXTABLE(0b, 0b)
13384 +#endif
13385 +
13386 /* subtracts 0xffff0001, returns the old value */
13387 " jns 1f\n\t"
13388 " call call_rwsem_wake\n" /* expects old value in %edx */
13389 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
13390 {
13391 asm volatile("# beginning __downgrade_write\n\t"
13392 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
13393 +
13394 +#ifdef CONFIG_PAX_REFCOUNT
13395 + "jno 0f\n"
13396 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
13397 + "int $4\n0:\n"
13398 + _ASM_EXTABLE(0b, 0b)
13399 +#endif
13400 +
13401 /*
13402 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
13403 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
13404 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
13405 */
13406 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
13407 {
13408 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
13409 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
13410 +
13411 +#ifdef CONFIG_PAX_REFCOUNT
13412 + "jno 0f\n"
13413 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
13414 + "int $4\n0:\n"
13415 + _ASM_EXTABLE(0b, 0b)
13416 +#endif
13417 +
13418 : "+m" (sem->count)
13419 : "er" (delta));
13420 }
13421 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
13422 */
13423 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
13424 {
13425 - return delta + xadd(&sem->count, delta);
13426 + return delta + xadd_check_overflow(&sem->count, delta);
13427 }
13428
13429 #endif /* __KERNEL__ */
13430 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
13431 index c48a950..c6d7468 100644
13432 --- a/arch/x86/include/asm/segment.h
13433 +++ b/arch/x86/include/asm/segment.h
13434 @@ -64,10 +64,15 @@
13435 * 26 - ESPFIX small SS
13436 * 27 - per-cpu [ offset to per-cpu data area ]
13437 * 28 - stack_canary-20 [ for stack protector ]
13438 - * 29 - unused
13439 - * 30 - unused
13440 + * 29 - PCI BIOS CS
13441 + * 30 - PCI BIOS DS
13442 * 31 - TSS for double fault handler
13443 */
13444 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
13445 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
13446 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
13447 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
13448 +
13449 #define GDT_ENTRY_TLS_MIN 6
13450 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
13451
13452 @@ -79,6 +84,8 @@
13453
13454 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
13455
13456 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
13457 +
13458 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
13459
13460 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
13461 @@ -104,6 +111,12 @@
13462 #define __KERNEL_STACK_CANARY 0
13463 #endif
13464
13465 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
13466 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
13467 +
13468 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
13469 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
13470 +
13471 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
13472
13473 /*
13474 @@ -141,7 +154,7 @@
13475 */
13476
13477 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
13478 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
13479 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
13480
13481
13482 #else
13483 @@ -165,6 +178,8 @@
13484 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
13485 #define __USER32_DS __USER_DS
13486
13487 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
13488 +
13489 #define GDT_ENTRY_TSS 8 /* needs two entries */
13490 #define GDT_ENTRY_LDT 10 /* needs two entries */
13491 #define GDT_ENTRY_TLS_MIN 12
13492 @@ -185,6 +200,7 @@
13493 #endif
13494
13495 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
13496 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
13497 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
13498 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
13499 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
13500 @@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
13501 {
13502 unsigned long __limit;
13503 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
13504 - return __limit + 1;
13505 + return __limit;
13506 }
13507
13508 #endif /* !__ASSEMBLY__ */
13509 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
13510 index 4f19a15..e04d86f 100644
13511 --- a/arch/x86/include/asm/smp.h
13512 +++ b/arch/x86/include/asm/smp.h
13513 @@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
13514 /* cpus sharing the last level cache: */
13515 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
13516 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
13517 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
13518 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
13519
13520 static inline struct cpumask *cpu_sibling_mask(int cpu)
13521 {
13522 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus __cpuinitdata;
13523 extern int safe_smp_processor_id(void);
13524
13525 #elif defined(CONFIG_X86_64_SMP)
13526 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
13527 -
13528 -#define stack_smp_processor_id() \
13529 -({ \
13530 - struct thread_info *ti; \
13531 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
13532 - ti->cpu; \
13533 -})
13534 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
13535 +#define stack_smp_processor_id() raw_smp_processor_id()
13536 #define safe_smp_processor_id() smp_processor_id()
13537
13538 #endif
13539 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
13540 index 33692ea..350a534 100644
13541 --- a/arch/x86/include/asm/spinlock.h
13542 +++ b/arch/x86/include/asm/spinlock.h
13543 @@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
13544 static inline void arch_read_lock(arch_rwlock_t *rw)
13545 {
13546 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
13547 +
13548 +#ifdef CONFIG_PAX_REFCOUNT
13549 + "jno 0f\n"
13550 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
13551 + "int $4\n0:\n"
13552 + _ASM_EXTABLE(0b, 0b)
13553 +#endif
13554 +
13555 "jns 1f\n"
13556 "call __read_lock_failed\n\t"
13557 "1:\n"
13558 @@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
13559 static inline void arch_write_lock(arch_rwlock_t *rw)
13560 {
13561 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
13562 +
13563 +#ifdef CONFIG_PAX_REFCOUNT
13564 + "jno 0f\n"
13565 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
13566 + "int $4\n0:\n"
13567 + _ASM_EXTABLE(0b, 0b)
13568 +#endif
13569 +
13570 "jz 1f\n"
13571 "call __write_lock_failed\n\t"
13572 "1:\n"
13573 @@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
13574
13575 static inline void arch_read_unlock(arch_rwlock_t *rw)
13576 {
13577 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
13578 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
13579 +
13580 +#ifdef CONFIG_PAX_REFCOUNT
13581 + "jno 0f\n"
13582 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
13583 + "int $4\n0:\n"
13584 + _ASM_EXTABLE(0b, 0b)
13585 +#endif
13586 +
13587 :"+m" (rw->lock) : : "memory");
13588 }
13589
13590 static inline void arch_write_unlock(arch_rwlock_t *rw)
13591 {
13592 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
13593 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
13594 +
13595 +#ifdef CONFIG_PAX_REFCOUNT
13596 + "jno 0f\n"
13597 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
13598 + "int $4\n0:\n"
13599 + _ASM_EXTABLE(0b, 0b)
13600 +#endif
13601 +
13602 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
13603 }
13604
13605 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
13606 index 6a99859..03cb807 100644
13607 --- a/arch/x86/include/asm/stackprotector.h
13608 +++ b/arch/x86/include/asm/stackprotector.h
13609 @@ -47,7 +47,7 @@
13610 * head_32 for boot CPU and setup_per_cpu_areas() for others.
13611 */
13612 #define GDT_STACK_CANARY_INIT \
13613 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
13614 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
13615
13616 /*
13617 * Initialize the stackprotector canary value.
13618 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
13619
13620 static inline void load_stack_canary_segment(void)
13621 {
13622 -#ifdef CONFIG_X86_32
13623 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
13624 asm volatile ("mov %0, %%gs" : : "r" (0));
13625 #endif
13626 }
13627 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
13628 index 70bbe39..4ae2bd4 100644
13629 --- a/arch/x86/include/asm/stacktrace.h
13630 +++ b/arch/x86/include/asm/stacktrace.h
13631 @@ -11,28 +11,20 @@
13632
13633 extern int kstack_depth_to_print;
13634
13635 -struct thread_info;
13636 +struct task_struct;
13637 struct stacktrace_ops;
13638
13639 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
13640 - unsigned long *stack,
13641 - unsigned long bp,
13642 - const struct stacktrace_ops *ops,
13643 - void *data,
13644 - unsigned long *end,
13645 - int *graph);
13646 +typedef unsigned long walk_stack_t(struct task_struct *task,
13647 + void *stack_start,
13648 + unsigned long *stack,
13649 + unsigned long bp,
13650 + const struct stacktrace_ops *ops,
13651 + void *data,
13652 + unsigned long *end,
13653 + int *graph);
13654
13655 -extern unsigned long
13656 -print_context_stack(struct thread_info *tinfo,
13657 - unsigned long *stack, unsigned long bp,
13658 - const struct stacktrace_ops *ops, void *data,
13659 - unsigned long *end, int *graph);
13660 -
13661 -extern unsigned long
13662 -print_context_stack_bp(struct thread_info *tinfo,
13663 - unsigned long *stack, unsigned long bp,
13664 - const struct stacktrace_ops *ops, void *data,
13665 - unsigned long *end, int *graph);
13666 +extern walk_stack_t print_context_stack;
13667 +extern walk_stack_t print_context_stack_bp;
13668
13669 /* Generic stack tracer with callbacks */
13670
13671 @@ -40,7 +32,7 @@ struct stacktrace_ops {
13672 void (*address)(void *data, unsigned long address, int reliable);
13673 /* On negative return stop dumping */
13674 int (*stack)(void *data, char *name);
13675 - walk_stack_t walk_stack;
13676 + walk_stack_t *walk_stack;
13677 };
13678
13679 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
13680 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
13681 index 4ec45b3..a4f0a8a 100644
13682 --- a/arch/x86/include/asm/switch_to.h
13683 +++ b/arch/x86/include/asm/switch_to.h
13684 @@ -108,7 +108,7 @@ do { \
13685 "call __switch_to\n\t" \
13686 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
13687 __switch_canary \
13688 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
13689 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
13690 "movq %%rax,%%rdi\n\t" \
13691 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
13692 "jnz ret_from_fork\n\t" \
13693 @@ -119,7 +119,7 @@ do { \
13694 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
13695 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
13696 [_tif_fork] "i" (_TIF_FORK), \
13697 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
13698 + [thread_info] "m" (current_tinfo), \
13699 [current_task] "m" (current_task) \
13700 __switch_canary_iparam \
13701 : "memory", "cc" __EXTRA_CLOBBER)
13702 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
13703 index 2d946e6..e453ec4 100644
13704 --- a/arch/x86/include/asm/thread_info.h
13705 +++ b/arch/x86/include/asm/thread_info.h
13706 @@ -10,6 +10,7 @@
13707 #include <linux/compiler.h>
13708 #include <asm/page.h>
13709 #include <asm/types.h>
13710 +#include <asm/percpu.h>
13711
13712 /*
13713 * low level task data that entry.S needs immediate access to
13714 @@ -24,7 +25,6 @@ struct exec_domain;
13715 #include <linux/atomic.h>
13716
13717 struct thread_info {
13718 - struct task_struct *task; /* main task structure */
13719 struct exec_domain *exec_domain; /* execution domain */
13720 __u32 flags; /* low level flags */
13721 __u32 status; /* thread synchronous flags */
13722 @@ -34,19 +34,13 @@ struct thread_info {
13723 mm_segment_t addr_limit;
13724 struct restart_block restart_block;
13725 void __user *sysenter_return;
13726 -#ifdef CONFIG_X86_32
13727 - unsigned long previous_esp; /* ESP of the previous stack in
13728 - case of nested (IRQ) stacks
13729 - */
13730 - __u8 supervisor_stack[0];
13731 -#endif
13732 + unsigned long lowest_stack;
13733 unsigned int sig_on_uaccess_error:1;
13734 unsigned int uaccess_err:1; /* uaccess failed */
13735 };
13736
13737 -#define INIT_THREAD_INFO(tsk) \
13738 +#define INIT_THREAD_INFO \
13739 { \
13740 - .task = &tsk, \
13741 .exec_domain = &default_exec_domain, \
13742 .flags = 0, \
13743 .cpu = 0, \
13744 @@ -57,7 +51,7 @@ struct thread_info {
13745 }, \
13746 }
13747
13748 -#define init_thread_info (init_thread_union.thread_info)
13749 +#define init_thread_info (init_thread_union.stack)
13750 #define init_stack (init_thread_union.stack)
13751
13752 #else /* !__ASSEMBLY__ */
13753 @@ -98,6 +92,7 @@ struct thread_info {
13754 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
13755 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
13756 #define TIF_X32 30 /* 32-bit native x86-64 binary */
13757 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
13758
13759 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
13760 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
13761 @@ -122,17 +117,18 @@ struct thread_info {
13762 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
13763 #define _TIF_ADDR32 (1 << TIF_ADDR32)
13764 #define _TIF_X32 (1 << TIF_X32)
13765 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
13766
13767 /* work to do in syscall_trace_enter() */
13768 #define _TIF_WORK_SYSCALL_ENTRY \
13769 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
13770 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
13771 - _TIF_NOHZ)
13772 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
13773
13774 /* work to do in syscall_trace_leave() */
13775 #define _TIF_WORK_SYSCALL_EXIT \
13776 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
13777 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
13778 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
13779
13780 /* work to do on interrupt/exception return */
13781 #define _TIF_WORK_MASK \
13782 @@ -143,7 +139,7 @@ struct thread_info {
13783 /* work to do on any return to user space */
13784 #define _TIF_ALLWORK_MASK \
13785 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
13786 - _TIF_NOHZ)
13787 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
13788
13789 /* Only used for 64 bit */
13790 #define _TIF_DO_NOTIFY_MASK \
13791 @@ -159,45 +155,40 @@ struct thread_info {
13792
13793 #define PREEMPT_ACTIVE 0x10000000
13794
13795 -#ifdef CONFIG_X86_32
13796 -
13797 -#define STACK_WARN (THREAD_SIZE/8)
13798 -/*
13799 - * macros/functions for gaining access to the thread information structure
13800 - *
13801 - * preempt_count needs to be 1 initially, until the scheduler is functional.
13802 - */
13803 -#ifndef __ASSEMBLY__
13804 -
13805 -
13806 -/* how to get the current stack pointer from C */
13807 -register unsigned long current_stack_pointer asm("esp") __used;
13808 -
13809 -/* how to get the thread information struct from C */
13810 -static inline struct thread_info *current_thread_info(void)
13811 -{
13812 - return (struct thread_info *)
13813 - (current_stack_pointer & ~(THREAD_SIZE - 1));
13814 -}
13815 -
13816 -#else /* !__ASSEMBLY__ */
13817 -
13818 +#ifdef __ASSEMBLY__
13819 /* how to get the thread information struct from ASM */
13820 #define GET_THREAD_INFO(reg) \
13821 - movl $-THREAD_SIZE, reg; \
13822 - andl %esp, reg
13823 + mov PER_CPU_VAR(current_tinfo), reg
13824
13825 /* use this one if reg already contains %esp */
13826 -#define GET_THREAD_INFO_WITH_ESP(reg) \
13827 - andl $-THREAD_SIZE, reg
13828 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
13829 +#else
13830 +/* how to get the thread information struct from C */
13831 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
13832 +
13833 +static __always_inline struct thread_info *current_thread_info(void)
13834 +{
13835 + return this_cpu_read_stable(current_tinfo);
13836 +}
13837 +#endif
13838 +
13839 +#ifdef CONFIG_X86_32
13840 +
13841 +#define STACK_WARN (THREAD_SIZE/8)
13842 +/*
13843 + * macros/functions for gaining access to the thread information structure
13844 + *
13845 + * preempt_count needs to be 1 initially, until the scheduler is functional.
13846 + */
13847 +#ifndef __ASSEMBLY__
13848 +
13849 +/* how to get the current stack pointer from C */
13850 +register unsigned long current_stack_pointer asm("esp") __used;
13851
13852 #endif
13853
13854 #else /* X86_32 */
13855
13856 -#include <asm/percpu.h>
13857 -#define KERNEL_STACK_OFFSET (5*8)
13858 -
13859 /*
13860 * macros/functions for gaining access to the thread information structure
13861 * preempt_count needs to be 1 initially, until the scheduler is functional.
13862 @@ -205,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
13863 #ifndef __ASSEMBLY__
13864 DECLARE_PER_CPU(unsigned long, kernel_stack);
13865
13866 -static inline struct thread_info *current_thread_info(void)
13867 -{
13868 - struct thread_info *ti;
13869 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
13870 - KERNEL_STACK_OFFSET - THREAD_SIZE);
13871 - return ti;
13872 -}
13873 -
13874 -#else /* !__ASSEMBLY__ */
13875 -
13876 -/* how to get the thread information struct from ASM */
13877 -#define GET_THREAD_INFO(reg) \
13878 - movq PER_CPU_VAR(kernel_stack),reg ; \
13879 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
13880 -
13881 -/*
13882 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
13883 - * a certain register (to be used in assembler memory operands).
13884 - */
13885 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
13886 -
13887 +/* how to get the current stack pointer from C */
13888 +register unsigned long current_stack_pointer asm("rsp") __used;
13889 #endif
13890
13891 #endif /* !X86_32 */
13892 @@ -286,5 +258,12 @@ static inline bool is_ia32_task(void)
13893 extern void arch_task_cache_init(void);
13894 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
13895 extern void arch_release_task_struct(struct task_struct *tsk);
13896 +
13897 +#define __HAVE_THREAD_FUNCTIONS
13898 +#define task_thread_info(task) (&(task)->tinfo)
13899 +#define task_stack_page(task) ((task)->stack)
13900 +#define setup_thread_stack(p, org) do {} while (0)
13901 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
13902 +
13903 #endif
13904 #endif /* _ASM_X86_THREAD_INFO_H */
13905 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
13906 index 7ccf8d1..9a18110 100644
13907 --- a/arch/x86/include/asm/uaccess.h
13908 +++ b/arch/x86/include/asm/uaccess.h
13909 @@ -7,6 +7,7 @@
13910 #include <linux/compiler.h>
13911 #include <linux/thread_info.h>
13912 #include <linux/string.h>
13913 +#include <linux/sched.h>
13914 #include <asm/asm.h>
13915 #include <asm/page.h>
13916 #include <asm/smap.h>
13917 @@ -29,7 +30,12 @@
13918
13919 #define get_ds() (KERNEL_DS)
13920 #define get_fs() (current_thread_info()->addr_limit)
13921 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
13922 +void __set_fs(mm_segment_t x);
13923 +void set_fs(mm_segment_t x);
13924 +#else
13925 #define set_fs(x) (current_thread_info()->addr_limit = (x))
13926 +#endif
13927
13928 #define segment_eq(a, b) ((a).seg == (b).seg)
13929
13930 @@ -77,8 +83,33 @@
13931 * checks that the pointer is in the user space range - after calling
13932 * this function, memory access functions may still return -EFAULT.
13933 */
13934 -#define access_ok(type, addr, size) \
13935 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
13936 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
13937 +#define access_ok(type, addr, size) \
13938 +({ \
13939 + long __size = size; \
13940 + unsigned long __addr = (unsigned long)addr; \
13941 + unsigned long __addr_ao = __addr & PAGE_MASK; \
13942 + unsigned long __end_ao = __addr + __size - 1; \
13943 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
13944 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
13945 + while(__addr_ao <= __end_ao) { \
13946 + char __c_ao; \
13947 + __addr_ao += PAGE_SIZE; \
13948 + if (__size > PAGE_SIZE) \
13949 + cond_resched(); \
13950 + if (__get_user(__c_ao, (char __user *)__addr)) \
13951 + break; \
13952 + if (type != VERIFY_WRITE) { \
13953 + __addr = __addr_ao; \
13954 + continue; \
13955 + } \
13956 + if (__put_user(__c_ao, (char __user *)__addr)) \
13957 + break; \
13958 + __addr = __addr_ao; \
13959 + } \
13960 + } \
13961 + __ret_ao; \
13962 +})
13963
13964 /*
13965 * The exception table consists of pairs of addresses relative to the
13966 @@ -189,13 +220,21 @@ extern int __get_user_bad(void);
13967 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
13968 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
13969
13970 -
13971 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
13972 +#define __copyuser_seg "gs;"
13973 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
13974 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
13975 +#else
13976 +#define __copyuser_seg
13977 +#define __COPYUSER_SET_ES
13978 +#define __COPYUSER_RESTORE_ES
13979 +#endif
13980
13981 #ifdef CONFIG_X86_32
13982 #define __put_user_asm_u64(x, addr, err, errret) \
13983 asm volatile(ASM_STAC "\n" \
13984 - "1: movl %%eax,0(%2)\n" \
13985 - "2: movl %%edx,4(%2)\n" \
13986 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
13987 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
13988 "3: " ASM_CLAC "\n" \
13989 ".section .fixup,\"ax\"\n" \
13990 "4: movl %3,%0\n" \
13991 @@ -208,8 +247,8 @@ extern int __get_user_bad(void);
13992
13993 #define __put_user_asm_ex_u64(x, addr) \
13994 asm volatile(ASM_STAC "\n" \
13995 - "1: movl %%eax,0(%1)\n" \
13996 - "2: movl %%edx,4(%1)\n" \
13997 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
13998 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
13999 "3: " ASM_CLAC "\n" \
14000 _ASM_EXTABLE_EX(1b, 2b) \
14001 _ASM_EXTABLE_EX(2b, 3b) \
14002 @@ -261,7 +300,7 @@ extern void __put_user_8(void);
14003 __typeof__(*(ptr)) __pu_val; \
14004 __chk_user_ptr(ptr); \
14005 might_fault(); \
14006 - __pu_val = x; \
14007 + __pu_val = (x); \
14008 switch (sizeof(*(ptr))) { \
14009 case 1: \
14010 __put_user_x(1, __pu_val, ptr, __ret_pu); \
14011 @@ -383,7 +422,7 @@ do { \
14012
14013 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
14014 asm volatile(ASM_STAC "\n" \
14015 - "1: mov"itype" %2,%"rtype"1\n" \
14016 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
14017 "2: " ASM_CLAC "\n" \
14018 ".section .fixup,\"ax\"\n" \
14019 "3: mov %3,%0\n" \
14020 @@ -391,7 +430,7 @@ do { \
14021 " jmp 2b\n" \
14022 ".previous\n" \
14023 _ASM_EXTABLE(1b, 3b) \
14024 - : "=r" (err), ltype(x) \
14025 + : "=r" (err), ltype (x) \
14026 : "m" (__m(addr)), "i" (errret), "0" (err))
14027
14028 #define __get_user_size_ex(x, ptr, size) \
14029 @@ -416,7 +455,7 @@ do { \
14030 } while (0)
14031
14032 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
14033 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
14034 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
14035 "2:\n" \
14036 _ASM_EXTABLE_EX(1b, 2b) \
14037 : ltype(x) : "m" (__m(addr)))
14038 @@ -433,13 +472,24 @@ do { \
14039 int __gu_err; \
14040 unsigned long __gu_val; \
14041 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
14042 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
14043 + (x) = (__typeof__(*(ptr)))__gu_val; \
14044 __gu_err; \
14045 })
14046
14047 /* FIXME: this hack is definitely wrong -AK */
14048 struct __large_struct { unsigned long buf[100]; };
14049 -#define __m(x) (*(struct __large_struct __user *)(x))
14050 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14051 +#define ____m(x) \
14052 +({ \
14053 + unsigned long ____x = (unsigned long)(x); \
14054 + if (____x < PAX_USER_SHADOW_BASE) \
14055 + ____x += PAX_USER_SHADOW_BASE; \
14056 + (void __user *)____x; \
14057 +})
14058 +#else
14059 +#define ____m(x) (x)
14060 +#endif
14061 +#define __m(x) (*(struct __large_struct __user *)____m(x))
14062
14063 /*
14064 * Tell gcc we read from memory instead of writing: this is because
14065 @@ -448,7 +498,7 @@ struct __large_struct { unsigned long buf[100]; };
14066 */
14067 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
14068 asm volatile(ASM_STAC "\n" \
14069 - "1: mov"itype" %"rtype"1,%2\n" \
14070 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
14071 "2: " ASM_CLAC "\n" \
14072 ".section .fixup,\"ax\"\n" \
14073 "3: mov %3,%0\n" \
14074 @@ -456,10 +506,10 @@ struct __large_struct { unsigned long buf[100]; };
14075 ".previous\n" \
14076 _ASM_EXTABLE(1b, 3b) \
14077 : "=r"(err) \
14078 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
14079 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
14080
14081 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
14082 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
14083 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
14084 "2:\n" \
14085 _ASM_EXTABLE_EX(1b, 2b) \
14086 : : ltype(x), "m" (__m(addr)))
14087 @@ -498,8 +548,12 @@ struct __large_struct { unsigned long buf[100]; };
14088 * On error, the variable @x is set to zero.
14089 */
14090
14091 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14092 +#define __get_user(x, ptr) get_user((x), (ptr))
14093 +#else
14094 #define __get_user(x, ptr) \
14095 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
14096 +#endif
14097
14098 /**
14099 * __put_user: - Write a simple value into user space, with less checking.
14100 @@ -521,8 +575,12 @@ struct __large_struct { unsigned long buf[100]; };
14101 * Returns zero on success, or -EFAULT on error.
14102 */
14103
14104 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14105 +#define __put_user(x, ptr) put_user((x), (ptr))
14106 +#else
14107 #define __put_user(x, ptr) \
14108 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
14109 +#endif
14110
14111 #define __get_user_unaligned __get_user
14112 #define __put_user_unaligned __put_user
14113 @@ -540,7 +598,7 @@ struct __large_struct { unsigned long buf[100]; };
14114 #define get_user_ex(x, ptr) do { \
14115 unsigned long __gue_val; \
14116 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
14117 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
14118 + (x) = (__typeof__(*(ptr)))__gue_val; \
14119 } while (0)
14120
14121 #ifdef CONFIG_X86_WP_WORKS_OK
14122 @@ -574,8 +632,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
14123 extern __must_check long strlen_user(const char __user *str);
14124 extern __must_check long strnlen_user(const char __user *str, long n);
14125
14126 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
14127 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
14128 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
14129 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
14130
14131 /*
14132 * movsl can be slow when source and dest are not both 8-byte aligned
14133 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
14134 index 7f760a9..04b1c65 100644
14135 --- a/arch/x86/include/asm/uaccess_32.h
14136 +++ b/arch/x86/include/asm/uaccess_32.h
14137 @@ -11,15 +11,15 @@
14138 #include <asm/page.h>
14139
14140 unsigned long __must_check __copy_to_user_ll
14141 - (void __user *to, const void *from, unsigned long n);
14142 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
14143 unsigned long __must_check __copy_from_user_ll
14144 - (void *to, const void __user *from, unsigned long n);
14145 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14146 unsigned long __must_check __copy_from_user_ll_nozero
14147 - (void *to, const void __user *from, unsigned long n);
14148 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14149 unsigned long __must_check __copy_from_user_ll_nocache
14150 - (void *to, const void __user *from, unsigned long n);
14151 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14152 unsigned long __must_check __copy_from_user_ll_nocache_nozero
14153 - (void *to, const void __user *from, unsigned long n);
14154 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14155
14156 /**
14157 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
14158 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
14159 static __always_inline unsigned long __must_check
14160 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
14161 {
14162 + if ((long)n < 0)
14163 + return n;
14164 +
14165 + check_object_size(from, n, true);
14166 +
14167 if (__builtin_constant_p(n)) {
14168 unsigned long ret;
14169
14170 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
14171 __copy_to_user(void __user *to, const void *from, unsigned long n)
14172 {
14173 might_fault();
14174 +
14175 return __copy_to_user_inatomic(to, from, n);
14176 }
14177
14178 static __always_inline unsigned long
14179 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
14180 {
14181 + if ((long)n < 0)
14182 + return n;
14183 +
14184 /* Avoid zeroing the tail if the copy fails..
14185 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
14186 * but as the zeroing behaviour is only significant when n is not
14187 @@ -137,6 +146,12 @@ static __always_inline unsigned long
14188 __copy_from_user(void *to, const void __user *from, unsigned long n)
14189 {
14190 might_fault();
14191 +
14192 + if ((long)n < 0)
14193 + return n;
14194 +
14195 + check_object_size(to, n, false);
14196 +
14197 if (__builtin_constant_p(n)) {
14198 unsigned long ret;
14199
14200 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
14201 const void __user *from, unsigned long n)
14202 {
14203 might_fault();
14204 +
14205 + if ((long)n < 0)
14206 + return n;
14207 +
14208 if (__builtin_constant_p(n)) {
14209 unsigned long ret;
14210
14211 @@ -181,15 +200,19 @@ static __always_inline unsigned long
14212 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
14213 unsigned long n)
14214 {
14215 - return __copy_from_user_ll_nocache_nozero(to, from, n);
14216 + if ((long)n < 0)
14217 + return n;
14218 +
14219 + return __copy_from_user_ll_nocache_nozero(to, from, n);
14220 }
14221
14222 -unsigned long __must_check copy_to_user(void __user *to,
14223 - const void *from, unsigned long n);
14224 -unsigned long __must_check _copy_from_user(void *to,
14225 - const void __user *from,
14226 - unsigned long n);
14227 -
14228 +extern void copy_to_user_overflow(void)
14229 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14230 + __compiletime_error("copy_to_user() buffer size is not provably correct")
14231 +#else
14232 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
14233 +#endif
14234 +;
14235
14236 extern void copy_from_user_overflow(void)
14237 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14238 @@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
14239 #endif
14240 ;
14241
14242 -static inline unsigned long __must_check copy_from_user(void *to,
14243 - const void __user *from,
14244 - unsigned long n)
14245 +/**
14246 + * copy_to_user: - Copy a block of data into user space.
14247 + * @to: Destination address, in user space.
14248 + * @from: Source address, in kernel space.
14249 + * @n: Number of bytes to copy.
14250 + *
14251 + * Context: User context only. This function may sleep.
14252 + *
14253 + * Copy data from kernel space to user space.
14254 + *
14255 + * Returns number of bytes that could not be copied.
14256 + * On success, this will be zero.
14257 + */
14258 +static inline unsigned long __must_check
14259 +copy_to_user(void __user *to, const void *from, unsigned long n)
14260 {
14261 - int sz = __compiletime_object_size(to);
14262 + size_t sz = __compiletime_object_size(from);
14263
14264 - if (likely(sz == -1 || sz >= n))
14265 - n = _copy_from_user(to, from, n);
14266 - else
14267 + if (unlikely(sz != (size_t)-1 && sz < n))
14268 + copy_to_user_overflow();
14269 + else if (access_ok(VERIFY_WRITE, to, n))
14270 + n = __copy_to_user(to, from, n);
14271 + return n;
14272 +}
14273 +
14274 +/**
14275 + * copy_from_user: - Copy a block of data from user space.
14276 + * @to: Destination address, in kernel space.
14277 + * @from: Source address, in user space.
14278 + * @n: Number of bytes to copy.
14279 + *
14280 + * Context: User context only. This function may sleep.
14281 + *
14282 + * Copy data from user space to kernel space.
14283 + *
14284 + * Returns number of bytes that could not be copied.
14285 + * On success, this will be zero.
14286 + *
14287 + * If some data could not be copied, this function will pad the copied
14288 + * data to the requested size using zero bytes.
14289 + */
14290 +static inline unsigned long __must_check
14291 +copy_from_user(void *to, const void __user *from, unsigned long n)
14292 +{
14293 + size_t sz = __compiletime_object_size(to);
14294 +
14295 + check_object_size(to, n, false);
14296 +
14297 + if (unlikely(sz != (size_t)-1 && sz < n))
14298 copy_from_user_overflow();
14299 -
14300 + else if (access_ok(VERIFY_READ, from, n))
14301 + n = __copy_from_user(to, from, n);
14302 + else if ((long)n > 0)
14303 + memset(to, 0, n);
14304 return n;
14305 }
14306
14307 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
14308 index 142810c..4b68a3e 100644
14309 --- a/arch/x86/include/asm/uaccess_64.h
14310 +++ b/arch/x86/include/asm/uaccess_64.h
14311 @@ -10,6 +10,9 @@
14312 #include <asm/alternative.h>
14313 #include <asm/cpufeature.h>
14314 #include <asm/page.h>
14315 +#include <asm/pgtable.h>
14316 +
14317 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
14318
14319 /*
14320 * Copy To/From Userspace
14321 @@ -17,13 +20,13 @@
14322
14323 /* Handles exceptions in both to and from, but doesn't do access_ok */
14324 __must_check unsigned long
14325 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
14326 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
14327 __must_check unsigned long
14328 -copy_user_generic_string(void *to, const void *from, unsigned len);
14329 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
14330 __must_check unsigned long
14331 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
14332 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
14333
14334 -static __always_inline __must_check unsigned long
14335 +static __always_inline __must_check __size_overflow(3) unsigned long
14336 copy_user_generic(void *to, const void *from, unsigned len)
14337 {
14338 unsigned ret;
14339 @@ -41,142 +44,203 @@ copy_user_generic(void *to, const void *from, unsigned len)
14340 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
14341 "=d" (len)),
14342 "1" (to), "2" (from), "3" (len)
14343 - : "memory", "rcx", "r8", "r9", "r10", "r11");
14344 + : "memory", "rcx", "r8", "r9", "r11");
14345 return ret;
14346 }
14347
14348 +static __always_inline __must_check unsigned long
14349 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
14350 +static __always_inline __must_check unsigned long
14351 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
14352 __must_check unsigned long
14353 -_copy_to_user(void __user *to, const void *from, unsigned len);
14354 -__must_check unsigned long
14355 -_copy_from_user(void *to, const void __user *from, unsigned len);
14356 -__must_check unsigned long
14357 -copy_in_user(void __user *to, const void __user *from, unsigned len);
14358 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
14359 +
14360 +extern void copy_to_user_overflow(void)
14361 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14362 + __compiletime_error("copy_to_user() buffer size is not provably correct")
14363 +#else
14364 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
14365 +#endif
14366 +;
14367 +
14368 +extern void copy_from_user_overflow(void)
14369 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14370 + __compiletime_error("copy_from_user() buffer size is not provably correct")
14371 +#else
14372 + __compiletime_warning("copy_from_user() buffer size is not provably correct")
14373 +#endif
14374 +;
14375
14376 static inline unsigned long __must_check copy_from_user(void *to,
14377 const void __user *from,
14378 unsigned long n)
14379 {
14380 - int sz = __compiletime_object_size(to);
14381 -
14382 might_fault();
14383 - if (likely(sz == -1 || sz >= n))
14384 - n = _copy_from_user(to, from, n);
14385 -#ifdef CONFIG_DEBUG_VM
14386 - else
14387 - WARN(1, "Buffer overflow detected!\n");
14388 -#endif
14389 +
14390 + check_object_size(to, n, false);
14391 + if (access_ok(VERIFY_READ, from, n))
14392 + n = __copy_from_user(to, from, n);
14393 + else if (n < INT_MAX)
14394 + memset(to, 0, n);
14395 return n;
14396 }
14397
14398 static __always_inline __must_check
14399 -int copy_to_user(void __user *dst, const void *src, unsigned size)
14400 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
14401 {
14402 might_fault();
14403
14404 - return _copy_to_user(dst, src, size);
14405 + if (access_ok(VERIFY_WRITE, dst, size))
14406 + size = __copy_to_user(dst, src, size);
14407 + return size;
14408 }
14409
14410 static __always_inline __must_check
14411 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
14412 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
14413 {
14414 - int ret = 0;
14415 + size_t sz = __compiletime_object_size(dst);
14416 + unsigned ret = 0;
14417
14418 might_fault();
14419 +
14420 + if (size > INT_MAX)
14421 + return size;
14422 +
14423 + check_object_size(dst, size, false);
14424 +
14425 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14426 + if (!__access_ok(VERIFY_READ, src, size))
14427 + return size;
14428 +#endif
14429 +
14430 + if (unlikely(sz != (size_t)-1 && sz < size)) {
14431 + copy_from_user_overflow();
14432 + return size;
14433 + }
14434 +
14435 if (!__builtin_constant_p(size))
14436 - return copy_user_generic(dst, (__force void *)src, size);
14437 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
14438 switch (size) {
14439 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
14440 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
14441 ret, "b", "b", "=q", 1);
14442 return ret;
14443 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
14444 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
14445 ret, "w", "w", "=r", 2);
14446 return ret;
14447 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
14448 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
14449 ret, "l", "k", "=r", 4);
14450 return ret;
14451 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
14452 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
14453 ret, "q", "", "=r", 8);
14454 return ret;
14455 case 10:
14456 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
14457 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
14458 ret, "q", "", "=r", 10);
14459 if (unlikely(ret))
14460 return ret;
14461 __get_user_asm(*(u16 *)(8 + (char *)dst),
14462 - (u16 __user *)(8 + (char __user *)src),
14463 + (const u16 __user *)(8 + (const char __user *)src),
14464 ret, "w", "w", "=r", 2);
14465 return ret;
14466 case 16:
14467 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
14468 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
14469 ret, "q", "", "=r", 16);
14470 if (unlikely(ret))
14471 return ret;
14472 __get_user_asm(*(u64 *)(8 + (char *)dst),
14473 - (u64 __user *)(8 + (char __user *)src),
14474 + (const u64 __user *)(8 + (const char __user *)src),
14475 ret, "q", "", "=r", 8);
14476 return ret;
14477 default:
14478 - return copy_user_generic(dst, (__force void *)src, size);
14479 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
14480 }
14481 }
14482
14483 static __always_inline __must_check
14484 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
14485 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
14486 {
14487 - int ret = 0;
14488 + size_t sz = __compiletime_object_size(src);
14489 + unsigned ret = 0;
14490
14491 might_fault();
14492 +
14493 + if (size > INT_MAX)
14494 + return size;
14495 +
14496 + check_object_size(src, size, true);
14497 +
14498 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14499 + if (!__access_ok(VERIFY_WRITE, dst, size))
14500 + return size;
14501 +#endif
14502 +
14503 + if (unlikely(sz != (size_t)-1 && sz < size)) {
14504 + copy_to_user_overflow();
14505 + return size;
14506 + }
14507 +
14508 if (!__builtin_constant_p(size))
14509 - return copy_user_generic((__force void *)dst, src, size);
14510 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
14511 switch (size) {
14512 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
14513 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
14514 ret, "b", "b", "iq", 1);
14515 return ret;
14516 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
14517 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
14518 ret, "w", "w", "ir", 2);
14519 return ret;
14520 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
14521 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
14522 ret, "l", "k", "ir", 4);
14523 return ret;
14524 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
14525 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
14526 ret, "q", "", "er", 8);
14527 return ret;
14528 case 10:
14529 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
14530 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
14531 ret, "q", "", "er", 10);
14532 if (unlikely(ret))
14533 return ret;
14534 asm("":::"memory");
14535 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
14536 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
14537 ret, "w", "w", "ir", 2);
14538 return ret;
14539 case 16:
14540 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
14541 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
14542 ret, "q", "", "er", 16);
14543 if (unlikely(ret))
14544 return ret;
14545 asm("":::"memory");
14546 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
14547 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
14548 ret, "q", "", "er", 8);
14549 return ret;
14550 default:
14551 - return copy_user_generic((__force void *)dst, src, size);
14552 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
14553 }
14554 }
14555
14556 static __always_inline __must_check
14557 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14558 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
14559 {
14560 - int ret = 0;
14561 + unsigned ret = 0;
14562
14563 might_fault();
14564 +
14565 + if (size > INT_MAX)
14566 + return size;
14567 +
14568 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14569 + if (!__access_ok(VERIFY_READ, src, size))
14570 + return size;
14571 + if (!__access_ok(VERIFY_WRITE, dst, size))
14572 + return size;
14573 +#endif
14574 +
14575 if (!__builtin_constant_p(size))
14576 - return copy_user_generic((__force void *)dst,
14577 - (__force void *)src, size);
14578 + return copy_user_generic((__force_kernel void *)____m(dst),
14579 + (__force_kernel const void *)____m(src), size);
14580 switch (size) {
14581 case 1: {
14582 u8 tmp;
14583 - __get_user_asm(tmp, (u8 __user *)src,
14584 + __get_user_asm(tmp, (const u8 __user *)src,
14585 ret, "b", "b", "=q", 1);
14586 if (likely(!ret))
14587 __put_user_asm(tmp, (u8 __user *)dst,
14588 @@ -185,7 +249,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14589 }
14590 case 2: {
14591 u16 tmp;
14592 - __get_user_asm(tmp, (u16 __user *)src,
14593 + __get_user_asm(tmp, (const u16 __user *)src,
14594 ret, "w", "w", "=r", 2);
14595 if (likely(!ret))
14596 __put_user_asm(tmp, (u16 __user *)dst,
14597 @@ -195,7 +259,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14598
14599 case 4: {
14600 u32 tmp;
14601 - __get_user_asm(tmp, (u32 __user *)src,
14602 + __get_user_asm(tmp, (const u32 __user *)src,
14603 ret, "l", "k", "=r", 4);
14604 if (likely(!ret))
14605 __put_user_asm(tmp, (u32 __user *)dst,
14606 @@ -204,7 +268,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14607 }
14608 case 8: {
14609 u64 tmp;
14610 - __get_user_asm(tmp, (u64 __user *)src,
14611 + __get_user_asm(tmp, (const u64 __user *)src,
14612 ret, "q", "", "=r", 8);
14613 if (likely(!ret))
14614 __put_user_asm(tmp, (u64 __user *)dst,
14615 @@ -212,41 +276,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14616 return ret;
14617 }
14618 default:
14619 - return copy_user_generic((__force void *)dst,
14620 - (__force void *)src, size);
14621 + return copy_user_generic((__force_kernel void *)____m(dst),
14622 + (__force_kernel const void *)____m(src), size);
14623 }
14624 }
14625
14626 static __must_check __always_inline int
14627 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
14628 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
14629 {
14630 - return copy_user_generic(dst, (__force const void *)src, size);
14631 + if (size > INT_MAX)
14632 + return size;
14633 +
14634 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14635 + if (!__access_ok(VERIFY_READ, src, size))
14636 + return size;
14637 +#endif
14638 +
14639 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
14640 }
14641
14642 -static __must_check __always_inline int
14643 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
14644 +static __must_check __always_inline unsigned long
14645 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
14646 {
14647 - return copy_user_generic((__force void *)dst, src, size);
14648 + if (size > INT_MAX)
14649 + return size;
14650 +
14651 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14652 + if (!__access_ok(VERIFY_WRITE, dst, size))
14653 + return size;
14654 +#endif
14655 +
14656 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
14657 }
14658
14659 -extern long __copy_user_nocache(void *dst, const void __user *src,
14660 - unsigned size, int zerorest);
14661 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
14662 + unsigned long size, int zerorest) __size_overflow(3);
14663
14664 -static inline int
14665 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
14666 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
14667 {
14668 might_sleep();
14669 +
14670 + if (size > INT_MAX)
14671 + return size;
14672 +
14673 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14674 + if (!__access_ok(VERIFY_READ, src, size))
14675 + return size;
14676 +#endif
14677 +
14678 return __copy_user_nocache(dst, src, size, 1);
14679 }
14680
14681 -static inline int
14682 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
14683 - unsigned size)
14684 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
14685 + unsigned long size)
14686 {
14687 + if (size > INT_MAX)
14688 + return size;
14689 +
14690 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14691 + if (!__access_ok(VERIFY_READ, src, size))
14692 + return size;
14693 +#endif
14694 +
14695 return __copy_user_nocache(dst, src, size, 0);
14696 }
14697
14698 -unsigned long
14699 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
14700 +extern unsigned long
14701 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
14702
14703 #endif /* _ASM_X86_UACCESS_64_H */
14704 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
14705 index 5b238981..77fdd78 100644
14706 --- a/arch/x86/include/asm/word-at-a-time.h
14707 +++ b/arch/x86/include/asm/word-at-a-time.h
14708 @@ -11,7 +11,7 @@
14709 * and shift, for example.
14710 */
14711 struct word_at_a_time {
14712 - const unsigned long one_bits, high_bits;
14713 + unsigned long one_bits, high_bits;
14714 };
14715
14716 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
14717 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
14718 index 0415cda..b43d877 100644
14719 --- a/arch/x86/include/asm/xsave.h
14720 +++ b/arch/x86/include/asm/xsave.h
14721 @@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
14722 return -EFAULT;
14723
14724 __asm__ __volatile__(ASM_STAC "\n"
14725 - "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
14726 + "1:"
14727 + __copyuser_seg
14728 + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
14729 "2: " ASM_CLAC "\n"
14730 ".section .fixup,\"ax\"\n"
14731 "3: movl $-1,%[err]\n"
14732 @@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
14733 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
14734 {
14735 int err;
14736 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
14737 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
14738 u32 lmask = mask;
14739 u32 hmask = mask >> 32;
14740
14741 __asm__ __volatile__(ASM_STAC "\n"
14742 - "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
14743 + "1:"
14744 + __copyuser_seg
14745 + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
14746 "2: " ASM_CLAC "\n"
14747 ".section .fixup,\"ax\"\n"
14748 "3: movl $-1,%[err]\n"
14749 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
14750 index 91ce48f..a48ea05 100644
14751 --- a/arch/x86/kernel/Makefile
14752 +++ b/arch/x86/kernel/Makefile
14753 @@ -23,7 +23,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
14754 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
14755 obj-$(CONFIG_IRQ_WORK) += irq_work.o
14756 obj-y += probe_roms.o
14757 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
14758 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
14759 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
14760 obj-y += syscall_$(BITS).o
14761 obj-$(CONFIG_X86_64) += vsyscall_64.o
14762 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
14763 index e651f7a..c995dc4 100644
14764 --- a/arch/x86/kernel/acpi/boot.c
14765 +++ b/arch/x86/kernel/acpi/boot.c
14766 @@ -1576,7 +1576,7 @@ int __init acpi_boot_init(void)
14767 acpi_table_parse(ACPI_SIG_HPET, acpi_parse_hpet);
14768
14769 if (!acpi_noirq)
14770 - x86_init.pci.init = pci_acpi_init;
14771 + *(void **)&x86_init.pci.init = pci_acpi_init;
14772
14773 return 0;
14774 }
14775 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
14776 index 11676cf..a8cf3ec 100644
14777 --- a/arch/x86/kernel/acpi/sleep.c
14778 +++ b/arch/x86/kernel/acpi/sleep.c
14779 @@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
14780 #else /* CONFIG_64BIT */
14781 #ifdef CONFIG_SMP
14782 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
14783 +
14784 + pax_open_kernel();
14785 early_gdt_descr.address =
14786 (unsigned long)get_cpu_gdt_table(smp_processor_id());
14787 + pax_close_kernel();
14788 +
14789 initial_gs = per_cpu_offset(smp_processor_id());
14790 #endif
14791 initial_code = (unsigned long)wakeup_long64;
14792 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
14793 index 13ab720..95d5442 100644
14794 --- a/arch/x86/kernel/acpi/wakeup_32.S
14795 +++ b/arch/x86/kernel/acpi/wakeup_32.S
14796 @@ -30,13 +30,11 @@ wakeup_pmode_return:
14797 # and restore the stack ... but you need gdt for this to work
14798 movl saved_context_esp, %esp
14799
14800 - movl %cs:saved_magic, %eax
14801 - cmpl $0x12345678, %eax
14802 + cmpl $0x12345678, saved_magic
14803 jne bogus_magic
14804
14805 # jump to place where we left off
14806 - movl saved_eip, %eax
14807 - jmp *%eax
14808 + jmp *(saved_eip)
14809
14810 bogus_magic:
14811 jmp bogus_magic
14812 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
14813 index ef5ccca..bd83949 100644
14814 --- a/arch/x86/kernel/alternative.c
14815 +++ b/arch/x86/kernel/alternative.c
14816 @@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
14817 */
14818 for (a = start; a < end; a++) {
14819 instr = (u8 *)&a->instr_offset + a->instr_offset;
14820 +
14821 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14822 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14823 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
14824 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14825 +#endif
14826 +
14827 replacement = (u8 *)&a->repl_offset + a->repl_offset;
14828 BUG_ON(a->replacementlen > a->instrlen);
14829 BUG_ON(a->instrlen > sizeof(insnbuf));
14830 @@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
14831 for (poff = start; poff < end; poff++) {
14832 u8 *ptr = (u8 *)poff + *poff;
14833
14834 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14835 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14836 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
14837 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14838 +#endif
14839 +
14840 if (!*poff || ptr < text || ptr >= text_end)
14841 continue;
14842 /* turn DS segment override prefix into lock prefix */
14843 - if (*ptr == 0x3e)
14844 + if (*ktla_ktva(ptr) == 0x3e)
14845 text_poke(ptr, ((unsigned char []){0xf0}), 1);
14846 }
14847 mutex_unlock(&text_mutex);
14848 @@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
14849 for (poff = start; poff < end; poff++) {
14850 u8 *ptr = (u8 *)poff + *poff;
14851
14852 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14853 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14854 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
14855 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14856 +#endif
14857 +
14858 if (!*poff || ptr < text || ptr >= text_end)
14859 continue;
14860 /* turn lock prefix into DS segment override prefix */
14861 - if (*ptr == 0xf0)
14862 + if (*ktla_ktva(ptr) == 0xf0)
14863 text_poke(ptr, ((unsigned char []){0x3E}), 1);
14864 }
14865 mutex_unlock(&text_mutex);
14866 @@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
14867
14868 BUG_ON(p->len > MAX_PATCH_LEN);
14869 /* prep the buffer with the original instructions */
14870 - memcpy(insnbuf, p->instr, p->len);
14871 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
14872 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
14873 (unsigned long)p->instr, p->len);
14874
14875 @@ -515,7 +534,7 @@ void __init alternative_instructions(void)
14876 if (!uniproc_patched || num_possible_cpus() == 1)
14877 free_init_pages("SMP alternatives",
14878 (unsigned long)__smp_locks,
14879 - (unsigned long)__smp_locks_end);
14880 + PAGE_ALIGN((unsigned long)__smp_locks_end));
14881 #endif
14882
14883 apply_paravirt(__parainstructions, __parainstructions_end);
14884 @@ -535,13 +554,17 @@ void __init alternative_instructions(void)
14885 * instructions. And on the local CPU you need to be protected again NMI or MCE
14886 * handlers seeing an inconsistent instruction while you patch.
14887 */
14888 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
14889 +void *__kprobes text_poke_early(void *addr, const void *opcode,
14890 size_t len)
14891 {
14892 unsigned long flags;
14893 local_irq_save(flags);
14894 - memcpy(addr, opcode, len);
14895 +
14896 + pax_open_kernel();
14897 + memcpy(ktla_ktva(addr), opcode, len);
14898 sync_core();
14899 + pax_close_kernel();
14900 +
14901 local_irq_restore(flags);
14902 /* Could also do a CLFLUSH here to speed up CPU recovery; but
14903 that causes hangs on some VIA CPUs. */
14904 @@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
14905 */
14906 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
14907 {
14908 - unsigned long flags;
14909 - char *vaddr;
14910 + unsigned char *vaddr = ktla_ktva(addr);
14911 struct page *pages[2];
14912 - int i;
14913 + size_t i;
14914
14915 if (!core_kernel_text((unsigned long)addr)) {
14916 - pages[0] = vmalloc_to_page(addr);
14917 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
14918 + pages[0] = vmalloc_to_page(vaddr);
14919 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
14920 } else {
14921 - pages[0] = virt_to_page(addr);
14922 + pages[0] = virt_to_page(vaddr);
14923 WARN_ON(!PageReserved(pages[0]));
14924 - pages[1] = virt_to_page(addr + PAGE_SIZE);
14925 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
14926 }
14927 BUG_ON(!pages[0]);
14928 - local_irq_save(flags);
14929 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
14930 - if (pages[1])
14931 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
14932 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
14933 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
14934 - clear_fixmap(FIX_TEXT_POKE0);
14935 - if (pages[1])
14936 - clear_fixmap(FIX_TEXT_POKE1);
14937 - local_flush_tlb();
14938 - sync_core();
14939 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
14940 - that causes hangs on some VIA CPUs. */
14941 + text_poke_early(addr, opcode, len);
14942 for (i = 0; i < len; i++)
14943 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
14944 - local_irq_restore(flags);
14945 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
14946 return addr;
14947 }
14948
14949 diff --git a/arch/x86/kernel/amd_gart_64.c b/arch/x86/kernel/amd_gart_64.c
14950 index e663112..21938a3 100644
14951 --- a/arch/x86/kernel/amd_gart_64.c
14952 +++ b/arch/x86/kernel/amd_gart_64.c
14953 @@ -851,7 +851,7 @@ int __init gart_iommu_init(void)
14954
14955 flush_gart();
14956 dma_ops = &gart_dma_ops;
14957 - x86_platform.iommu_shutdown = gart_iommu_shutdown;
14958 + *(void **)&x86_platform.iommu_shutdown = gart_iommu_shutdown;
14959 swiotlb = 0;
14960
14961 return 0;
14962 diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c
14963 index d5fd66f..6119b16 100644
14964 --- a/arch/x86/kernel/aperture_64.c
14965 +++ b/arch/x86/kernel/aperture_64.c
14966 @@ -390,7 +390,7 @@ int __init gart_iommu_hole_init(void)
14967
14968 iommu_detected = 1;
14969 gart_iommu_aperture = 1;
14970 - x86_init.iommu.iommu_init = gart_iommu_init;
14971 + *(void **)&x86_init.iommu.iommu_init = gart_iommu_init;
14972
14973 ctl = read_pci_config(bus, slot, 3,
14974 AMD64_GARTAPERTURECTL);
14975 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
14976 index b17416e..be6e5dc 100644
14977 --- a/arch/x86/kernel/apic/apic.c
14978 +++ b/arch/x86/kernel/apic/apic.c
14979 @@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
14980 /*
14981 * Debug level, exported for io_apic.c
14982 */
14983 -unsigned int apic_verbosity;
14984 +int apic_verbosity;
14985
14986 int pic_mode;
14987
14988 @@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
14989 apic_write(APIC_ESR, 0);
14990 v1 = apic_read(APIC_ESR);
14991 ack_APIC_irq();
14992 - atomic_inc(&irq_err_count);
14993 + atomic_inc_unchecked(&irq_err_count);
14994
14995 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
14996 smp_processor_id(), v0 , v1);
14997 @@ -2155,7 +2155,9 @@ void __init apic_set_eoi_write(void (*eoi_write)(u32 reg, u32 v))
14998 for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
14999 /* Should happen once for each apic */
15000 WARN_ON((*drv)->eoi_write == eoi_write);
15001 - (*drv)->eoi_write = eoi_write;
15002 + pax_open_kernel();
15003 + *(void **)&(*drv)->eoi_write = eoi_write;
15004 + pax_close_kernel();
15005 }
15006 }
15007
15008 diff --git a/arch/x86/kernel/apic/apic_numachip.c b/arch/x86/kernel/apic/apic_numachip.c
15009 index a65829a..6ddc249 100644
15010 --- a/arch/x86/kernel/apic/apic_numachip.c
15011 +++ b/arch/x86/kernel/apic/apic_numachip.c
15012 @@ -178,7 +178,7 @@ static int __init numachip_system_init(void)
15013 if (!numachip_system)
15014 return 0;
15015
15016 - x86_cpuinit.fixup_cpu_id = fixup_cpu_id;
15017 + *(void **)&x86_cpuinit.fixup_cpu_id = fixup_cpu_id;
15018
15019 map_csrs();
15020
15021 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
15022 index 1817fa9..7bff097 100644
15023 --- a/arch/x86/kernel/apic/io_apic.c
15024 +++ b/arch/x86/kernel/apic/io_apic.c
15025 @@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
15026 }
15027 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
15028
15029 -void lock_vector_lock(void)
15030 +void lock_vector_lock(void) __acquires(vector_lock)
15031 {
15032 /* Used to the online set of cpus does not change
15033 * during assign_irq_vector.
15034 @@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
15035 raw_spin_lock(&vector_lock);
15036 }
15037
15038 -void unlock_vector_lock(void)
15039 +void unlock_vector_lock(void) __releases(vector_lock)
15040 {
15041 raw_spin_unlock(&vector_lock);
15042 }
15043 @@ -2411,7 +2411,7 @@ static void ack_apic_edge(struct irq_data *data)
15044 ack_APIC_irq();
15045 }
15046
15047 -atomic_t irq_mis_count;
15048 +atomic_unchecked_t irq_mis_count;
15049
15050 #ifdef CONFIG_GENERIC_PENDING_IRQ
15051 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
15052 @@ -2552,7 +2552,7 @@ static void ack_apic_level(struct irq_data *data)
15053 * at the cpu.
15054 */
15055 if (!(v & (1 << (i & 0x1f)))) {
15056 - atomic_inc(&irq_mis_count);
15057 + atomic_inc_unchecked(&irq_mis_count);
15058
15059 eoi_ioapic_irq(irq, cfg);
15060 }
15061 diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
15062 index d661ee9..512c0a1 100644
15063 --- a/arch/x86/kernel/apic/numaq_32.c
15064 +++ b/arch/x86/kernel/apic/numaq_32.c
15065 @@ -257,14 +257,14 @@ static __init void early_check_numaq(void)
15066 early_get_smp_config();
15067
15068 if (found_numaq) {
15069 - x86_init.mpparse.mpc_record = numaq_mpc_record;
15070 - x86_init.mpparse.setup_ioapic_ids = x86_init_noop;
15071 - x86_init.mpparse.mpc_apic_id = mpc_apic_id;
15072 - x86_init.mpparse.smp_read_mpc_oem = smp_read_mpc_oem;
15073 - x86_init.mpparse.mpc_oem_pci_bus = mpc_oem_pci_bus;
15074 - x86_init.mpparse.mpc_oem_bus_info = mpc_oem_bus_info;
15075 - x86_init.timers.tsc_pre_init = numaq_tsc_init;
15076 - x86_init.pci.init = pci_numaq_init;
15077 + *(void **)&x86_init.mpparse.mpc_record = numaq_mpc_record;
15078 + *(void **)&x86_init.mpparse.setup_ioapic_ids = x86_init_noop;
15079 + *(void **)&x86_init.mpparse.mpc_apic_id = mpc_apic_id;
15080 + *(void **)&x86_init.mpparse.smp_read_mpc_oem = smp_read_mpc_oem;
15081 + *(void **)&x86_init.mpparse.mpc_oem_pci_bus = mpc_oem_pci_bus;
15082 + *(void **)&x86_init.mpparse.mpc_oem_bus_info = mpc_oem_bus_info;
15083 + *(void **)&x86_init.timers.tsc_pre_init = numaq_tsc_init;
15084 + *(void **)&x86_init.pci.init = pci_numaq_init;
15085 }
15086 }
15087
15088 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
15089 index 8cfade9..8ea7b51 100644
15090 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
15091 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
15092 @@ -139,8 +139,8 @@ static int __init uv_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
15093 is_uv1 ? UV1_HUB_REVISION_BASE : UV2_HUB_REVISION_BASE;
15094 pnodeid = early_get_pnodeid();
15095 early_get_apic_pnode_shift();
15096 - x86_platform.is_untracked_pat_range = uv_is_untracked_pat_range;
15097 - x86_platform.nmi_init = uv_nmi_init;
15098 + *(void **)&x86_platform.is_untracked_pat_range = uv_is_untracked_pat_range;
15099 + *(void **)&x86_platform.nmi_init = uv_nmi_init;
15100 if (!strcmp(oem_table_id, "UVL"))
15101 uv_system_type = UV_LEGACY_APIC;
15102 else if (!strcmp(oem_table_id, "UVX"))
15103 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
15104 index d65464e..1035d31 100644
15105 --- a/arch/x86/kernel/apm_32.c
15106 +++ b/arch/x86/kernel/apm_32.c
15107 @@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
15108 * This is for buggy BIOS's that refer to (real mode) segment 0x40
15109 * even though they are called in protected mode.
15110 */
15111 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
15112 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
15113 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
15114
15115 static const char driver_version[] = "1.16ac"; /* no spaces */
15116 @@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
15117 BUG_ON(cpu != 0);
15118 gdt = get_cpu_gdt_table(cpu);
15119 save_desc_40 = gdt[0x40 / 8];
15120 +
15121 + pax_open_kernel();
15122 gdt[0x40 / 8] = bad_bios_desc;
15123 + pax_close_kernel();
15124
15125 apm_irq_save(flags);
15126 APM_DO_SAVE_SEGS;
15127 @@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
15128 &call->esi);
15129 APM_DO_RESTORE_SEGS;
15130 apm_irq_restore(flags);
15131 +
15132 + pax_open_kernel();
15133 gdt[0x40 / 8] = save_desc_40;
15134 + pax_close_kernel();
15135 +
15136 put_cpu();
15137
15138 return call->eax & 0xff;
15139 @@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
15140 BUG_ON(cpu != 0);
15141 gdt = get_cpu_gdt_table(cpu);
15142 save_desc_40 = gdt[0x40 / 8];
15143 +
15144 + pax_open_kernel();
15145 gdt[0x40 / 8] = bad_bios_desc;
15146 + pax_close_kernel();
15147
15148 apm_irq_save(flags);
15149 APM_DO_SAVE_SEGS;
15150 @@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
15151 &call->eax);
15152 APM_DO_RESTORE_SEGS;
15153 apm_irq_restore(flags);
15154 +
15155 + pax_open_kernel();
15156 gdt[0x40 / 8] = save_desc_40;
15157 + pax_close_kernel();
15158 +
15159 put_cpu();
15160 return error;
15161 }
15162 @@ -2345,12 +2359,15 @@ static int __init apm_init(void)
15163 * code to that CPU.
15164 */
15165 gdt = get_cpu_gdt_table(0);
15166 +
15167 + pax_open_kernel();
15168 set_desc_base(&gdt[APM_CS >> 3],
15169 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
15170 set_desc_base(&gdt[APM_CS_16 >> 3],
15171 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
15172 set_desc_base(&gdt[APM_DS >> 3],
15173 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
15174 + pax_close_kernel();
15175
15176 proc_create("apm", 0, NULL, &apm_file_ops);
15177
15178 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
15179 index 2861082..6d4718e 100644
15180 --- a/arch/x86/kernel/asm-offsets.c
15181 +++ b/arch/x86/kernel/asm-offsets.c
15182 @@ -33,6 +33,8 @@ void common(void) {
15183 OFFSET(TI_status, thread_info, status);
15184 OFFSET(TI_addr_limit, thread_info, addr_limit);
15185 OFFSET(TI_preempt_count, thread_info, preempt_count);
15186 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
15187 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
15188
15189 BLANK();
15190 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
15191 @@ -53,8 +55,26 @@ void common(void) {
15192 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
15193 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
15194 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
15195 +
15196 +#ifdef CONFIG_PAX_KERNEXEC
15197 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
15198 #endif
15199
15200 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15201 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
15202 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
15203 +#ifdef CONFIG_X86_64
15204 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
15205 +#endif
15206 +#endif
15207 +
15208 +#endif
15209 +
15210 + BLANK();
15211 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
15212 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
15213 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
15214 +
15215 #ifdef CONFIG_XEN
15216 BLANK();
15217 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
15218 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
15219 index 1b4754f..fbb4227 100644
15220 --- a/arch/x86/kernel/asm-offsets_64.c
15221 +++ b/arch/x86/kernel/asm-offsets_64.c
15222 @@ -76,6 +76,7 @@ int main(void)
15223 BLANK();
15224 #undef ENTRY
15225
15226 + DEFINE(TSS_size, sizeof(struct tss_struct));
15227 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
15228 BLANK();
15229
15230 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
15231 index a0e067d..9c7db16 100644
15232 --- a/arch/x86/kernel/cpu/Makefile
15233 +++ b/arch/x86/kernel/cpu/Makefile
15234 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
15235 CFLAGS_REMOVE_perf_event.o = -pg
15236 endif
15237
15238 -# Make sure load_percpu_segment has no stackprotector
15239 -nostackp := $(call cc-option, -fno-stack-protector)
15240 -CFLAGS_common.o := $(nostackp)
15241 -
15242 obj-y := intel_cacheinfo.o scattered.o topology.o
15243 obj-y += proc.o capflags.o powerflags.o common.o
15244 obj-y += vmware.o hypervisor.o mshyperv.o
15245 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
15246 index 1b7d165..b9e2627 100644
15247 --- a/arch/x86/kernel/cpu/amd.c
15248 +++ b/arch/x86/kernel/cpu/amd.c
15249 @@ -738,7 +738,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
15250 unsigned int size)
15251 {
15252 /* AMD errata T13 (order #21922) */
15253 - if ((c->x86 == 6)) {
15254 + if (c->x86 == 6) {
15255 /* Duron Rev A0 */
15256 if (c->x86_model == 3 && c->x86_mask == 0)
15257 size = 64;
15258 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
15259 index 7505f7b..d59dac0 100644
15260 --- a/arch/x86/kernel/cpu/common.c
15261 +++ b/arch/x86/kernel/cpu/common.c
15262 @@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
15263
15264 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
15265
15266 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
15267 -#ifdef CONFIG_X86_64
15268 - /*
15269 - * We need valid kernel segments for data and code in long mode too
15270 - * IRET will check the segment types kkeil 2000/10/28
15271 - * Also sysret mandates a special GDT layout
15272 - *
15273 - * TLS descriptors are currently at a different place compared to i386.
15274 - * Hopefully nobody expects them at a fixed place (Wine?)
15275 - */
15276 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
15277 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
15278 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
15279 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
15280 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
15281 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
15282 -#else
15283 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
15284 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
15285 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
15286 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
15287 - /*
15288 - * Segments used for calling PnP BIOS have byte granularity.
15289 - * They code segments and data segments have fixed 64k limits,
15290 - * the transfer segment sizes are set at run time.
15291 - */
15292 - /* 32-bit code */
15293 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
15294 - /* 16-bit code */
15295 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
15296 - /* 16-bit data */
15297 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
15298 - /* 16-bit data */
15299 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
15300 - /* 16-bit data */
15301 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
15302 - /*
15303 - * The APM segments have byte granularity and their bases
15304 - * are set at run time. All have 64k limits.
15305 - */
15306 - /* 32-bit code */
15307 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
15308 - /* 16-bit code */
15309 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
15310 - /* data */
15311 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
15312 -
15313 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
15314 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
15315 - GDT_STACK_CANARY_INIT
15316 -#endif
15317 -} };
15318 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
15319 -
15320 static int __init x86_xsave_setup(char *s)
15321 {
15322 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
15323 @@ -389,7 +335,7 @@ void switch_to_new_gdt(int cpu)
15324 {
15325 struct desc_ptr gdt_descr;
15326
15327 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
15328 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
15329 gdt_descr.size = GDT_SIZE - 1;
15330 load_gdt(&gdt_descr);
15331 /* Reload the per-cpu base */
15332 @@ -885,6 +831,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
15333 /* Filter out anything that depends on CPUID levels we don't have */
15334 filter_cpuid_features(c, true);
15335
15336 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
15337 + setup_clear_cpu_cap(X86_FEATURE_SEP);
15338 +#endif
15339 +
15340 /* If the model name is still unset, do table lookup. */
15341 if (!c->x86_model_id[0]) {
15342 const char *p;
15343 @@ -1068,10 +1018,12 @@ static __init int setup_disablecpuid(char *arg)
15344 }
15345 __setup("clearcpuid=", setup_disablecpuid);
15346
15347 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
15348 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
15349 +
15350 #ifdef CONFIG_X86_64
15351 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
15352 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
15353 - (unsigned long) nmi_idt_table };
15354 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
15355
15356 DEFINE_PER_CPU_FIRST(union irq_stack_union,
15357 irq_stack_union) __aligned(PAGE_SIZE);
15358 @@ -1085,7 +1037,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
15359 EXPORT_PER_CPU_SYMBOL(current_task);
15360
15361 DEFINE_PER_CPU(unsigned long, kernel_stack) =
15362 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
15363 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
15364 EXPORT_PER_CPU_SYMBOL(kernel_stack);
15365
15366 DEFINE_PER_CPU(char *, irq_stack_ptr) =
15367 @@ -1178,7 +1130,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
15368 {
15369 memset(regs, 0, sizeof(struct pt_regs));
15370 regs->fs = __KERNEL_PERCPU;
15371 - regs->gs = __KERNEL_STACK_CANARY;
15372 + savesegment(gs, regs->gs);
15373
15374 return regs;
15375 }
15376 @@ -1233,7 +1185,7 @@ void __cpuinit cpu_init(void)
15377 int i;
15378
15379 cpu = stack_smp_processor_id();
15380 - t = &per_cpu(init_tss, cpu);
15381 + t = init_tss + cpu;
15382 oist = &per_cpu(orig_ist, cpu);
15383
15384 #ifdef CONFIG_NUMA
15385 @@ -1259,7 +1211,7 @@ void __cpuinit cpu_init(void)
15386 switch_to_new_gdt(cpu);
15387 loadsegment(fs, 0);
15388
15389 - load_idt((const struct desc_ptr *)&idt_descr);
15390 + load_idt(&idt_descr);
15391
15392 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
15393 syscall_init();
15394 @@ -1268,7 +1220,6 @@ void __cpuinit cpu_init(void)
15395 wrmsrl(MSR_KERNEL_GS_BASE, 0);
15396 barrier();
15397
15398 - x86_configure_nx();
15399 if (cpu != 0)
15400 enable_x2apic();
15401
15402 @@ -1321,7 +1272,7 @@ void __cpuinit cpu_init(void)
15403 {
15404 int cpu = smp_processor_id();
15405 struct task_struct *curr = current;
15406 - struct tss_struct *t = &per_cpu(init_tss, cpu);
15407 + struct tss_struct *t = init_tss + cpu;
15408 struct thread_struct *thread = &curr->thread;
15409
15410 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
15411 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
15412 index 198e019..867575e 100644
15413 --- a/arch/x86/kernel/cpu/intel.c
15414 +++ b/arch/x86/kernel/cpu/intel.c
15415 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
15416 * Update the IDT descriptor and reload the IDT so that
15417 * it uses the read-only mapped virtual address.
15418 */
15419 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
15420 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
15421 load_idt(&idt_descr);
15422 }
15423 #endif
15424 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
15425 index 93c5451..3887433 100644
15426 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
15427 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
15428 @@ -983,6 +983,22 @@ static struct attribute *default_attrs[] = {
15429 };
15430
15431 #ifdef CONFIG_AMD_NB
15432 +static struct attribute *default_attrs_amd_nb[] = {
15433 + &type.attr,
15434 + &level.attr,
15435 + &coherency_line_size.attr,
15436 + &physical_line_partition.attr,
15437 + &ways_of_associativity.attr,
15438 + &number_of_sets.attr,
15439 + &size.attr,
15440 + &shared_cpu_map.attr,
15441 + &shared_cpu_list.attr,
15442 + NULL,
15443 + NULL,
15444 + NULL,
15445 + NULL
15446 +};
15447 +
15448 static struct attribute ** __cpuinit amd_l3_attrs(void)
15449 {
15450 static struct attribute **attrs;
15451 @@ -993,18 +1009,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
15452
15453 n = ARRAY_SIZE(default_attrs);
15454
15455 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
15456 - n += 2;
15457 -
15458 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
15459 - n += 1;
15460 -
15461 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
15462 - if (attrs == NULL)
15463 - return attrs = default_attrs;
15464 -
15465 - for (n = 0; default_attrs[n]; n++)
15466 - attrs[n] = default_attrs[n];
15467 + attrs = default_attrs_amd_nb;
15468
15469 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
15470 attrs[n++] = &cache_disable_0.attr;
15471 @@ -1055,6 +1060,13 @@ static struct kobj_type ktype_cache = {
15472 .default_attrs = default_attrs,
15473 };
15474
15475 +#ifdef CONFIG_AMD_NB
15476 +static struct kobj_type ktype_cache_amd_nb = {
15477 + .sysfs_ops = &sysfs_ops,
15478 + .default_attrs = default_attrs_amd_nb,
15479 +};
15480 +#endif
15481 +
15482 static struct kobj_type ktype_percpu_entry = {
15483 .sysfs_ops = &sysfs_ops,
15484 };
15485 @@ -1120,20 +1132,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
15486 return retval;
15487 }
15488
15489 +#ifdef CONFIG_AMD_NB
15490 + amd_l3_attrs();
15491 +#endif
15492 +
15493 for (i = 0; i < num_cache_leaves; i++) {
15494 + struct kobj_type *ktype;
15495 +
15496 this_object = INDEX_KOBJECT_PTR(cpu, i);
15497 this_object->cpu = cpu;
15498 this_object->index = i;
15499
15500 this_leaf = CPUID4_INFO_IDX(cpu, i);
15501
15502 - ktype_cache.default_attrs = default_attrs;
15503 + ktype = &ktype_cache;
15504 #ifdef CONFIG_AMD_NB
15505 if (this_leaf->base.nb)
15506 - ktype_cache.default_attrs = amd_l3_attrs();
15507 + ktype = &ktype_cache_amd_nb;
15508 #endif
15509 retval = kobject_init_and_add(&(this_object->kobj),
15510 - &ktype_cache,
15511 + ktype,
15512 per_cpu(ici_cache_kobject, cpu),
15513 "index%1lu", i);
15514 if (unlikely(retval)) {
15515 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
15516 index 46cbf86..55c7292 100644
15517 --- a/arch/x86/kernel/cpu/mcheck/mce.c
15518 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
15519 @@ -45,6 +45,7 @@
15520 #include <asm/processor.h>
15521 #include <asm/mce.h>
15522 #include <asm/msr.h>
15523 +#include <asm/local.h>
15524
15525 #include "mce-internal.h"
15526
15527 @@ -254,7 +255,7 @@ static void print_mce(struct mce *m)
15528 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
15529 m->cs, m->ip);
15530
15531 - if (m->cs == __KERNEL_CS)
15532 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
15533 print_symbol("{%s}", m->ip);
15534 pr_cont("\n");
15535 }
15536 @@ -287,10 +288,10 @@ static void print_mce(struct mce *m)
15537
15538 #define PANIC_TIMEOUT 5 /* 5 seconds */
15539
15540 -static atomic_t mce_paniced;
15541 +static atomic_unchecked_t mce_paniced;
15542
15543 static int fake_panic;
15544 -static atomic_t mce_fake_paniced;
15545 +static atomic_unchecked_t mce_fake_paniced;
15546
15547 /* Panic in progress. Enable interrupts and wait for final IPI */
15548 static void wait_for_panic(void)
15549 @@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
15550 /*
15551 * Make sure only one CPU runs in machine check panic
15552 */
15553 - if (atomic_inc_return(&mce_paniced) > 1)
15554 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
15555 wait_for_panic();
15556 barrier();
15557
15558 @@ -322,7 +323,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
15559 console_verbose();
15560 } else {
15561 /* Don't log too much for fake panic */
15562 - if (atomic_inc_return(&mce_fake_paniced) > 1)
15563 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
15564 return;
15565 }
15566 /* First print corrected ones that are still unlogged */
15567 @@ -694,7 +695,7 @@ static int mce_timed_out(u64 *t)
15568 * might have been modified by someone else.
15569 */
15570 rmb();
15571 - if (atomic_read(&mce_paniced))
15572 + if (atomic_read_unchecked(&mce_paniced))
15573 wait_for_panic();
15574 if (!monarch_timeout)
15575 goto out;
15576 @@ -1659,7 +1660,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
15577 }
15578
15579 /* Call the installed machine check handler for this CPU setup. */
15580 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
15581 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
15582 unexpected_machine_check;
15583
15584 /*
15585 @@ -1682,7 +1683,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
15586 return;
15587 }
15588
15589 + pax_open_kernel();
15590 machine_check_vector = do_machine_check;
15591 + pax_close_kernel();
15592
15593 __mcheck_cpu_init_generic();
15594 __mcheck_cpu_init_vendor(c);
15595 @@ -1696,7 +1699,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
15596 */
15597
15598 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
15599 -static int mce_chrdev_open_count; /* #times opened */
15600 +static local_t mce_chrdev_open_count; /* #times opened */
15601 static int mce_chrdev_open_exclu; /* already open exclusive? */
15602
15603 static int mce_chrdev_open(struct inode *inode, struct file *file)
15604 @@ -1704,7 +1707,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
15605 spin_lock(&mce_chrdev_state_lock);
15606
15607 if (mce_chrdev_open_exclu ||
15608 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
15609 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
15610 spin_unlock(&mce_chrdev_state_lock);
15611
15612 return -EBUSY;
15613 @@ -1712,7 +1715,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
15614
15615 if (file->f_flags & O_EXCL)
15616 mce_chrdev_open_exclu = 1;
15617 - mce_chrdev_open_count++;
15618 + local_inc(&mce_chrdev_open_count);
15619
15620 spin_unlock(&mce_chrdev_state_lock);
15621
15622 @@ -1723,7 +1726,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
15623 {
15624 spin_lock(&mce_chrdev_state_lock);
15625
15626 - mce_chrdev_open_count--;
15627 + local_dec(&mce_chrdev_open_count);
15628 mce_chrdev_open_exclu = 0;
15629
15630 spin_unlock(&mce_chrdev_state_lock);
15631 @@ -2367,7 +2370,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
15632 return NOTIFY_OK;
15633 }
15634
15635 -static struct notifier_block mce_cpu_notifier __cpuinitdata = {
15636 +static struct notifier_block mce_cpu_notifier __cpuinitconst = {
15637 .notifier_call = mce_cpu_callback,
15638 };
15639
15640 @@ -2445,7 +2448,7 @@ struct dentry *mce_get_debugfs_dir(void)
15641 static void mce_reset(void)
15642 {
15643 cpu_missing = 0;
15644 - atomic_set(&mce_fake_paniced, 0);
15645 + atomic_set_unchecked(&mce_fake_paniced, 0);
15646 atomic_set(&mce_executing, 0);
15647 atomic_set(&mce_callin, 0);
15648 atomic_set(&global_nwo, 0);
15649 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
15650 index 2d5454c..51987eb 100644
15651 --- a/arch/x86/kernel/cpu/mcheck/p5.c
15652 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
15653 @@ -11,6 +11,7 @@
15654 #include <asm/processor.h>
15655 #include <asm/mce.h>
15656 #include <asm/msr.h>
15657 +#include <asm/pgtable.h>
15658
15659 /* By default disabled */
15660 int mce_p5_enabled __read_mostly;
15661 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
15662 if (!cpu_has(c, X86_FEATURE_MCE))
15663 return;
15664
15665 + pax_open_kernel();
15666 machine_check_vector = pentium_machine_check;
15667 + pax_close_kernel();
15668 /* Make sure the vector pointer is visible before we enable MCEs: */
15669 wmb();
15670
15671 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
15672 index 2d7998f..17c9de1 100644
15673 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
15674 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
15675 @@ -10,6 +10,7 @@
15676 #include <asm/processor.h>
15677 #include <asm/mce.h>
15678 #include <asm/msr.h>
15679 +#include <asm/pgtable.h>
15680
15681 /* Machine check handler for WinChip C6: */
15682 static void winchip_machine_check(struct pt_regs *regs, long error_code)
15683 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
15684 {
15685 u32 lo, hi;
15686
15687 + pax_open_kernel();
15688 machine_check_vector = winchip_machine_check;
15689 + pax_close_kernel();
15690 /* Make sure the vector pointer is visible before we enable MCEs: */
15691 wmb();
15692
15693 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
15694 index 6b96110..0da73eb 100644
15695 --- a/arch/x86/kernel/cpu/mtrr/main.c
15696 +++ b/arch/x86/kernel/cpu/mtrr/main.c
15697 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
15698 u64 size_or_mask, size_and_mask;
15699 static bool mtrr_aps_delayed_init;
15700
15701 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
15702 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
15703
15704 const struct mtrr_ops *mtrr_if;
15705
15706 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
15707 index df5e41f..816c719 100644
15708 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
15709 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
15710 @@ -25,7 +25,7 @@ struct mtrr_ops {
15711 int (*validate_add_page)(unsigned long base, unsigned long size,
15712 unsigned int type);
15713 int (*have_wrcomb)(void);
15714 -};
15715 +} __do_const;
15716
15717 extern int generic_get_free_region(unsigned long base, unsigned long size,
15718 int replace_reg);
15719 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
15720 index d18b2b8..d3b834c 100644
15721 --- a/arch/x86/kernel/cpu/perf_event.c
15722 +++ b/arch/x86/kernel/cpu/perf_event.c
15723 @@ -1759,7 +1759,7 @@ static unsigned long get_segment_base(unsigned int segment)
15724 if (idx > GDT_ENTRIES)
15725 return 0;
15726
15727 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
15728 + desc = get_cpu_gdt_table(smp_processor_id());
15729 }
15730
15731 return get_desc_base(desc + idx);
15732 @@ -1849,7 +1849,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
15733 break;
15734
15735 perf_callchain_store(entry, frame.return_address);
15736 - fp = frame.next_frame;
15737 + fp = (const void __force_user *)frame.next_frame;
15738 }
15739 }
15740
15741 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
15742 index 324bb52..1a93d85 100644
15743 --- a/arch/x86/kernel/cpu/perf_event_intel.c
15744 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
15745 @@ -1949,10 +1949,10 @@ __init int intel_pmu_init(void)
15746 * v2 and above have a perf capabilities MSR
15747 */
15748 if (version > 1) {
15749 - u64 capabilities;
15750 + u64 capabilities = x86_pmu.intel_cap.capabilities;
15751
15752 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
15753 - x86_pmu.intel_cap.capabilities = capabilities;
15754 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
15755 + x86_pmu.intel_cap.capabilities = capabilities;
15756 }
15757
15758 intel_ds_init();
15759 diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c
15760 index d22d0c4..088eb6f 100644
15761 --- a/arch/x86/kernel/cpu/vmware.c
15762 +++ b/arch/x86/kernel/cpu/vmware.c
15763 @@ -79,7 +79,7 @@ static void __init vmware_platform_setup(void)
15764 VMWARE_PORT(GETHZ, eax, ebx, ecx, edx);
15765
15766 if (ebx != UINT_MAX)
15767 - x86_platform.calibrate_tsc = vmware_get_tsc_khz;
15768 + *(void **)&x86_platform.calibrate_tsc = vmware_get_tsc_khz;
15769 else
15770 printk(KERN_WARNING
15771 "Failed to get TSC freq from the hypervisor\n");
15772 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
15773 index 13ad899..f642b9a 100644
15774 --- a/arch/x86/kernel/crash.c
15775 +++ b/arch/x86/kernel/crash.c
15776 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
15777 {
15778 #ifdef CONFIG_X86_32
15779 struct pt_regs fixed_regs;
15780 -#endif
15781
15782 -#ifdef CONFIG_X86_32
15783 - if (!user_mode_vm(regs)) {
15784 + if (!user_mode(regs)) {
15785 crash_fixup_ss_esp(&fixed_regs, regs);
15786 regs = &fixed_regs;
15787 }
15788 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
15789 index 37250fe..bf2ec74 100644
15790 --- a/arch/x86/kernel/doublefault_32.c
15791 +++ b/arch/x86/kernel/doublefault_32.c
15792 @@ -11,7 +11,7 @@
15793
15794 #define DOUBLEFAULT_STACKSIZE (1024)
15795 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
15796 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
15797 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
15798
15799 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
15800
15801 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
15802 unsigned long gdt, tss;
15803
15804 store_gdt(&gdt_desc);
15805 - gdt = gdt_desc.address;
15806 + gdt = (unsigned long)gdt_desc.address;
15807
15808 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
15809
15810 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
15811 /* 0x2 bit is always set */
15812 .flags = X86_EFLAGS_SF | 0x2,
15813 .sp = STACK_START,
15814 - .es = __USER_DS,
15815 + .es = __KERNEL_DS,
15816 .cs = __KERNEL_CS,
15817 .ss = __KERNEL_DS,
15818 - .ds = __USER_DS,
15819 + .ds = __KERNEL_DS,
15820 .fs = __KERNEL_PERCPU,
15821
15822 .__cr3 = __pa_nodebug(swapper_pg_dir),
15823 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
15824 index ae42418b..787c16b 100644
15825 --- a/arch/x86/kernel/dumpstack.c
15826 +++ b/arch/x86/kernel/dumpstack.c
15827 @@ -2,6 +2,9 @@
15828 * Copyright (C) 1991, 1992 Linus Torvalds
15829 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
15830 */
15831 +#ifdef CONFIG_GRKERNSEC_HIDESYM
15832 +#define __INCLUDED_BY_HIDESYM 1
15833 +#endif
15834 #include <linux/kallsyms.h>
15835 #include <linux/kprobes.h>
15836 #include <linux/uaccess.h>
15837 @@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
15838 static void
15839 print_ftrace_graph_addr(unsigned long addr, void *data,
15840 const struct stacktrace_ops *ops,
15841 - struct thread_info *tinfo, int *graph)
15842 + struct task_struct *task, int *graph)
15843 {
15844 - struct task_struct *task;
15845 unsigned long ret_addr;
15846 int index;
15847
15848 if (addr != (unsigned long)return_to_handler)
15849 return;
15850
15851 - task = tinfo->task;
15852 index = task->curr_ret_stack;
15853
15854 if (!task->ret_stack || index < *graph)
15855 @@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
15856 static inline void
15857 print_ftrace_graph_addr(unsigned long addr, void *data,
15858 const struct stacktrace_ops *ops,
15859 - struct thread_info *tinfo, int *graph)
15860 + struct task_struct *task, int *graph)
15861 { }
15862 #endif
15863
15864 @@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
15865 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
15866 */
15867
15868 -static inline int valid_stack_ptr(struct thread_info *tinfo,
15869 - void *p, unsigned int size, void *end)
15870 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
15871 {
15872 - void *t = tinfo;
15873 if (end) {
15874 if (p < end && p >= (end-THREAD_SIZE))
15875 return 1;
15876 @@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
15877 }
15878
15879 unsigned long
15880 -print_context_stack(struct thread_info *tinfo,
15881 +print_context_stack(struct task_struct *task, void *stack_start,
15882 unsigned long *stack, unsigned long bp,
15883 const struct stacktrace_ops *ops, void *data,
15884 unsigned long *end, int *graph)
15885 {
15886 struct stack_frame *frame = (struct stack_frame *)bp;
15887
15888 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
15889 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
15890 unsigned long addr;
15891
15892 addr = *stack;
15893 @@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
15894 } else {
15895 ops->address(data, addr, 0);
15896 }
15897 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
15898 + print_ftrace_graph_addr(addr, data, ops, task, graph);
15899 }
15900 stack++;
15901 }
15902 @@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
15903 EXPORT_SYMBOL_GPL(print_context_stack);
15904
15905 unsigned long
15906 -print_context_stack_bp(struct thread_info *tinfo,
15907 +print_context_stack_bp(struct task_struct *task, void *stack_start,
15908 unsigned long *stack, unsigned long bp,
15909 const struct stacktrace_ops *ops, void *data,
15910 unsigned long *end, int *graph)
15911 @@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
15912 struct stack_frame *frame = (struct stack_frame *)bp;
15913 unsigned long *ret_addr = &frame->return_address;
15914
15915 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
15916 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
15917 unsigned long addr = *ret_addr;
15918
15919 if (!__kernel_text_address(addr))
15920 @@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
15921 ops->address(data, addr, 1);
15922 frame = frame->next_frame;
15923 ret_addr = &frame->return_address;
15924 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
15925 + print_ftrace_graph_addr(addr, data, ops, task, graph);
15926 }
15927
15928 return (unsigned long)frame;
15929 @@ -189,7 +188,7 @@ void dump_stack(void)
15930
15931 bp = stack_frame(current, NULL);
15932 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
15933 - current->pid, current->comm, print_tainted(),
15934 + task_pid_nr(current), current->comm, print_tainted(),
15935 init_utsname()->release,
15936 (int)strcspn(init_utsname()->version, " "),
15937 init_utsname()->version);
15938 @@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
15939 }
15940 EXPORT_SYMBOL_GPL(oops_begin);
15941
15942 +extern void gr_handle_kernel_exploit(void);
15943 +
15944 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
15945 {
15946 if (regs && kexec_should_crash(current))
15947 @@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
15948 panic("Fatal exception in interrupt");
15949 if (panic_on_oops)
15950 panic("Fatal exception");
15951 - do_exit(signr);
15952 +
15953 + gr_handle_kernel_exploit();
15954 +
15955 + do_group_exit(signr);
15956 }
15957
15958 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
15959 @@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
15960 print_modules();
15961 show_regs(regs);
15962 #ifdef CONFIG_X86_32
15963 - if (user_mode_vm(regs)) {
15964 + if (user_mode(regs)) {
15965 sp = regs->sp;
15966 ss = regs->ss & 0xffff;
15967 } else {
15968 @@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
15969 unsigned long flags = oops_begin();
15970 int sig = SIGSEGV;
15971
15972 - if (!user_mode_vm(regs))
15973 + if (!user_mode(regs))
15974 report_bug(regs->ip, regs);
15975
15976 if (__die(str, regs, err))
15977 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
15978 index 1038a41..db2c12b 100644
15979 --- a/arch/x86/kernel/dumpstack_32.c
15980 +++ b/arch/x86/kernel/dumpstack_32.c
15981 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
15982 bp = stack_frame(task, regs);
15983
15984 for (;;) {
15985 - struct thread_info *context;
15986 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
15987
15988 - context = (struct thread_info *)
15989 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
15990 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
15991 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
15992
15993 - stack = (unsigned long *)context->previous_esp;
15994 - if (!stack)
15995 + if (stack_start == task_stack_page(task))
15996 break;
15997 + stack = *(unsigned long **)stack_start;
15998 if (ops->stack(data, "IRQ") < 0)
15999 break;
16000 touch_nmi_watchdog();
16001 @@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
16002 {
16003 int i;
16004
16005 - __show_regs(regs, !user_mode_vm(regs));
16006 + __show_regs(regs, !user_mode(regs));
16007
16008 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
16009 TASK_COMM_LEN, current->comm, task_pid_nr(current),
16010 @@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
16011 * When in-kernel, we also print out the stack and code at the
16012 * time of the fault..
16013 */
16014 - if (!user_mode_vm(regs)) {
16015 + if (!user_mode(regs)) {
16016 unsigned int code_prologue = code_bytes * 43 / 64;
16017 unsigned int code_len = code_bytes;
16018 unsigned char c;
16019 u8 *ip;
16020 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
16021
16022 pr_emerg("Stack:\n");
16023 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
16024
16025 pr_emerg("Code:");
16026
16027 - ip = (u8 *)regs->ip - code_prologue;
16028 + ip = (u8 *)regs->ip - code_prologue + cs_base;
16029 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
16030 /* try starting at IP */
16031 - ip = (u8 *)regs->ip;
16032 + ip = (u8 *)regs->ip + cs_base;
16033 code_len = code_len - code_prologue + 1;
16034 }
16035 for (i = 0; i < code_len; i++, ip++) {
16036 @@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
16037 pr_cont(" Bad EIP value.");
16038 break;
16039 }
16040 - if (ip == (u8 *)regs->ip)
16041 + if (ip == (u8 *)regs->ip + cs_base)
16042 pr_cont(" <%02x>", c);
16043 else
16044 pr_cont(" %02x", c);
16045 @@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
16046 {
16047 unsigned short ud2;
16048
16049 + ip = ktla_ktva(ip);
16050 if (ip < PAGE_OFFSET)
16051 return 0;
16052 if (probe_kernel_address((unsigned short *)ip, ud2))
16053 @@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
16054
16055 return ud2 == 0x0b0f;
16056 }
16057 +
16058 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16059 +void pax_check_alloca(unsigned long size)
16060 +{
16061 + unsigned long sp = (unsigned long)&sp, stack_left;
16062 +
16063 + /* all kernel stacks are of the same size */
16064 + stack_left = sp & (THREAD_SIZE - 1);
16065 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
16066 +}
16067 +EXPORT_SYMBOL(pax_check_alloca);
16068 +#endif
16069 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
16070 index b653675..51cc8c0 100644
16071 --- a/arch/x86/kernel/dumpstack_64.c
16072 +++ b/arch/x86/kernel/dumpstack_64.c
16073 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16074 unsigned long *irq_stack_end =
16075 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
16076 unsigned used = 0;
16077 - struct thread_info *tinfo;
16078 int graph = 0;
16079 unsigned long dummy;
16080 + void *stack_start;
16081
16082 if (!task)
16083 task = current;
16084 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16085 * current stack address. If the stacks consist of nested
16086 * exceptions
16087 */
16088 - tinfo = task_thread_info(task);
16089 for (;;) {
16090 char *id;
16091 unsigned long *estack_end;
16092 +
16093 estack_end = in_exception_stack(cpu, (unsigned long)stack,
16094 &used, &id);
16095
16096 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16097 if (ops->stack(data, id) < 0)
16098 break;
16099
16100 - bp = ops->walk_stack(tinfo, stack, bp, ops,
16101 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
16102 data, estack_end, &graph);
16103 ops->stack(data, "<EOE>");
16104 /*
16105 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16106 * second-to-last pointer (index -2 to end) in the
16107 * exception stack:
16108 */
16109 + if ((u16)estack_end[-1] != __KERNEL_DS)
16110 + goto out;
16111 stack = (unsigned long *) estack_end[-2];
16112 continue;
16113 }
16114 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16115 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
16116 if (ops->stack(data, "IRQ") < 0)
16117 break;
16118 - bp = ops->walk_stack(tinfo, stack, bp,
16119 + bp = ops->walk_stack(task, irq_stack, stack, bp,
16120 ops, data, irq_stack_end, &graph);
16121 /*
16122 * We link to the next stack (which would be
16123 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16124 /*
16125 * This handles the process stack:
16126 */
16127 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
16128 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
16129 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
16130 +out:
16131 put_cpu();
16132 }
16133 EXPORT_SYMBOL(dump_trace);
16134 @@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
16135 {
16136 int i;
16137 unsigned long sp;
16138 - const int cpu = smp_processor_id();
16139 + const int cpu = raw_smp_processor_id();
16140 struct task_struct *cur = current;
16141
16142 sp = regs->sp;
16143 @@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
16144
16145 return ud2 == 0x0b0f;
16146 }
16147 +
16148 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16149 +void pax_check_alloca(unsigned long size)
16150 +{
16151 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
16152 + unsigned cpu, used;
16153 + char *id;
16154 +
16155 + /* check the process stack first */
16156 + stack_start = (unsigned long)task_stack_page(current);
16157 + stack_end = stack_start + THREAD_SIZE;
16158 + if (likely(stack_start <= sp && sp < stack_end)) {
16159 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
16160 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
16161 + return;
16162 + }
16163 +
16164 + cpu = get_cpu();
16165 +
16166 + /* check the irq stacks */
16167 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
16168 + stack_start = stack_end - IRQ_STACK_SIZE;
16169 + if (stack_start <= sp && sp < stack_end) {
16170 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
16171 + put_cpu();
16172 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
16173 + return;
16174 + }
16175 +
16176 + /* check the exception stacks */
16177 + used = 0;
16178 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
16179 + stack_start = stack_end - EXCEPTION_STKSZ;
16180 + if (stack_end && stack_start <= sp && sp < stack_end) {
16181 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
16182 + put_cpu();
16183 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
16184 + return;
16185 + }
16186 +
16187 + put_cpu();
16188 +
16189 + /* unknown stack */
16190 + BUG();
16191 +}
16192 +EXPORT_SYMBOL(pax_check_alloca);
16193 +#endif
16194 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
16195 index 9b9f18b..9fcaa04 100644
16196 --- a/arch/x86/kernel/early_printk.c
16197 +++ b/arch/x86/kernel/early_printk.c
16198 @@ -7,6 +7,7 @@
16199 #include <linux/pci_regs.h>
16200 #include <linux/pci_ids.h>
16201 #include <linux/errno.h>
16202 +#include <linux/sched.h>
16203 #include <asm/io.h>
16204 #include <asm/processor.h>
16205 #include <asm/fcntl.h>
16206 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
16207 index cf8639b..6c6a674 100644
16208 --- a/arch/x86/kernel/entry_32.S
16209 +++ b/arch/x86/kernel/entry_32.S
16210 @@ -177,13 +177,153 @@
16211 /*CFI_REL_OFFSET gs, PT_GS*/
16212 .endm
16213 .macro SET_KERNEL_GS reg
16214 +
16215 +#ifdef CONFIG_CC_STACKPROTECTOR
16216 movl $(__KERNEL_STACK_CANARY), \reg
16217 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
16218 + movl $(__USER_DS), \reg
16219 +#else
16220 + xorl \reg, \reg
16221 +#endif
16222 +
16223 movl \reg, %gs
16224 .endm
16225
16226 #endif /* CONFIG_X86_32_LAZY_GS */
16227
16228 -.macro SAVE_ALL
16229 +.macro pax_enter_kernel
16230 +#ifdef CONFIG_PAX_KERNEXEC
16231 + call pax_enter_kernel
16232 +#endif
16233 +.endm
16234 +
16235 +.macro pax_exit_kernel
16236 +#ifdef CONFIG_PAX_KERNEXEC
16237 + call pax_exit_kernel
16238 +#endif
16239 +.endm
16240 +
16241 +#ifdef CONFIG_PAX_KERNEXEC
16242 +ENTRY(pax_enter_kernel)
16243 +#ifdef CONFIG_PARAVIRT
16244 + pushl %eax
16245 + pushl %ecx
16246 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
16247 + mov %eax, %esi
16248 +#else
16249 + mov %cr0, %esi
16250 +#endif
16251 + bts $16, %esi
16252 + jnc 1f
16253 + mov %cs, %esi
16254 + cmp $__KERNEL_CS, %esi
16255 + jz 3f
16256 + ljmp $__KERNEL_CS, $3f
16257 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
16258 +2:
16259 +#ifdef CONFIG_PARAVIRT
16260 + mov %esi, %eax
16261 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
16262 +#else
16263 + mov %esi, %cr0
16264 +#endif
16265 +3:
16266 +#ifdef CONFIG_PARAVIRT
16267 + popl %ecx
16268 + popl %eax
16269 +#endif
16270 + ret
16271 +ENDPROC(pax_enter_kernel)
16272 +
16273 +ENTRY(pax_exit_kernel)
16274 +#ifdef CONFIG_PARAVIRT
16275 + pushl %eax
16276 + pushl %ecx
16277 +#endif
16278 + mov %cs, %esi
16279 + cmp $__KERNEXEC_KERNEL_CS, %esi
16280 + jnz 2f
16281 +#ifdef CONFIG_PARAVIRT
16282 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
16283 + mov %eax, %esi
16284 +#else
16285 + mov %cr0, %esi
16286 +#endif
16287 + btr $16, %esi
16288 + ljmp $__KERNEL_CS, $1f
16289 +1:
16290 +#ifdef CONFIG_PARAVIRT
16291 + mov %esi, %eax
16292 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
16293 +#else
16294 + mov %esi, %cr0
16295 +#endif
16296 +2:
16297 +#ifdef CONFIG_PARAVIRT
16298 + popl %ecx
16299 + popl %eax
16300 +#endif
16301 + ret
16302 +ENDPROC(pax_exit_kernel)
16303 +#endif
16304 +
16305 +.macro pax_erase_kstack
16306 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16307 + call pax_erase_kstack
16308 +#endif
16309 +.endm
16310 +
16311 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16312 +/*
16313 + * ebp: thread_info
16314 + */
16315 +ENTRY(pax_erase_kstack)
16316 + pushl %edi
16317 + pushl %ecx
16318 + pushl %eax
16319 +
16320 + mov TI_lowest_stack(%ebp), %edi
16321 + mov $-0xBEEF, %eax
16322 + std
16323 +
16324 +1: mov %edi, %ecx
16325 + and $THREAD_SIZE_asm - 1, %ecx
16326 + shr $2, %ecx
16327 + repne scasl
16328 + jecxz 2f
16329 +
16330 + cmp $2*16, %ecx
16331 + jc 2f
16332 +
16333 + mov $2*16, %ecx
16334 + repe scasl
16335 + jecxz 2f
16336 + jne 1b
16337 +
16338 +2: cld
16339 + mov %esp, %ecx
16340 + sub %edi, %ecx
16341 +
16342 + cmp $THREAD_SIZE_asm, %ecx
16343 + jb 3f
16344 + ud2
16345 +3:
16346 +
16347 + shr $2, %ecx
16348 + rep stosl
16349 +
16350 + mov TI_task_thread_sp0(%ebp), %edi
16351 + sub $128, %edi
16352 + mov %edi, TI_lowest_stack(%ebp)
16353 +
16354 + popl %eax
16355 + popl %ecx
16356 + popl %edi
16357 + ret
16358 +ENDPROC(pax_erase_kstack)
16359 +#endif
16360 +
16361 +.macro __SAVE_ALL _DS
16362 cld
16363 PUSH_GS
16364 pushl_cfi %fs
16365 @@ -206,7 +346,7 @@
16366 CFI_REL_OFFSET ecx, 0
16367 pushl_cfi %ebx
16368 CFI_REL_OFFSET ebx, 0
16369 - movl $(__USER_DS), %edx
16370 + movl $\_DS, %edx
16371 movl %edx, %ds
16372 movl %edx, %es
16373 movl $(__KERNEL_PERCPU), %edx
16374 @@ -214,6 +354,15 @@
16375 SET_KERNEL_GS %edx
16376 .endm
16377
16378 +.macro SAVE_ALL
16379 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
16380 + __SAVE_ALL __KERNEL_DS
16381 + pax_enter_kernel
16382 +#else
16383 + __SAVE_ALL __USER_DS
16384 +#endif
16385 +.endm
16386 +
16387 .macro RESTORE_INT_REGS
16388 popl_cfi %ebx
16389 CFI_RESTORE ebx
16390 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
16391 popfl_cfi
16392 jmp syscall_exit
16393 CFI_ENDPROC
16394 -END(ret_from_fork)
16395 +ENDPROC(ret_from_fork)
16396
16397 ENTRY(ret_from_kernel_thread)
16398 CFI_STARTPROC
16399 @@ -344,7 +493,15 @@ ret_from_intr:
16400 andl $SEGMENT_RPL_MASK, %eax
16401 #endif
16402 cmpl $USER_RPL, %eax
16403 +
16404 +#ifdef CONFIG_PAX_KERNEXEC
16405 + jae resume_userspace
16406 +
16407 + pax_exit_kernel
16408 + jmp resume_kernel
16409 +#else
16410 jb resume_kernel # not returning to v8086 or userspace
16411 +#endif
16412
16413 ENTRY(resume_userspace)
16414 LOCKDEP_SYS_EXIT
16415 @@ -356,8 +513,8 @@ ENTRY(resume_userspace)
16416 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
16417 # int/exception return?
16418 jne work_pending
16419 - jmp restore_all
16420 -END(ret_from_exception)
16421 + jmp restore_all_pax
16422 +ENDPROC(ret_from_exception)
16423
16424 #ifdef CONFIG_PREEMPT
16425 ENTRY(resume_kernel)
16426 @@ -372,7 +529,7 @@ need_resched:
16427 jz restore_all
16428 call preempt_schedule_irq
16429 jmp need_resched
16430 -END(resume_kernel)
16431 +ENDPROC(resume_kernel)
16432 #endif
16433 CFI_ENDPROC
16434 /*
16435 @@ -406,30 +563,45 @@ sysenter_past_esp:
16436 /*CFI_REL_OFFSET cs, 0*/
16437 /*
16438 * Push current_thread_info()->sysenter_return to the stack.
16439 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
16440 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
16441 */
16442 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
16443 + pushl_cfi $0
16444 CFI_REL_OFFSET eip, 0
16445
16446 pushl_cfi %eax
16447 SAVE_ALL
16448 + GET_THREAD_INFO(%ebp)
16449 + movl TI_sysenter_return(%ebp),%ebp
16450 + movl %ebp,PT_EIP(%esp)
16451 ENABLE_INTERRUPTS(CLBR_NONE)
16452
16453 /*
16454 * Load the potential sixth argument from user stack.
16455 * Careful about security.
16456 */
16457 + movl PT_OLDESP(%esp),%ebp
16458 +
16459 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16460 + mov PT_OLDSS(%esp),%ds
16461 +1: movl %ds:(%ebp),%ebp
16462 + push %ss
16463 + pop %ds
16464 +#else
16465 cmpl $__PAGE_OFFSET-3,%ebp
16466 jae syscall_fault
16467 ASM_STAC
16468 1: movl (%ebp),%ebp
16469 ASM_CLAC
16470 +#endif
16471 +
16472 movl %ebp,PT_EBP(%esp)
16473 _ASM_EXTABLE(1b,syscall_fault)
16474
16475 GET_THREAD_INFO(%ebp)
16476
16477 +#ifdef CONFIG_PAX_RANDKSTACK
16478 + pax_erase_kstack
16479 +#endif
16480 +
16481 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
16482 jnz sysenter_audit
16483 sysenter_do_call:
16484 @@ -444,12 +616,24 @@ sysenter_do_call:
16485 testl $_TIF_ALLWORK_MASK, %ecx
16486 jne sysexit_audit
16487 sysenter_exit:
16488 +
16489 +#ifdef CONFIG_PAX_RANDKSTACK
16490 + pushl_cfi %eax
16491 + movl %esp, %eax
16492 + call pax_randomize_kstack
16493 + popl_cfi %eax
16494 +#endif
16495 +
16496 + pax_erase_kstack
16497 +
16498 /* if something modifies registers it must also disable sysexit */
16499 movl PT_EIP(%esp), %edx
16500 movl PT_OLDESP(%esp), %ecx
16501 xorl %ebp,%ebp
16502 TRACE_IRQS_ON
16503 1: mov PT_FS(%esp), %fs
16504 +2: mov PT_DS(%esp), %ds
16505 +3: mov PT_ES(%esp), %es
16506 PTGS_TO_GS
16507 ENABLE_INTERRUPTS_SYSEXIT
16508
16509 @@ -466,6 +650,9 @@ sysenter_audit:
16510 movl %eax,%edx /* 2nd arg: syscall number */
16511 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
16512 call __audit_syscall_entry
16513 +
16514 + pax_erase_kstack
16515 +
16516 pushl_cfi %ebx
16517 movl PT_EAX(%esp),%eax /* reload syscall number */
16518 jmp sysenter_do_call
16519 @@ -491,10 +678,16 @@ sysexit_audit:
16520
16521 CFI_ENDPROC
16522 .pushsection .fixup,"ax"
16523 -2: movl $0,PT_FS(%esp)
16524 +4: movl $0,PT_FS(%esp)
16525 + jmp 1b
16526 +5: movl $0,PT_DS(%esp)
16527 + jmp 1b
16528 +6: movl $0,PT_ES(%esp)
16529 jmp 1b
16530 .popsection
16531 - _ASM_EXTABLE(1b,2b)
16532 + _ASM_EXTABLE(1b,4b)
16533 + _ASM_EXTABLE(2b,5b)
16534 + _ASM_EXTABLE(3b,6b)
16535 PTGS_TO_GS_EX
16536 ENDPROC(ia32_sysenter_target)
16537
16538 @@ -509,6 +702,11 @@ ENTRY(system_call)
16539 pushl_cfi %eax # save orig_eax
16540 SAVE_ALL
16541 GET_THREAD_INFO(%ebp)
16542 +
16543 +#ifdef CONFIG_PAX_RANDKSTACK
16544 + pax_erase_kstack
16545 +#endif
16546 +
16547 # system call tracing in operation / emulation
16548 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
16549 jnz syscall_trace_entry
16550 @@ -527,6 +725,15 @@ syscall_exit:
16551 testl $_TIF_ALLWORK_MASK, %ecx # current->work
16552 jne syscall_exit_work
16553
16554 +restore_all_pax:
16555 +
16556 +#ifdef CONFIG_PAX_RANDKSTACK
16557 + movl %esp, %eax
16558 + call pax_randomize_kstack
16559 +#endif
16560 +
16561 + pax_erase_kstack
16562 +
16563 restore_all:
16564 TRACE_IRQS_IRET
16565 restore_all_notrace:
16566 @@ -583,14 +790,34 @@ ldt_ss:
16567 * compensating for the offset by changing to the ESPFIX segment with
16568 * a base address that matches for the difference.
16569 */
16570 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
16571 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
16572 mov %esp, %edx /* load kernel esp */
16573 mov PT_OLDESP(%esp), %eax /* load userspace esp */
16574 mov %dx, %ax /* eax: new kernel esp */
16575 sub %eax, %edx /* offset (low word is 0) */
16576 +#ifdef CONFIG_SMP
16577 + movl PER_CPU_VAR(cpu_number), %ebx
16578 + shll $PAGE_SHIFT_asm, %ebx
16579 + addl $cpu_gdt_table, %ebx
16580 +#else
16581 + movl $cpu_gdt_table, %ebx
16582 +#endif
16583 shr $16, %edx
16584 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
16585 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
16586 +
16587 +#ifdef CONFIG_PAX_KERNEXEC
16588 + mov %cr0, %esi
16589 + btr $16, %esi
16590 + mov %esi, %cr0
16591 +#endif
16592 +
16593 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
16594 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
16595 +
16596 +#ifdef CONFIG_PAX_KERNEXEC
16597 + bts $16, %esi
16598 + mov %esi, %cr0
16599 +#endif
16600 +
16601 pushl_cfi $__ESPFIX_SS
16602 pushl_cfi %eax /* new kernel esp */
16603 /* Disable interrupts, but do not irqtrace this section: we
16604 @@ -619,20 +846,18 @@ work_resched:
16605 movl TI_flags(%ebp), %ecx
16606 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
16607 # than syscall tracing?
16608 - jz restore_all
16609 + jz restore_all_pax
16610 testb $_TIF_NEED_RESCHED, %cl
16611 jnz work_resched
16612
16613 work_notifysig: # deal with pending signals and
16614 # notify-resume requests
16615 + movl %esp, %eax
16616 #ifdef CONFIG_VM86
16617 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
16618 - movl %esp, %eax
16619 jne work_notifysig_v86 # returning to kernel-space or
16620 # vm86-space
16621 1:
16622 -#else
16623 - movl %esp, %eax
16624 #endif
16625 TRACE_IRQS_ON
16626 ENABLE_INTERRUPTS(CLBR_NONE)
16627 @@ -653,7 +878,7 @@ work_notifysig_v86:
16628 movl %eax, %esp
16629 jmp 1b
16630 #endif
16631 -END(work_pending)
16632 +ENDPROC(work_pending)
16633
16634 # perform syscall exit tracing
16635 ALIGN
16636 @@ -661,11 +886,14 @@ syscall_trace_entry:
16637 movl $-ENOSYS,PT_EAX(%esp)
16638 movl %esp, %eax
16639 call syscall_trace_enter
16640 +
16641 + pax_erase_kstack
16642 +
16643 /* What it returned is what we'll actually use. */
16644 cmpl $(NR_syscalls), %eax
16645 jnae syscall_call
16646 jmp syscall_exit
16647 -END(syscall_trace_entry)
16648 +ENDPROC(syscall_trace_entry)
16649
16650 # perform syscall exit tracing
16651 ALIGN
16652 @@ -678,21 +906,25 @@ syscall_exit_work:
16653 movl %esp, %eax
16654 call syscall_trace_leave
16655 jmp resume_userspace
16656 -END(syscall_exit_work)
16657 +ENDPROC(syscall_exit_work)
16658 CFI_ENDPROC
16659
16660 RING0_INT_FRAME # can't unwind into user space anyway
16661 syscall_fault:
16662 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16663 + push %ss
16664 + pop %ds
16665 +#endif
16666 ASM_CLAC
16667 GET_THREAD_INFO(%ebp)
16668 movl $-EFAULT,PT_EAX(%esp)
16669 jmp resume_userspace
16670 -END(syscall_fault)
16671 +ENDPROC(syscall_fault)
16672
16673 syscall_badsys:
16674 movl $-ENOSYS,PT_EAX(%esp)
16675 jmp resume_userspace
16676 -END(syscall_badsys)
16677 +ENDPROC(syscall_badsys)
16678 CFI_ENDPROC
16679 /*
16680 * End of kprobes section
16681 @@ -772,8 +1004,15 @@ ENDPROC(ptregs_clone)
16682 * normal stack and adjusts ESP with the matching offset.
16683 */
16684 /* fixup the stack */
16685 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
16686 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
16687 +#ifdef CONFIG_SMP
16688 + movl PER_CPU_VAR(cpu_number), %ebx
16689 + shll $PAGE_SHIFT_asm, %ebx
16690 + addl $cpu_gdt_table, %ebx
16691 +#else
16692 + movl $cpu_gdt_table, %ebx
16693 +#endif
16694 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
16695 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
16696 shl $16, %eax
16697 addl %esp, %eax /* the adjusted stack pointer */
16698 pushl_cfi $__KERNEL_DS
16699 @@ -826,7 +1065,7 @@ vector=vector+1
16700 .endr
16701 2: jmp common_interrupt
16702 .endr
16703 -END(irq_entries_start)
16704 +ENDPROC(irq_entries_start)
16705
16706 .previous
16707 END(interrupt)
16708 @@ -877,7 +1116,7 @@ ENTRY(coprocessor_error)
16709 pushl_cfi $do_coprocessor_error
16710 jmp error_code
16711 CFI_ENDPROC
16712 -END(coprocessor_error)
16713 +ENDPROC(coprocessor_error)
16714
16715 ENTRY(simd_coprocessor_error)
16716 RING0_INT_FRAME
16717 @@ -899,7 +1138,7 @@ ENTRY(simd_coprocessor_error)
16718 #endif
16719 jmp error_code
16720 CFI_ENDPROC
16721 -END(simd_coprocessor_error)
16722 +ENDPROC(simd_coprocessor_error)
16723
16724 ENTRY(device_not_available)
16725 RING0_INT_FRAME
16726 @@ -908,18 +1147,18 @@ ENTRY(device_not_available)
16727 pushl_cfi $do_device_not_available
16728 jmp error_code
16729 CFI_ENDPROC
16730 -END(device_not_available)
16731 +ENDPROC(device_not_available)
16732
16733 #ifdef CONFIG_PARAVIRT
16734 ENTRY(native_iret)
16735 iret
16736 _ASM_EXTABLE(native_iret, iret_exc)
16737 -END(native_iret)
16738 +ENDPROC(native_iret)
16739
16740 ENTRY(native_irq_enable_sysexit)
16741 sti
16742 sysexit
16743 -END(native_irq_enable_sysexit)
16744 +ENDPROC(native_irq_enable_sysexit)
16745 #endif
16746
16747 ENTRY(overflow)
16748 @@ -929,7 +1168,7 @@ ENTRY(overflow)
16749 pushl_cfi $do_overflow
16750 jmp error_code
16751 CFI_ENDPROC
16752 -END(overflow)
16753 +ENDPROC(overflow)
16754
16755 ENTRY(bounds)
16756 RING0_INT_FRAME
16757 @@ -938,7 +1177,7 @@ ENTRY(bounds)
16758 pushl_cfi $do_bounds
16759 jmp error_code
16760 CFI_ENDPROC
16761 -END(bounds)
16762 +ENDPROC(bounds)
16763
16764 ENTRY(invalid_op)
16765 RING0_INT_FRAME
16766 @@ -947,7 +1186,7 @@ ENTRY(invalid_op)
16767 pushl_cfi $do_invalid_op
16768 jmp error_code
16769 CFI_ENDPROC
16770 -END(invalid_op)
16771 +ENDPROC(invalid_op)
16772
16773 ENTRY(coprocessor_segment_overrun)
16774 RING0_INT_FRAME
16775 @@ -956,7 +1195,7 @@ ENTRY(coprocessor_segment_overrun)
16776 pushl_cfi $do_coprocessor_segment_overrun
16777 jmp error_code
16778 CFI_ENDPROC
16779 -END(coprocessor_segment_overrun)
16780 +ENDPROC(coprocessor_segment_overrun)
16781
16782 ENTRY(invalid_TSS)
16783 RING0_EC_FRAME
16784 @@ -964,7 +1203,7 @@ ENTRY(invalid_TSS)
16785 pushl_cfi $do_invalid_TSS
16786 jmp error_code
16787 CFI_ENDPROC
16788 -END(invalid_TSS)
16789 +ENDPROC(invalid_TSS)
16790
16791 ENTRY(segment_not_present)
16792 RING0_EC_FRAME
16793 @@ -972,7 +1211,7 @@ ENTRY(segment_not_present)
16794 pushl_cfi $do_segment_not_present
16795 jmp error_code
16796 CFI_ENDPROC
16797 -END(segment_not_present)
16798 +ENDPROC(segment_not_present)
16799
16800 ENTRY(stack_segment)
16801 RING0_EC_FRAME
16802 @@ -980,7 +1219,7 @@ ENTRY(stack_segment)
16803 pushl_cfi $do_stack_segment
16804 jmp error_code
16805 CFI_ENDPROC
16806 -END(stack_segment)
16807 +ENDPROC(stack_segment)
16808
16809 ENTRY(alignment_check)
16810 RING0_EC_FRAME
16811 @@ -988,7 +1227,7 @@ ENTRY(alignment_check)
16812 pushl_cfi $do_alignment_check
16813 jmp error_code
16814 CFI_ENDPROC
16815 -END(alignment_check)
16816 +ENDPROC(alignment_check)
16817
16818 ENTRY(divide_error)
16819 RING0_INT_FRAME
16820 @@ -997,7 +1236,7 @@ ENTRY(divide_error)
16821 pushl_cfi $do_divide_error
16822 jmp error_code
16823 CFI_ENDPROC
16824 -END(divide_error)
16825 +ENDPROC(divide_error)
16826
16827 #ifdef CONFIG_X86_MCE
16828 ENTRY(machine_check)
16829 @@ -1007,7 +1246,7 @@ ENTRY(machine_check)
16830 pushl_cfi machine_check_vector
16831 jmp error_code
16832 CFI_ENDPROC
16833 -END(machine_check)
16834 +ENDPROC(machine_check)
16835 #endif
16836
16837 ENTRY(spurious_interrupt_bug)
16838 @@ -1017,7 +1256,7 @@ ENTRY(spurious_interrupt_bug)
16839 pushl_cfi $do_spurious_interrupt_bug
16840 jmp error_code
16841 CFI_ENDPROC
16842 -END(spurious_interrupt_bug)
16843 +ENDPROC(spurious_interrupt_bug)
16844 /*
16845 * End of kprobes section
16846 */
16847 @@ -1120,7 +1359,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
16848
16849 ENTRY(mcount)
16850 ret
16851 -END(mcount)
16852 +ENDPROC(mcount)
16853
16854 ENTRY(ftrace_caller)
16855 cmpl $0, function_trace_stop
16856 @@ -1153,7 +1392,7 @@ ftrace_graph_call:
16857 .globl ftrace_stub
16858 ftrace_stub:
16859 ret
16860 -END(ftrace_caller)
16861 +ENDPROC(ftrace_caller)
16862
16863 ENTRY(ftrace_regs_caller)
16864 pushf /* push flags before compare (in cs location) */
16865 @@ -1254,7 +1493,7 @@ trace:
16866 popl %ecx
16867 popl %eax
16868 jmp ftrace_stub
16869 -END(mcount)
16870 +ENDPROC(mcount)
16871 #endif /* CONFIG_DYNAMIC_FTRACE */
16872 #endif /* CONFIG_FUNCTION_TRACER */
16873
16874 @@ -1272,7 +1511,7 @@ ENTRY(ftrace_graph_caller)
16875 popl %ecx
16876 popl %eax
16877 ret
16878 -END(ftrace_graph_caller)
16879 +ENDPROC(ftrace_graph_caller)
16880
16881 .globl return_to_handler
16882 return_to_handler:
16883 @@ -1328,15 +1567,18 @@ error_code:
16884 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
16885 REG_TO_PTGS %ecx
16886 SET_KERNEL_GS %ecx
16887 - movl $(__USER_DS), %ecx
16888 + movl $(__KERNEL_DS), %ecx
16889 movl %ecx, %ds
16890 movl %ecx, %es
16891 +
16892 + pax_enter_kernel
16893 +
16894 TRACE_IRQS_OFF
16895 movl %esp,%eax # pt_regs pointer
16896 call *%edi
16897 jmp ret_from_exception
16898 CFI_ENDPROC
16899 -END(page_fault)
16900 +ENDPROC(page_fault)
16901
16902 /*
16903 * Debug traps and NMI can happen at the one SYSENTER instruction
16904 @@ -1379,7 +1621,7 @@ debug_stack_correct:
16905 call do_debug
16906 jmp ret_from_exception
16907 CFI_ENDPROC
16908 -END(debug)
16909 +ENDPROC(debug)
16910
16911 /*
16912 * NMI is doubly nasty. It can happen _while_ we're handling
16913 @@ -1417,6 +1659,9 @@ nmi_stack_correct:
16914 xorl %edx,%edx # zero error code
16915 movl %esp,%eax # pt_regs pointer
16916 call do_nmi
16917 +
16918 + pax_exit_kernel
16919 +
16920 jmp restore_all_notrace
16921 CFI_ENDPROC
16922
16923 @@ -1453,12 +1698,15 @@ nmi_espfix_stack:
16924 FIXUP_ESPFIX_STACK # %eax == %esp
16925 xorl %edx,%edx # zero error code
16926 call do_nmi
16927 +
16928 + pax_exit_kernel
16929 +
16930 RESTORE_REGS
16931 lss 12+4(%esp), %esp # back to espfix stack
16932 CFI_ADJUST_CFA_OFFSET -24
16933 jmp irq_return
16934 CFI_ENDPROC
16935 -END(nmi)
16936 +ENDPROC(nmi)
16937
16938 ENTRY(int3)
16939 RING0_INT_FRAME
16940 @@ -1471,14 +1719,14 @@ ENTRY(int3)
16941 call do_int3
16942 jmp ret_from_exception
16943 CFI_ENDPROC
16944 -END(int3)
16945 +ENDPROC(int3)
16946
16947 ENTRY(general_protection)
16948 RING0_EC_FRAME
16949 pushl_cfi $do_general_protection
16950 jmp error_code
16951 CFI_ENDPROC
16952 -END(general_protection)
16953 +ENDPROC(general_protection)
16954
16955 #ifdef CONFIG_KVM_GUEST
16956 ENTRY(async_page_fault)
16957 @@ -1487,7 +1735,7 @@ ENTRY(async_page_fault)
16958 pushl_cfi $do_async_page_fault
16959 jmp error_code
16960 CFI_ENDPROC
16961 -END(async_page_fault)
16962 +ENDPROC(async_page_fault)
16963 #endif
16964
16965 /*
16966 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
16967 index 1328fe4..cb03298 100644
16968 --- a/arch/x86/kernel/entry_64.S
16969 +++ b/arch/x86/kernel/entry_64.S
16970 @@ -59,6 +59,8 @@
16971 #include <asm/rcu.h>
16972 #include <asm/smap.h>
16973 #include <linux/err.h>
16974 +#include <asm/pgtable.h>
16975 +#include <asm/alternative-asm.h>
16976
16977 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
16978 #include <linux/elf-em.h>
16979 @@ -80,8 +82,9 @@
16980 #ifdef CONFIG_DYNAMIC_FTRACE
16981
16982 ENTRY(function_hook)
16983 + pax_force_retaddr
16984 retq
16985 -END(function_hook)
16986 +ENDPROC(function_hook)
16987
16988 /* skip is set if stack has been adjusted */
16989 .macro ftrace_caller_setup skip=0
16990 @@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
16991 #endif
16992
16993 GLOBAL(ftrace_stub)
16994 + pax_force_retaddr
16995 retq
16996 -END(ftrace_caller)
16997 +ENDPROC(ftrace_caller)
16998
16999 ENTRY(ftrace_regs_caller)
17000 /* Save the current flags before compare (in SS location)*/
17001 @@ -191,7 +195,7 @@ ftrace_restore_flags:
17002 popfq
17003 jmp ftrace_stub
17004
17005 -END(ftrace_regs_caller)
17006 +ENDPROC(ftrace_regs_caller)
17007
17008
17009 #else /* ! CONFIG_DYNAMIC_FTRACE */
17010 @@ -212,6 +216,7 @@ ENTRY(function_hook)
17011 #endif
17012
17013 GLOBAL(ftrace_stub)
17014 + pax_force_retaddr
17015 retq
17016
17017 trace:
17018 @@ -225,12 +230,13 @@ trace:
17019 #endif
17020 subq $MCOUNT_INSN_SIZE, %rdi
17021
17022 + pax_force_fptr ftrace_trace_function
17023 call *ftrace_trace_function
17024
17025 MCOUNT_RESTORE_FRAME
17026
17027 jmp ftrace_stub
17028 -END(function_hook)
17029 +ENDPROC(function_hook)
17030 #endif /* CONFIG_DYNAMIC_FTRACE */
17031 #endif /* CONFIG_FUNCTION_TRACER */
17032
17033 @@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
17034
17035 MCOUNT_RESTORE_FRAME
17036
17037 + pax_force_retaddr
17038 retq
17039 -END(ftrace_graph_caller)
17040 +ENDPROC(ftrace_graph_caller)
17041
17042 GLOBAL(return_to_handler)
17043 subq $24, %rsp
17044 @@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
17045 movq 8(%rsp), %rdx
17046 movq (%rsp), %rax
17047 addq $24, %rsp
17048 + pax_force_fptr %rdi
17049 jmp *%rdi
17050 +ENDPROC(return_to_handler)
17051 #endif
17052
17053
17054 @@ -284,6 +293,273 @@ ENTRY(native_usergs_sysret64)
17055 ENDPROC(native_usergs_sysret64)
17056 #endif /* CONFIG_PARAVIRT */
17057
17058 + .macro ljmpq sel, off
17059 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
17060 + .byte 0x48; ljmp *1234f(%rip)
17061 + .pushsection .rodata
17062 + .align 16
17063 + 1234: .quad \off; .word \sel
17064 + .popsection
17065 +#else
17066 + pushq $\sel
17067 + pushq $\off
17068 + lretq
17069 +#endif
17070 + .endm
17071 +
17072 + .macro pax_enter_kernel
17073 + pax_set_fptr_mask
17074 +#ifdef CONFIG_PAX_KERNEXEC
17075 + call pax_enter_kernel
17076 +#endif
17077 + .endm
17078 +
17079 + .macro pax_exit_kernel
17080 +#ifdef CONFIG_PAX_KERNEXEC
17081 + call pax_exit_kernel
17082 +#endif
17083 + .endm
17084 +
17085 +#ifdef CONFIG_PAX_KERNEXEC
17086 +ENTRY(pax_enter_kernel)
17087 + pushq %rdi
17088 +
17089 +#ifdef CONFIG_PARAVIRT
17090 + PV_SAVE_REGS(CLBR_RDI)
17091 +#endif
17092 +
17093 + GET_CR0_INTO_RDI
17094 + bts $16,%rdi
17095 + jnc 3f
17096 + mov %cs,%edi
17097 + cmp $__KERNEL_CS,%edi
17098 + jnz 2f
17099 +1:
17100 +
17101 +#ifdef CONFIG_PARAVIRT
17102 + PV_RESTORE_REGS(CLBR_RDI)
17103 +#endif
17104 +
17105 + popq %rdi
17106 + pax_force_retaddr
17107 + retq
17108 +
17109 +2: ljmpq __KERNEL_CS,1f
17110 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
17111 +4: SET_RDI_INTO_CR0
17112 + jmp 1b
17113 +ENDPROC(pax_enter_kernel)
17114 +
17115 +ENTRY(pax_exit_kernel)
17116 + pushq %rdi
17117 +
17118 +#ifdef CONFIG_PARAVIRT
17119 + PV_SAVE_REGS(CLBR_RDI)
17120 +#endif
17121 +
17122 + mov %cs,%rdi
17123 + cmp $__KERNEXEC_KERNEL_CS,%edi
17124 + jz 2f
17125 +1:
17126 +
17127 +#ifdef CONFIG_PARAVIRT
17128 + PV_RESTORE_REGS(CLBR_RDI);
17129 +#endif
17130 +
17131 + popq %rdi
17132 + pax_force_retaddr
17133 + retq
17134 +
17135 +2: GET_CR0_INTO_RDI
17136 + btr $16,%rdi
17137 + ljmpq __KERNEL_CS,3f
17138 +3: SET_RDI_INTO_CR0
17139 + jmp 1b
17140 +ENDPROC(pax_exit_kernel)
17141 +#endif
17142 +
17143 + .macro pax_enter_kernel_user
17144 + pax_set_fptr_mask
17145 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17146 + call pax_enter_kernel_user
17147 +#endif
17148 + .endm
17149 +
17150 + .macro pax_exit_kernel_user
17151 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17152 + call pax_exit_kernel_user
17153 +#endif
17154 +#ifdef CONFIG_PAX_RANDKSTACK
17155 + pushq %rax
17156 + call pax_randomize_kstack
17157 + popq %rax
17158 +#endif
17159 + .endm
17160 +
17161 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17162 +ENTRY(pax_enter_kernel_user)
17163 + pushq %rdi
17164 + pushq %rbx
17165 +
17166 +#ifdef CONFIG_PARAVIRT
17167 + PV_SAVE_REGS(CLBR_RDI)
17168 +#endif
17169 +
17170 + GET_CR3_INTO_RDI
17171 + mov %rdi,%rbx
17172 + add $__START_KERNEL_map,%rbx
17173 + sub phys_base(%rip),%rbx
17174 +
17175 +#ifdef CONFIG_PARAVIRT
17176 + pushq %rdi
17177 + cmpl $0, pv_info+PARAVIRT_enabled
17178 + jz 1f
17179 + i = 0
17180 + .rept USER_PGD_PTRS
17181 + mov i*8(%rbx),%rsi
17182 + mov $0,%sil
17183 + lea i*8(%rbx),%rdi
17184 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
17185 + i = i + 1
17186 + .endr
17187 + jmp 2f
17188 +1:
17189 +#endif
17190 +
17191 + i = 0
17192 + .rept USER_PGD_PTRS
17193 + movb $0,i*8(%rbx)
17194 + i = i + 1
17195 + .endr
17196 +
17197 +#ifdef CONFIG_PARAVIRT
17198 +2: popq %rdi
17199 +#endif
17200 + SET_RDI_INTO_CR3
17201 +
17202 +#ifdef CONFIG_PAX_KERNEXEC
17203 + GET_CR0_INTO_RDI
17204 + bts $16,%rdi
17205 + SET_RDI_INTO_CR0
17206 +#endif
17207 +
17208 +#ifdef CONFIG_PARAVIRT
17209 + PV_RESTORE_REGS(CLBR_RDI)
17210 +#endif
17211 +
17212 + popq %rbx
17213 + popq %rdi
17214 + pax_force_retaddr
17215 + retq
17216 +ENDPROC(pax_enter_kernel_user)
17217 +
17218 +ENTRY(pax_exit_kernel_user)
17219 + push %rdi
17220 +
17221 +#ifdef CONFIG_PARAVIRT
17222 + pushq %rbx
17223 + PV_SAVE_REGS(CLBR_RDI)
17224 +#endif
17225 +
17226 +#ifdef CONFIG_PAX_KERNEXEC
17227 + GET_CR0_INTO_RDI
17228 + btr $16,%rdi
17229 + SET_RDI_INTO_CR0
17230 +#endif
17231 +
17232 + GET_CR3_INTO_RDI
17233 + add $__START_KERNEL_map,%rdi
17234 + sub phys_base(%rip),%rdi
17235 +
17236 +#ifdef CONFIG_PARAVIRT
17237 + cmpl $0, pv_info+PARAVIRT_enabled
17238 + jz 1f
17239 + mov %rdi,%rbx
17240 + i = 0
17241 + .rept USER_PGD_PTRS
17242 + mov i*8(%rbx),%rsi
17243 + mov $0x67,%sil
17244 + lea i*8(%rbx),%rdi
17245 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
17246 + i = i + 1
17247 + .endr
17248 + jmp 2f
17249 +1:
17250 +#endif
17251 +
17252 + i = 0
17253 + .rept USER_PGD_PTRS
17254 + movb $0x67,i*8(%rdi)
17255 + i = i + 1
17256 + .endr
17257 +
17258 +#ifdef CONFIG_PARAVIRT
17259 +2: PV_RESTORE_REGS(CLBR_RDI)
17260 + popq %rbx
17261 +#endif
17262 +
17263 + popq %rdi
17264 + pax_force_retaddr
17265 + retq
17266 +ENDPROC(pax_exit_kernel_user)
17267 +#endif
17268 +
17269 +.macro pax_erase_kstack
17270 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17271 + call pax_erase_kstack
17272 +#endif
17273 +.endm
17274 +
17275 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17276 +ENTRY(pax_erase_kstack)
17277 + pushq %rdi
17278 + pushq %rcx
17279 + pushq %rax
17280 + pushq %r11
17281 +
17282 + GET_THREAD_INFO(%r11)
17283 + mov TI_lowest_stack(%r11), %rdi
17284 + mov $-0xBEEF, %rax
17285 + std
17286 +
17287 +1: mov %edi, %ecx
17288 + and $THREAD_SIZE_asm - 1, %ecx
17289 + shr $3, %ecx
17290 + repne scasq
17291 + jecxz 2f
17292 +
17293 + cmp $2*8, %ecx
17294 + jc 2f
17295 +
17296 + mov $2*8, %ecx
17297 + repe scasq
17298 + jecxz 2f
17299 + jne 1b
17300 +
17301 +2: cld
17302 + mov %esp, %ecx
17303 + sub %edi, %ecx
17304 +
17305 + cmp $THREAD_SIZE_asm, %rcx
17306 + jb 3f
17307 + ud2
17308 +3:
17309 +
17310 + shr $3, %ecx
17311 + rep stosq
17312 +
17313 + mov TI_task_thread_sp0(%r11), %rdi
17314 + sub $256, %rdi
17315 + mov %rdi, TI_lowest_stack(%r11)
17316 +
17317 + popq %r11
17318 + popq %rax
17319 + popq %rcx
17320 + popq %rdi
17321 + pax_force_retaddr
17322 + ret
17323 +ENDPROC(pax_erase_kstack)
17324 +#endif
17325
17326 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
17327 #ifdef CONFIG_TRACE_IRQFLAGS
17328 @@ -375,8 +651,8 @@ ENDPROC(native_usergs_sysret64)
17329 .endm
17330
17331 .macro UNFAKE_STACK_FRAME
17332 - addq $8*6, %rsp
17333 - CFI_ADJUST_CFA_OFFSET -(6*8)
17334 + addq $8*6 + ARG_SKIP, %rsp
17335 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
17336 .endm
17337
17338 /*
17339 @@ -463,7 +739,7 @@ ENDPROC(native_usergs_sysret64)
17340 movq %rsp, %rsi
17341
17342 leaq -RBP(%rsp),%rdi /* arg1 for handler */
17343 - testl $3, CS-RBP(%rsi)
17344 + testb $3, CS-RBP(%rsi)
17345 je 1f
17346 SWAPGS
17347 /*
17348 @@ -498,9 +774,10 @@ ENTRY(save_rest)
17349 movq_cfi r15, R15+16
17350 movq %r11, 8(%rsp) /* return address */
17351 FIXUP_TOP_OF_STACK %r11, 16
17352 + pax_force_retaddr
17353 ret
17354 CFI_ENDPROC
17355 -END(save_rest)
17356 +ENDPROC(save_rest)
17357
17358 /* save complete stack frame */
17359 .pushsection .kprobes.text, "ax"
17360 @@ -529,9 +806,10 @@ ENTRY(save_paranoid)
17361 js 1f /* negative -> in kernel */
17362 SWAPGS
17363 xorl %ebx,%ebx
17364 -1: ret
17365 +1: pax_force_retaddr_bts
17366 + ret
17367 CFI_ENDPROC
17368 -END(save_paranoid)
17369 +ENDPROC(save_paranoid)
17370 .popsection
17371
17372 /*
17373 @@ -553,7 +831,7 @@ ENTRY(ret_from_fork)
17374
17375 RESTORE_REST
17376
17377 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
17378 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
17379 jz 1f
17380
17381 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
17382 @@ -571,7 +849,7 @@ ENTRY(ret_from_fork)
17383 RESTORE_REST
17384 jmp int_ret_from_sys_call
17385 CFI_ENDPROC
17386 -END(ret_from_fork)
17387 +ENDPROC(ret_from_fork)
17388
17389 /*
17390 * System call entry. Up to 6 arguments in registers are supported.
17391 @@ -608,7 +886,7 @@ END(ret_from_fork)
17392 ENTRY(system_call)
17393 CFI_STARTPROC simple
17394 CFI_SIGNAL_FRAME
17395 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
17396 + CFI_DEF_CFA rsp,0
17397 CFI_REGISTER rip,rcx
17398 /*CFI_REGISTER rflags,r11*/
17399 SWAPGS_UNSAFE_STACK
17400 @@ -621,16 +899,23 @@ GLOBAL(system_call_after_swapgs)
17401
17402 movq %rsp,PER_CPU_VAR(old_rsp)
17403 movq PER_CPU_VAR(kernel_stack),%rsp
17404 + SAVE_ARGS 8*6,0
17405 + pax_enter_kernel_user
17406 +
17407 +#ifdef CONFIG_PAX_RANDKSTACK
17408 + pax_erase_kstack
17409 +#endif
17410 +
17411 /*
17412 * No need to follow this irqs off/on section - it's straight
17413 * and short:
17414 */
17415 ENABLE_INTERRUPTS(CLBR_NONE)
17416 - SAVE_ARGS 8,0
17417 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
17418 movq %rcx,RIP-ARGOFFSET(%rsp)
17419 CFI_REL_OFFSET rip,RIP-ARGOFFSET
17420 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
17421 + GET_THREAD_INFO(%rcx)
17422 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
17423 jnz tracesys
17424 system_call_fastpath:
17425 #if __SYSCALL_MASK == ~0
17426 @@ -640,7 +925,7 @@ system_call_fastpath:
17427 cmpl $__NR_syscall_max,%eax
17428 #endif
17429 ja badsys
17430 - movq %r10,%rcx
17431 + movq R10-ARGOFFSET(%rsp),%rcx
17432 call *sys_call_table(,%rax,8) # XXX: rip relative
17433 movq %rax,RAX-ARGOFFSET(%rsp)
17434 /*
17435 @@ -654,10 +939,13 @@ sysret_check:
17436 LOCKDEP_SYS_EXIT
17437 DISABLE_INTERRUPTS(CLBR_NONE)
17438 TRACE_IRQS_OFF
17439 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
17440 + GET_THREAD_INFO(%rcx)
17441 + movl TI_flags(%rcx),%edx
17442 andl %edi,%edx
17443 jnz sysret_careful
17444 CFI_REMEMBER_STATE
17445 + pax_exit_kernel_user
17446 + pax_erase_kstack
17447 /*
17448 * sysretq will re-enable interrupts:
17449 */
17450 @@ -709,14 +997,18 @@ badsys:
17451 * jump back to the normal fast path.
17452 */
17453 auditsys:
17454 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
17455 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
17456 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
17457 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
17458 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
17459 movq %rax,%rsi /* 2nd arg: syscall number */
17460 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
17461 call __audit_syscall_entry
17462 +
17463 + pax_erase_kstack
17464 +
17465 LOAD_ARGS 0 /* reload call-clobbered registers */
17466 + pax_set_fptr_mask
17467 jmp system_call_fastpath
17468
17469 /*
17470 @@ -737,7 +1029,7 @@ sysret_audit:
17471 /* Do syscall tracing */
17472 tracesys:
17473 #ifdef CONFIG_AUDITSYSCALL
17474 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
17475 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
17476 jz auditsys
17477 #endif
17478 SAVE_REST
17479 @@ -745,12 +1037,16 @@ tracesys:
17480 FIXUP_TOP_OF_STACK %rdi
17481 movq %rsp,%rdi
17482 call syscall_trace_enter
17483 +
17484 + pax_erase_kstack
17485 +
17486 /*
17487 * Reload arg registers from stack in case ptrace changed them.
17488 * We don't reload %rax because syscall_trace_enter() returned
17489 * the value it wants us to use in the table lookup.
17490 */
17491 LOAD_ARGS ARGOFFSET, 1
17492 + pax_set_fptr_mask
17493 RESTORE_REST
17494 #if __SYSCALL_MASK == ~0
17495 cmpq $__NR_syscall_max,%rax
17496 @@ -759,7 +1055,7 @@ tracesys:
17497 cmpl $__NR_syscall_max,%eax
17498 #endif
17499 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
17500 - movq %r10,%rcx /* fixup for C */
17501 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
17502 call *sys_call_table(,%rax,8)
17503 movq %rax,RAX-ARGOFFSET(%rsp)
17504 /* Use IRET because user could have changed frame */
17505 @@ -780,7 +1076,9 @@ GLOBAL(int_with_check)
17506 andl %edi,%edx
17507 jnz int_careful
17508 andl $~TS_COMPAT,TI_status(%rcx)
17509 - jmp retint_swapgs
17510 + pax_exit_kernel_user
17511 + pax_erase_kstack
17512 + jmp retint_swapgs_pax
17513
17514 /* Either reschedule or signal or syscall exit tracking needed. */
17515 /* First do a reschedule test. */
17516 @@ -826,7 +1124,7 @@ int_restore_rest:
17517 TRACE_IRQS_OFF
17518 jmp int_with_check
17519 CFI_ENDPROC
17520 -END(system_call)
17521 +ENDPROC(system_call)
17522
17523 /*
17524 * Certain special system calls that need to save a complete full stack frame.
17525 @@ -842,7 +1140,7 @@ ENTRY(\label)
17526 call \func
17527 jmp ptregscall_common
17528 CFI_ENDPROC
17529 -END(\label)
17530 +ENDPROC(\label)
17531 .endm
17532
17533 PTREGSCALL stub_clone, sys_clone, %r8
17534 @@ -860,9 +1158,10 @@ ENTRY(ptregscall_common)
17535 movq_cfi_restore R12+8, r12
17536 movq_cfi_restore RBP+8, rbp
17537 movq_cfi_restore RBX+8, rbx
17538 + pax_force_retaddr
17539 ret $REST_SKIP /* pop extended registers */
17540 CFI_ENDPROC
17541 -END(ptregscall_common)
17542 +ENDPROC(ptregscall_common)
17543
17544 ENTRY(stub_execve)
17545 CFI_STARTPROC
17546 @@ -876,7 +1175,7 @@ ENTRY(stub_execve)
17547 RESTORE_REST
17548 jmp int_ret_from_sys_call
17549 CFI_ENDPROC
17550 -END(stub_execve)
17551 +ENDPROC(stub_execve)
17552
17553 /*
17554 * sigreturn is special because it needs to restore all registers on return.
17555 @@ -894,7 +1193,7 @@ ENTRY(stub_rt_sigreturn)
17556 RESTORE_REST
17557 jmp int_ret_from_sys_call
17558 CFI_ENDPROC
17559 -END(stub_rt_sigreturn)
17560 +ENDPROC(stub_rt_sigreturn)
17561
17562 #ifdef CONFIG_X86_X32_ABI
17563 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
17564 @@ -962,7 +1261,7 @@ vector=vector+1
17565 2: jmp common_interrupt
17566 .endr
17567 CFI_ENDPROC
17568 -END(irq_entries_start)
17569 +ENDPROC(irq_entries_start)
17570
17571 .previous
17572 END(interrupt)
17573 @@ -982,6 +1281,16 @@ END(interrupt)
17574 subq $ORIG_RAX-RBP, %rsp
17575 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
17576 SAVE_ARGS_IRQ
17577 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17578 + testb $3, CS(%rdi)
17579 + jnz 1f
17580 + pax_enter_kernel
17581 + jmp 2f
17582 +1: pax_enter_kernel_user
17583 +2:
17584 +#else
17585 + pax_enter_kernel
17586 +#endif
17587 call \func
17588 .endm
17589
17590 @@ -1014,7 +1323,7 @@ ret_from_intr:
17591
17592 exit_intr:
17593 GET_THREAD_INFO(%rcx)
17594 - testl $3,CS-ARGOFFSET(%rsp)
17595 + testb $3,CS-ARGOFFSET(%rsp)
17596 je retint_kernel
17597
17598 /* Interrupt came from user space */
17599 @@ -1036,12 +1345,16 @@ retint_swapgs: /* return to user-space */
17600 * The iretq could re-enable interrupts:
17601 */
17602 DISABLE_INTERRUPTS(CLBR_ANY)
17603 + pax_exit_kernel_user
17604 +retint_swapgs_pax:
17605 TRACE_IRQS_IRETQ
17606 SWAPGS
17607 jmp restore_args
17608
17609 retint_restore_args: /* return to kernel space */
17610 DISABLE_INTERRUPTS(CLBR_ANY)
17611 + pax_exit_kernel
17612 + pax_force_retaddr (RIP-ARGOFFSET)
17613 /*
17614 * The iretq could re-enable interrupts:
17615 */
17616 @@ -1124,7 +1437,7 @@ ENTRY(retint_kernel)
17617 #endif
17618
17619 CFI_ENDPROC
17620 -END(common_interrupt)
17621 +ENDPROC(common_interrupt)
17622 /*
17623 * End of kprobes section
17624 */
17625 @@ -1142,7 +1455,7 @@ ENTRY(\sym)
17626 interrupt \do_sym
17627 jmp ret_from_intr
17628 CFI_ENDPROC
17629 -END(\sym)
17630 +ENDPROC(\sym)
17631 .endm
17632
17633 #ifdef CONFIG_SMP
17634 @@ -1198,12 +1511,22 @@ ENTRY(\sym)
17635 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17636 call error_entry
17637 DEFAULT_FRAME 0
17638 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17639 + testb $3, CS(%rsp)
17640 + jnz 1f
17641 + pax_enter_kernel
17642 + jmp 2f
17643 +1: pax_enter_kernel_user
17644 +2:
17645 +#else
17646 + pax_enter_kernel
17647 +#endif
17648 movq %rsp,%rdi /* pt_regs pointer */
17649 xorl %esi,%esi /* no error code */
17650 call \do_sym
17651 jmp error_exit /* %ebx: no swapgs flag */
17652 CFI_ENDPROC
17653 -END(\sym)
17654 +ENDPROC(\sym)
17655 .endm
17656
17657 .macro paranoidzeroentry sym do_sym
17658 @@ -1216,15 +1539,25 @@ ENTRY(\sym)
17659 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17660 call save_paranoid
17661 TRACE_IRQS_OFF
17662 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17663 + testb $3, CS(%rsp)
17664 + jnz 1f
17665 + pax_enter_kernel
17666 + jmp 2f
17667 +1: pax_enter_kernel_user
17668 +2:
17669 +#else
17670 + pax_enter_kernel
17671 +#endif
17672 movq %rsp,%rdi /* pt_regs pointer */
17673 xorl %esi,%esi /* no error code */
17674 call \do_sym
17675 jmp paranoid_exit /* %ebx: no swapgs flag */
17676 CFI_ENDPROC
17677 -END(\sym)
17678 +ENDPROC(\sym)
17679 .endm
17680
17681 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
17682 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
17683 .macro paranoidzeroentry_ist sym do_sym ist
17684 ENTRY(\sym)
17685 INTR_FRAME
17686 @@ -1235,14 +1568,30 @@ ENTRY(\sym)
17687 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17688 call save_paranoid
17689 TRACE_IRQS_OFF_DEBUG
17690 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17691 + testb $3, CS(%rsp)
17692 + jnz 1f
17693 + pax_enter_kernel
17694 + jmp 2f
17695 +1: pax_enter_kernel_user
17696 +2:
17697 +#else
17698 + pax_enter_kernel
17699 +#endif
17700 movq %rsp,%rdi /* pt_regs pointer */
17701 xorl %esi,%esi /* no error code */
17702 +#ifdef CONFIG_SMP
17703 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
17704 + lea init_tss(%r12), %r12
17705 +#else
17706 + lea init_tss(%rip), %r12
17707 +#endif
17708 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
17709 call \do_sym
17710 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
17711 jmp paranoid_exit /* %ebx: no swapgs flag */
17712 CFI_ENDPROC
17713 -END(\sym)
17714 +ENDPROC(\sym)
17715 .endm
17716
17717 .macro errorentry sym do_sym
17718 @@ -1254,13 +1603,23 @@ ENTRY(\sym)
17719 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17720 call error_entry
17721 DEFAULT_FRAME 0
17722 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17723 + testb $3, CS(%rsp)
17724 + jnz 1f
17725 + pax_enter_kernel
17726 + jmp 2f
17727 +1: pax_enter_kernel_user
17728 +2:
17729 +#else
17730 + pax_enter_kernel
17731 +#endif
17732 movq %rsp,%rdi /* pt_regs pointer */
17733 movq ORIG_RAX(%rsp),%rsi /* get error code */
17734 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
17735 call \do_sym
17736 jmp error_exit /* %ebx: no swapgs flag */
17737 CFI_ENDPROC
17738 -END(\sym)
17739 +ENDPROC(\sym)
17740 .endm
17741
17742 /* error code is on the stack already */
17743 @@ -1274,13 +1633,23 @@ ENTRY(\sym)
17744 call save_paranoid
17745 DEFAULT_FRAME 0
17746 TRACE_IRQS_OFF
17747 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17748 + testb $3, CS(%rsp)
17749 + jnz 1f
17750 + pax_enter_kernel
17751 + jmp 2f
17752 +1: pax_enter_kernel_user
17753 +2:
17754 +#else
17755 + pax_enter_kernel
17756 +#endif
17757 movq %rsp,%rdi /* pt_regs pointer */
17758 movq ORIG_RAX(%rsp),%rsi /* get error code */
17759 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
17760 call \do_sym
17761 jmp paranoid_exit /* %ebx: no swapgs flag */
17762 CFI_ENDPROC
17763 -END(\sym)
17764 +ENDPROC(\sym)
17765 .endm
17766
17767 zeroentry divide_error do_divide_error
17768 @@ -1310,9 +1679,10 @@ gs_change:
17769 2: mfence /* workaround */
17770 SWAPGS
17771 popfq_cfi
17772 + pax_force_retaddr
17773 ret
17774 CFI_ENDPROC
17775 -END(native_load_gs_index)
17776 +ENDPROC(native_load_gs_index)
17777
17778 _ASM_EXTABLE(gs_change,bad_gs)
17779 .section .fixup,"ax"
17780 @@ -1340,9 +1710,10 @@ ENTRY(call_softirq)
17781 CFI_DEF_CFA_REGISTER rsp
17782 CFI_ADJUST_CFA_OFFSET -8
17783 decl PER_CPU_VAR(irq_count)
17784 + pax_force_retaddr
17785 ret
17786 CFI_ENDPROC
17787 -END(call_softirq)
17788 +ENDPROC(call_softirq)
17789
17790 #ifdef CONFIG_XEN
17791 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
17792 @@ -1380,7 +1751,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
17793 decl PER_CPU_VAR(irq_count)
17794 jmp error_exit
17795 CFI_ENDPROC
17796 -END(xen_do_hypervisor_callback)
17797 +ENDPROC(xen_do_hypervisor_callback)
17798
17799 /*
17800 * Hypervisor uses this for application faults while it executes.
17801 @@ -1439,7 +1810,7 @@ ENTRY(xen_failsafe_callback)
17802 SAVE_ALL
17803 jmp error_exit
17804 CFI_ENDPROC
17805 -END(xen_failsafe_callback)
17806 +ENDPROC(xen_failsafe_callback)
17807
17808 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
17809 xen_hvm_callback_vector xen_evtchn_do_upcall
17810 @@ -1488,16 +1859,31 @@ ENTRY(paranoid_exit)
17811 TRACE_IRQS_OFF_DEBUG
17812 testl %ebx,%ebx /* swapgs needed? */
17813 jnz paranoid_restore
17814 - testl $3,CS(%rsp)
17815 + testb $3,CS(%rsp)
17816 jnz paranoid_userspace
17817 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17818 + pax_exit_kernel
17819 + TRACE_IRQS_IRETQ 0
17820 + SWAPGS_UNSAFE_STACK
17821 + RESTORE_ALL 8
17822 + pax_force_retaddr_bts
17823 + jmp irq_return
17824 +#endif
17825 paranoid_swapgs:
17826 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17827 + pax_exit_kernel_user
17828 +#else
17829 + pax_exit_kernel
17830 +#endif
17831 TRACE_IRQS_IRETQ 0
17832 SWAPGS_UNSAFE_STACK
17833 RESTORE_ALL 8
17834 jmp irq_return
17835 paranoid_restore:
17836 + pax_exit_kernel
17837 TRACE_IRQS_IRETQ_DEBUG 0
17838 RESTORE_ALL 8
17839 + pax_force_retaddr_bts
17840 jmp irq_return
17841 paranoid_userspace:
17842 GET_THREAD_INFO(%rcx)
17843 @@ -1526,7 +1912,7 @@ paranoid_schedule:
17844 TRACE_IRQS_OFF
17845 jmp paranoid_userspace
17846 CFI_ENDPROC
17847 -END(paranoid_exit)
17848 +ENDPROC(paranoid_exit)
17849
17850 /*
17851 * Exception entry point. This expects an error code/orig_rax on the stack.
17852 @@ -1553,12 +1939,13 @@ ENTRY(error_entry)
17853 movq_cfi r14, R14+8
17854 movq_cfi r15, R15+8
17855 xorl %ebx,%ebx
17856 - testl $3,CS+8(%rsp)
17857 + testb $3,CS+8(%rsp)
17858 je error_kernelspace
17859 error_swapgs:
17860 SWAPGS
17861 error_sti:
17862 TRACE_IRQS_OFF
17863 + pax_force_retaddr_bts
17864 ret
17865
17866 /*
17867 @@ -1585,7 +1972,7 @@ bstep_iret:
17868 movq %rcx,RIP+8(%rsp)
17869 jmp error_swapgs
17870 CFI_ENDPROC
17871 -END(error_entry)
17872 +ENDPROC(error_entry)
17873
17874
17875 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
17876 @@ -1605,7 +1992,7 @@ ENTRY(error_exit)
17877 jnz retint_careful
17878 jmp retint_swapgs
17879 CFI_ENDPROC
17880 -END(error_exit)
17881 +ENDPROC(error_exit)
17882
17883 /*
17884 * Test if a given stack is an NMI stack or not.
17885 @@ -1663,9 +2050,11 @@ ENTRY(nmi)
17886 * If %cs was not the kernel segment, then the NMI triggered in user
17887 * space, which means it is definitely not nested.
17888 */
17889 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
17890 + je 1f
17891 cmpl $__KERNEL_CS, 16(%rsp)
17892 jne first_nmi
17893 -
17894 +1:
17895 /*
17896 * Check the special variable on the stack to see if NMIs are
17897 * executing.
17898 @@ -1824,6 +2213,17 @@ end_repeat_nmi:
17899 */
17900 movq %cr2, %r12
17901
17902 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17903 + testb $3, CS(%rsp)
17904 + jnz 1f
17905 + pax_enter_kernel
17906 + jmp 2f
17907 +1: pax_enter_kernel_user
17908 +2:
17909 +#else
17910 + pax_enter_kernel
17911 +#endif
17912 +
17913 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
17914 movq %rsp,%rdi
17915 movq $-1,%rsi
17916 @@ -1839,21 +2239,32 @@ end_repeat_nmi:
17917 testl %ebx,%ebx /* swapgs needed? */
17918 jnz nmi_restore
17919 nmi_swapgs:
17920 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17921 + pax_exit_kernel_user
17922 +#else
17923 + pax_exit_kernel
17924 +#endif
17925 SWAPGS_UNSAFE_STACK
17926 + RESTORE_ALL 8
17927 + /* Clear the NMI executing stack variable */
17928 + movq $0, 10*8(%rsp)
17929 + jmp irq_return
17930 nmi_restore:
17931 + pax_exit_kernel
17932 RESTORE_ALL 8
17933 + pax_force_retaddr_bts
17934 /* Clear the NMI executing stack variable */
17935 movq $0, 10*8(%rsp)
17936 jmp irq_return
17937 CFI_ENDPROC
17938 -END(nmi)
17939 +ENDPROC(nmi)
17940
17941 ENTRY(ignore_sysret)
17942 CFI_STARTPROC
17943 mov $-ENOSYS,%eax
17944 sysret
17945 CFI_ENDPROC
17946 -END(ignore_sysret)
17947 +ENDPROC(ignore_sysret)
17948
17949 /*
17950 * End of kprobes section
17951 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
17952 index 1d41402..af9a46a 100644
17953 --- a/arch/x86/kernel/ftrace.c
17954 +++ b/arch/x86/kernel/ftrace.c
17955 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
17956 {
17957 unsigned char replaced[MCOUNT_INSN_SIZE];
17958
17959 + ip = ktla_ktva(ip);
17960 +
17961 /*
17962 * Note: Due to modules and __init, code can
17963 * disappear and change, we need to protect against faulting
17964 @@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
17965 unsigned char old[MCOUNT_INSN_SIZE], *new;
17966 int ret;
17967
17968 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
17969 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
17970 new = ftrace_call_replace(ip, (unsigned long)func);
17971
17972 /* See comment above by declaration of modifying_ftrace_code */
17973 @@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
17974 /* Also update the regs callback function */
17975 if (!ret) {
17976 ip = (unsigned long)(&ftrace_regs_call);
17977 - memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
17978 + memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
17979 new = ftrace_call_replace(ip, (unsigned long)func);
17980 ret = ftrace_modify_code(ip, old, new);
17981 }
17982 @@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
17983 * kernel identity mapping to modify code.
17984 */
17985 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
17986 - ip = (unsigned long)__va(__pa(ip));
17987 + ip = (unsigned long)__va(__pa(ktla_ktva(ip)));
17988
17989 return probe_kernel_write((void *)ip, val, size);
17990 }
17991 @@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
17992 unsigned char replaced[MCOUNT_INSN_SIZE];
17993 unsigned char brk = BREAKPOINT_INSTRUCTION;
17994
17995 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
17996 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
17997 return -EFAULT;
17998
17999 /* Make sure it is what we expect it to be */
18000 @@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
18001 return ret;
18002
18003 fail_update:
18004 - probe_kernel_write((void *)ip, &old_code[0], 1);
18005 + probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
18006 goto out;
18007 }
18008
18009 @@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
18010 {
18011 unsigned char code[MCOUNT_INSN_SIZE];
18012
18013 + ip = ktla_ktva(ip);
18014 +
18015 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
18016 return -EFAULT;
18017
18018 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
18019 index c18f59d..69ddbc4 100644
18020 --- a/arch/x86/kernel/head32.c
18021 +++ b/arch/x86/kernel/head32.c
18022 @@ -18,20 +18,20 @@
18023 #include <asm/io_apic.h>
18024 #include <asm/bios_ebda.h>
18025 #include <asm/tlbflush.h>
18026 +#include <asm/boot.h>
18027
18028 static void __init i386_default_early_setup(void)
18029 {
18030 /* Initialize 32bit specific setup functions */
18031 - x86_init.resources.reserve_resources = i386_reserve_resources;
18032 - x86_init.mpparse.setup_ioapic_ids = setup_ioapic_ids_from_mpc;
18033 + *(void **)&x86_init.resources.reserve_resources = i386_reserve_resources;
18034 + *(void **)&x86_init.mpparse.setup_ioapic_ids = setup_ioapic_ids_from_mpc;
18035
18036 reserve_ebda_region();
18037 }
18038
18039 void __init i386_start_kernel(void)
18040 {
18041 - memblock_reserve(__pa_symbol(&_text),
18042 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
18043 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
18044
18045 #ifdef CONFIG_BLK_DEV_INITRD
18046 /* Reserve INITRD */
18047 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
18048 index 4dac2f6..bc6a335 100644
18049 --- a/arch/x86/kernel/head_32.S
18050 +++ b/arch/x86/kernel/head_32.S
18051 @@ -26,6 +26,12 @@
18052 /* Physical address */
18053 #define pa(X) ((X) - __PAGE_OFFSET)
18054
18055 +#ifdef CONFIG_PAX_KERNEXEC
18056 +#define ta(X) (X)
18057 +#else
18058 +#define ta(X) ((X) - __PAGE_OFFSET)
18059 +#endif
18060 +
18061 /*
18062 * References to members of the new_cpu_data structure.
18063 */
18064 @@ -55,11 +61,7 @@
18065 * and small than max_low_pfn, otherwise will waste some page table entries
18066 */
18067
18068 -#if PTRS_PER_PMD > 1
18069 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
18070 -#else
18071 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
18072 -#endif
18073 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
18074
18075 /* Number of possible pages in the lowmem region */
18076 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
18077 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
18078 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
18079
18080 /*
18081 + * Real beginning of normal "text" segment
18082 + */
18083 +ENTRY(stext)
18084 +ENTRY(_stext)
18085 +
18086 +/*
18087 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
18088 * %esi points to the real-mode code as a 32-bit pointer.
18089 * CS and DS must be 4 GB flat segments, but we don't depend on
18090 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
18091 * can.
18092 */
18093 __HEAD
18094 +
18095 +#ifdef CONFIG_PAX_KERNEXEC
18096 + jmp startup_32
18097 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
18098 +.fill PAGE_SIZE-5,1,0xcc
18099 +#endif
18100 +
18101 ENTRY(startup_32)
18102 movl pa(stack_start),%ecx
18103
18104 @@ -106,6 +121,59 @@ ENTRY(startup_32)
18105 2:
18106 leal -__PAGE_OFFSET(%ecx),%esp
18107
18108 +#ifdef CONFIG_SMP
18109 + movl $pa(cpu_gdt_table),%edi
18110 + movl $__per_cpu_load,%eax
18111 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
18112 + rorl $16,%eax
18113 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
18114 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
18115 + movl $__per_cpu_end - 1,%eax
18116 + subl $__per_cpu_start,%eax
18117 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
18118 +#endif
18119 +
18120 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18121 + movl $NR_CPUS,%ecx
18122 + movl $pa(cpu_gdt_table),%edi
18123 +1:
18124 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
18125 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
18126 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
18127 + addl $PAGE_SIZE_asm,%edi
18128 + loop 1b
18129 +#endif
18130 +
18131 +#ifdef CONFIG_PAX_KERNEXEC
18132 + movl $pa(boot_gdt),%edi
18133 + movl $__LOAD_PHYSICAL_ADDR,%eax
18134 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
18135 + rorl $16,%eax
18136 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
18137 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
18138 + rorl $16,%eax
18139 +
18140 + ljmp $(__BOOT_CS),$1f
18141 +1:
18142 +
18143 + movl $NR_CPUS,%ecx
18144 + movl $pa(cpu_gdt_table),%edi
18145 + addl $__PAGE_OFFSET,%eax
18146 +1:
18147 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
18148 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
18149 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
18150 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
18151 + rorl $16,%eax
18152 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
18153 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
18154 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
18155 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
18156 + rorl $16,%eax
18157 + addl $PAGE_SIZE_asm,%edi
18158 + loop 1b
18159 +#endif
18160 +
18161 /*
18162 * Clear BSS first so that there are no surprises...
18163 */
18164 @@ -196,8 +264,11 @@ ENTRY(startup_32)
18165 movl %eax, pa(max_pfn_mapped)
18166
18167 /* Do early initialization of the fixmap area */
18168 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
18169 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
18170 +#ifdef CONFIG_COMPAT_VDSO
18171 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
18172 +#else
18173 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
18174 +#endif
18175 #else /* Not PAE */
18176
18177 page_pde_offset = (__PAGE_OFFSET >> 20);
18178 @@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
18179 movl %eax, pa(max_pfn_mapped)
18180
18181 /* Do early initialization of the fixmap area */
18182 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
18183 - movl %eax,pa(initial_page_table+0xffc)
18184 +#ifdef CONFIG_COMPAT_VDSO
18185 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
18186 +#else
18187 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
18188 +#endif
18189 #endif
18190
18191 #ifdef CONFIG_PARAVIRT
18192 @@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
18193 cmpl $num_subarch_entries, %eax
18194 jae bad_subarch
18195
18196 - movl pa(subarch_entries)(,%eax,4), %eax
18197 - subl $__PAGE_OFFSET, %eax
18198 - jmp *%eax
18199 + jmp *pa(subarch_entries)(,%eax,4)
18200
18201 bad_subarch:
18202 WEAK(lguest_entry)
18203 @@ -256,10 +328,10 @@ WEAK(xen_entry)
18204 __INITDATA
18205
18206 subarch_entries:
18207 - .long default_entry /* normal x86/PC */
18208 - .long lguest_entry /* lguest hypervisor */
18209 - .long xen_entry /* Xen hypervisor */
18210 - .long default_entry /* Moorestown MID */
18211 + .long ta(default_entry) /* normal x86/PC */
18212 + .long ta(lguest_entry) /* lguest hypervisor */
18213 + .long ta(xen_entry) /* Xen hypervisor */
18214 + .long ta(default_entry) /* Moorestown MID */
18215 num_subarch_entries = (. - subarch_entries) / 4
18216 .previous
18217 #else
18218 @@ -316,6 +388,7 @@ default_entry:
18219 movl pa(mmu_cr4_features),%eax
18220 movl %eax,%cr4
18221
18222 +#ifdef CONFIG_X86_PAE
18223 testb $X86_CR4_PAE, %al # check if PAE is enabled
18224 jz 6f
18225
18226 @@ -344,6 +417,9 @@ default_entry:
18227 /* Make changes effective */
18228 wrmsr
18229
18230 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
18231 +#endif
18232 +
18233 6:
18234
18235 /*
18236 @@ -442,14 +518,20 @@ is386: movl $2,%ecx # set MP
18237 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
18238 movl %eax,%ss # after changing gdt.
18239
18240 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
18241 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
18242 movl %eax,%ds
18243 movl %eax,%es
18244
18245 movl $(__KERNEL_PERCPU), %eax
18246 movl %eax,%fs # set this cpu's percpu
18247
18248 +#ifdef CONFIG_CC_STACKPROTECTOR
18249 movl $(__KERNEL_STACK_CANARY),%eax
18250 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
18251 + movl $(__USER_DS),%eax
18252 +#else
18253 + xorl %eax,%eax
18254 +#endif
18255 movl %eax,%gs
18256
18257 xorl %eax,%eax # Clear LDT
18258 @@ -526,8 +608,11 @@ setup_once:
18259 * relocation. Manually set base address in stack canary
18260 * segment descriptor.
18261 */
18262 - movl $gdt_page,%eax
18263 + movl $cpu_gdt_table,%eax
18264 movl $stack_canary,%ecx
18265 +#ifdef CONFIG_SMP
18266 + addl $__per_cpu_load,%ecx
18267 +#endif
18268 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
18269 shrl $16, %ecx
18270 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
18271 @@ -558,7 +643,7 @@ ENDPROC(early_idt_handlers)
18272 /* This is global to keep gas from relaxing the jumps */
18273 ENTRY(early_idt_handler)
18274 cld
18275 - cmpl $2,%ss:early_recursion_flag
18276 + cmpl $1,%ss:early_recursion_flag
18277 je hlt_loop
18278 incl %ss:early_recursion_flag
18279
18280 @@ -596,8 +681,8 @@ ENTRY(early_idt_handler)
18281 pushl (20+6*4)(%esp) /* trapno */
18282 pushl $fault_msg
18283 call printk
18284 -#endif
18285 call dump_stack
18286 +#endif
18287 hlt_loop:
18288 hlt
18289 jmp hlt_loop
18290 @@ -616,8 +701,11 @@ ENDPROC(early_idt_handler)
18291 /* This is the default interrupt "handler" :-) */
18292 ALIGN
18293 ignore_int:
18294 - cld
18295 #ifdef CONFIG_PRINTK
18296 + cmpl $2,%ss:early_recursion_flag
18297 + je hlt_loop
18298 + incl %ss:early_recursion_flag
18299 + cld
18300 pushl %eax
18301 pushl %ecx
18302 pushl %edx
18303 @@ -626,9 +714,6 @@ ignore_int:
18304 movl $(__KERNEL_DS),%eax
18305 movl %eax,%ds
18306 movl %eax,%es
18307 - cmpl $2,early_recursion_flag
18308 - je hlt_loop
18309 - incl early_recursion_flag
18310 pushl 16(%esp)
18311 pushl 24(%esp)
18312 pushl 32(%esp)
18313 @@ -662,29 +747,43 @@ ENTRY(setup_once_ref)
18314 /*
18315 * BSS section
18316 */
18317 -__PAGE_ALIGNED_BSS
18318 - .align PAGE_SIZE
18319 #ifdef CONFIG_X86_PAE
18320 +.section .initial_pg_pmd,"a",@progbits
18321 initial_pg_pmd:
18322 .fill 1024*KPMDS,4,0
18323 #else
18324 +.section .initial_page_table,"a",@progbits
18325 ENTRY(initial_page_table)
18326 .fill 1024,4,0
18327 #endif
18328 +.section .initial_pg_fixmap,"a",@progbits
18329 initial_pg_fixmap:
18330 .fill 1024,4,0
18331 +.section .empty_zero_page,"a",@progbits
18332 ENTRY(empty_zero_page)
18333 .fill 4096,1,0
18334 +.section .swapper_pg_dir,"a",@progbits
18335 ENTRY(swapper_pg_dir)
18336 +#ifdef CONFIG_X86_PAE
18337 + .fill 4,8,0
18338 +#else
18339 .fill 1024,4,0
18340 +#endif
18341 +
18342 +/*
18343 + * The IDT has to be page-aligned to simplify the Pentium
18344 + * F0 0F bug workaround.. We have a special link segment
18345 + * for this.
18346 + */
18347 +.section .idt,"a",@progbits
18348 +ENTRY(idt_table)
18349 + .fill 256,8,0
18350
18351 /*
18352 * This starts the data section.
18353 */
18354 #ifdef CONFIG_X86_PAE
18355 -__PAGE_ALIGNED_DATA
18356 - /* Page-aligned for the benefit of paravirt? */
18357 - .align PAGE_SIZE
18358 +.section .initial_page_table,"a",@progbits
18359 ENTRY(initial_page_table)
18360 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
18361 # if KPMDS == 3
18362 @@ -703,12 +802,20 @@ ENTRY(initial_page_table)
18363 # error "Kernel PMDs should be 1, 2 or 3"
18364 # endif
18365 .align PAGE_SIZE /* needs to be page-sized too */
18366 +
18367 +#ifdef CONFIG_PAX_PER_CPU_PGD
18368 +ENTRY(cpu_pgd)
18369 + .rept NR_CPUS
18370 + .fill 4,8,0
18371 + .endr
18372 +#endif
18373 +
18374 #endif
18375
18376 .data
18377 .balign 4
18378 ENTRY(stack_start)
18379 - .long init_thread_union+THREAD_SIZE
18380 + .long init_thread_union+THREAD_SIZE-8
18381
18382 __INITRODATA
18383 int_msg:
18384 @@ -736,7 +843,7 @@ fault_msg:
18385 * segment size, and 32-bit linear address value:
18386 */
18387
18388 - .data
18389 +.section .rodata,"a",@progbits
18390 .globl boot_gdt_descr
18391 .globl idt_descr
18392
18393 @@ -745,7 +852,7 @@ fault_msg:
18394 .word 0 # 32 bit align gdt_desc.address
18395 boot_gdt_descr:
18396 .word __BOOT_DS+7
18397 - .long boot_gdt - __PAGE_OFFSET
18398 + .long pa(boot_gdt)
18399
18400 .word 0 # 32-bit align idt_desc.address
18401 idt_descr:
18402 @@ -756,7 +863,7 @@ idt_descr:
18403 .word 0 # 32 bit align gdt_desc.address
18404 ENTRY(early_gdt_descr)
18405 .word GDT_ENTRIES*8-1
18406 - .long gdt_page /* Overwritten for secondary CPUs */
18407 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
18408
18409 /*
18410 * The boot_gdt must mirror the equivalent in setup.S and is
18411 @@ -765,5 +872,65 @@ ENTRY(early_gdt_descr)
18412 .align L1_CACHE_BYTES
18413 ENTRY(boot_gdt)
18414 .fill GDT_ENTRY_BOOT_CS,8,0
18415 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
18416 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
18417 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
18418 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
18419 +
18420 + .align PAGE_SIZE_asm
18421 +ENTRY(cpu_gdt_table)
18422 + .rept NR_CPUS
18423 + .quad 0x0000000000000000 /* NULL descriptor */
18424 + .quad 0x0000000000000000 /* 0x0b reserved */
18425 + .quad 0x0000000000000000 /* 0x13 reserved */
18426 + .quad 0x0000000000000000 /* 0x1b reserved */
18427 +
18428 +#ifdef CONFIG_PAX_KERNEXEC
18429 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
18430 +#else
18431 + .quad 0x0000000000000000 /* 0x20 unused */
18432 +#endif
18433 +
18434 + .quad 0x0000000000000000 /* 0x28 unused */
18435 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
18436 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
18437 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
18438 + .quad 0x0000000000000000 /* 0x4b reserved */
18439 + .quad 0x0000000000000000 /* 0x53 reserved */
18440 + .quad 0x0000000000000000 /* 0x5b reserved */
18441 +
18442 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
18443 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
18444 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
18445 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
18446 +
18447 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
18448 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
18449 +
18450 + /*
18451 + * Segments used for calling PnP BIOS have byte granularity.
18452 + * The code segments and data segments have fixed 64k limits,
18453 + * the transfer segment sizes are set at run time.
18454 + */
18455 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
18456 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
18457 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
18458 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
18459 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
18460 +
18461 + /*
18462 + * The APM segments have byte granularity and their bases
18463 + * are set at run time. All have 64k limits.
18464 + */
18465 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
18466 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
18467 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
18468 +
18469 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
18470 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
18471 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
18472 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
18473 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
18474 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
18475 +
18476 + /* Be sure this is zeroed to avoid false validations in Xen */
18477 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
18478 + .endr
18479 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
18480 index 94bf9cc..400455a 100644
18481 --- a/arch/x86/kernel/head_64.S
18482 +++ b/arch/x86/kernel/head_64.S
18483 @@ -20,6 +20,8 @@
18484 #include <asm/processor-flags.h>
18485 #include <asm/percpu.h>
18486 #include <asm/nops.h>
18487 +#include <asm/cpufeature.h>
18488 +#include <asm/alternative-asm.h>
18489
18490 #ifdef CONFIG_PARAVIRT
18491 #include <asm/asm-offsets.h>
18492 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
18493 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
18494 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
18495 L3_START_KERNEL = pud_index(__START_KERNEL_map)
18496 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
18497 +L3_VMALLOC_START = pud_index(VMALLOC_START)
18498 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
18499 +L3_VMALLOC_END = pud_index(VMALLOC_END)
18500 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
18501 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
18502
18503 .text
18504 __HEAD
18505 @@ -88,35 +96,23 @@ startup_64:
18506 */
18507 addq %rbp, init_level4_pgt + 0(%rip)
18508 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
18509 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
18510 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
18511 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
18512 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
18513
18514 addq %rbp, level3_ident_pgt + 0(%rip)
18515 +#ifndef CONFIG_XEN
18516 + addq %rbp, level3_ident_pgt + 8(%rip)
18517 +#endif
18518
18519 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
18520 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
18521 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
18522 +
18523 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
18524 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
18525
18526 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
18527 -
18528 - /* Add an Identity mapping if I am above 1G */
18529 - leaq _text(%rip), %rdi
18530 - andq $PMD_PAGE_MASK, %rdi
18531 -
18532 - movq %rdi, %rax
18533 - shrq $PUD_SHIFT, %rax
18534 - andq $(PTRS_PER_PUD - 1), %rax
18535 - jz ident_complete
18536 -
18537 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
18538 - leaq level3_ident_pgt(%rip), %rbx
18539 - movq %rdx, 0(%rbx, %rax, 8)
18540 -
18541 - movq %rdi, %rax
18542 - shrq $PMD_SHIFT, %rax
18543 - andq $(PTRS_PER_PMD - 1), %rax
18544 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
18545 - leaq level2_spare_pgt(%rip), %rbx
18546 - movq %rdx, 0(%rbx, %rax, 8)
18547 -ident_complete:
18548 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
18549
18550 /*
18551 * Fixup the kernel text+data virtual addresses. Note that
18552 @@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
18553 * after the boot processor executes this code.
18554 */
18555
18556 - /* Enable PAE mode and PGE */
18557 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
18558 + /* Enable PAE mode and PSE/PGE */
18559 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
18560 movq %rax, %cr4
18561
18562 /* Setup early boot stage 4 level pagetables. */
18563 @@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
18564 movl $MSR_EFER, %ecx
18565 rdmsr
18566 btsl $_EFER_SCE, %eax /* Enable System Call */
18567 - btl $20,%edi /* No Execute supported? */
18568 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
18569 jnc 1f
18570 btsl $_EFER_NX, %eax
18571 + leaq init_level4_pgt(%rip), %rdi
18572 +#ifndef CONFIG_EFI
18573 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
18574 +#endif
18575 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
18576 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
18577 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
18578 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
18579 1: wrmsr /* Make changes effective */
18580
18581 /* Setup cr0 */
18582 @@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
18583 * jump. In addition we need to ensure %cs is set so we make this
18584 * a far return.
18585 */
18586 + pax_set_fptr_mask
18587 movq initial_code(%rip),%rax
18588 pushq $0 # fake return address to stop unwinder
18589 pushq $__KERNEL_CS # set correct cs
18590 @@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
18591 bad_address:
18592 jmp bad_address
18593
18594 - .section ".init.text","ax"
18595 + __INIT
18596 .globl early_idt_handlers
18597 early_idt_handlers:
18598 # 104(%rsp) %rflags
18599 @@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
18600 addq $16,%rsp # drop vector number and error code
18601 decl early_recursion_flag(%rip)
18602 INTERRUPT_RETURN
18603 + .previous
18604
18605 + __INITDATA
18606 .balign 4
18607 early_recursion_flag:
18608 .long 0
18609 + .previous
18610
18611 + .section .rodata,"a",@progbits
18612 #ifdef CONFIG_EARLY_PRINTK
18613 early_idt_msg:
18614 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
18615 @@ -360,6 +369,7 @@ early_idt_ripmsg:
18616 #endif /* CONFIG_EARLY_PRINTK */
18617 .previous
18618
18619 + .section .rodata,"a",@progbits
18620 #define NEXT_PAGE(name) \
18621 .balign PAGE_SIZE; \
18622 ENTRY(name)
18623 @@ -372,7 +382,6 @@ ENTRY(name)
18624 i = i + 1 ; \
18625 .endr
18626
18627 - .data
18628 /*
18629 * This default setting generates an ident mapping at address 0x100000
18630 * and a mapping for the kernel that precisely maps virtual address
18631 @@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
18632 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
18633 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
18634 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
18635 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
18636 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
18637 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
18638 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
18639 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
18640 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
18641 .org init_level4_pgt + L4_START_KERNEL*8, 0
18642 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
18643 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
18644
18645 +#ifdef CONFIG_PAX_PER_CPU_PGD
18646 +NEXT_PAGE(cpu_pgd)
18647 + .rept NR_CPUS
18648 + .fill 512,8,0
18649 + .endr
18650 +#endif
18651 +
18652 NEXT_PAGE(level3_ident_pgt)
18653 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
18654 +#ifdef CONFIG_XEN
18655 .fill 511,8,0
18656 +#else
18657 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
18658 + .fill 510,8,0
18659 +#endif
18660 +
18661 +NEXT_PAGE(level3_vmalloc_start_pgt)
18662 + .fill 512,8,0
18663 +
18664 +NEXT_PAGE(level3_vmalloc_end_pgt)
18665 + .fill 512,8,0
18666 +
18667 +NEXT_PAGE(level3_vmemmap_pgt)
18668 + .fill L3_VMEMMAP_START,8,0
18669 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
18670
18671 NEXT_PAGE(level3_kernel_pgt)
18672 .fill L3_START_KERNEL,8,0
18673 @@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
18674 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
18675 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
18676
18677 +NEXT_PAGE(level2_vmemmap_pgt)
18678 + .fill 512,8,0
18679 +
18680 NEXT_PAGE(level2_fixmap_pgt)
18681 - .fill 506,8,0
18682 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
18683 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
18684 - .fill 5,8,0
18685 + .fill 507,8,0
18686 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
18687 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
18688 + .fill 4,8,0
18689
18690 -NEXT_PAGE(level1_fixmap_pgt)
18691 +NEXT_PAGE(level1_vsyscall_pgt)
18692 .fill 512,8,0
18693
18694 -NEXT_PAGE(level2_ident_pgt)
18695 - /* Since I easily can, map the first 1G.
18696 + /* Since I easily can, map the first 2G.
18697 * Don't set NX because code runs from these pages.
18698 */
18699 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
18700 +NEXT_PAGE(level2_ident_pgt)
18701 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
18702
18703 NEXT_PAGE(level2_kernel_pgt)
18704 /*
18705 @@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
18706 * If you want to increase this then increase MODULES_VADDR
18707 * too.)
18708 */
18709 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
18710 - KERNEL_IMAGE_SIZE/PMD_SIZE)
18711 -
18712 -NEXT_PAGE(level2_spare_pgt)
18713 - .fill 512, 8, 0
18714 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
18715
18716 #undef PMDS
18717 #undef NEXT_PAGE
18718
18719 - .data
18720 + .align PAGE_SIZE
18721 +ENTRY(cpu_gdt_table)
18722 + .rept NR_CPUS
18723 + .quad 0x0000000000000000 /* NULL descriptor */
18724 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
18725 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
18726 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
18727 + .quad 0x00cffb000000ffff /* __USER32_CS */
18728 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
18729 + .quad 0x00affb000000ffff /* __USER_CS */
18730 +
18731 +#ifdef CONFIG_PAX_KERNEXEC
18732 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
18733 +#else
18734 + .quad 0x0 /* unused */
18735 +#endif
18736 +
18737 + .quad 0,0 /* TSS */
18738 + .quad 0,0 /* LDT */
18739 + .quad 0,0,0 /* three TLS descriptors */
18740 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
18741 + /* asm/segment.h:GDT_ENTRIES must match this */
18742 +
18743 + /* zero the remaining page */
18744 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
18745 + .endr
18746 +
18747 .align 16
18748 .globl early_gdt_descr
18749 early_gdt_descr:
18750 .word GDT_ENTRIES*8-1
18751 early_gdt_descr_base:
18752 - .quad INIT_PER_CPU_VAR(gdt_page)
18753 + .quad cpu_gdt_table
18754
18755 ENTRY(phys_base)
18756 /* This must match the first entry in level2_kernel_pgt */
18757 .quad 0x0000000000000000
18758
18759 #include "../../x86/xen/xen-head.S"
18760 -
18761 - .section .bss, "aw", @nobits
18762 +
18763 + .section .rodata,"a",@progbits
18764 .align L1_CACHE_BYTES
18765 ENTRY(idt_table)
18766 - .skip IDT_ENTRIES * 16
18767 + .fill 512,8,0
18768
18769 .align L1_CACHE_BYTES
18770 ENTRY(nmi_idt_table)
18771 - .skip IDT_ENTRIES * 16
18772 + .fill 512,8,0
18773
18774 __PAGE_ALIGNED_BSS
18775 .align PAGE_SIZE
18776 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
18777 index 9c3bd4a..e1d9b35 100644
18778 --- a/arch/x86/kernel/i386_ksyms_32.c
18779 +++ b/arch/x86/kernel/i386_ksyms_32.c
18780 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
18781 EXPORT_SYMBOL(cmpxchg8b_emu);
18782 #endif
18783
18784 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
18785 +
18786 /* Networking helper routines. */
18787 EXPORT_SYMBOL(csum_partial_copy_generic);
18788 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
18789 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
18790
18791 EXPORT_SYMBOL(__get_user_1);
18792 EXPORT_SYMBOL(__get_user_2);
18793 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
18794
18795 EXPORT_SYMBOL(csum_partial);
18796 EXPORT_SYMBOL(empty_zero_page);
18797 +
18798 +#ifdef CONFIG_PAX_KERNEXEC
18799 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
18800 +#endif
18801 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
18802 index 675a050..95febfd 100644
18803 --- a/arch/x86/kernel/i387.c
18804 +++ b/arch/x86/kernel/i387.c
18805 @@ -55,7 +55,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
18806 static inline bool interrupted_user_mode(void)
18807 {
18808 struct pt_regs *regs = get_irq_regs();
18809 - return regs && user_mode_vm(regs);
18810 + return regs && user_mode(regs);
18811 }
18812
18813 /*
18814 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
18815 index 9a5c460..dc4374d 100644
18816 --- a/arch/x86/kernel/i8259.c
18817 +++ b/arch/x86/kernel/i8259.c
18818 @@ -209,7 +209,7 @@ spurious_8259A_irq:
18819 "spurious 8259A interrupt: IRQ%d.\n", irq);
18820 spurious_irq_mask |= irqmask;
18821 }
18822 - atomic_inc(&irq_err_count);
18823 + atomic_inc_unchecked(&irq_err_count);
18824 /*
18825 * Theoretically we do not have to handle this IRQ,
18826 * but in Linux this does not cause problems and is
18827 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
18828 index 8c96897..be66bfa 100644
18829 --- a/arch/x86/kernel/ioport.c
18830 +++ b/arch/x86/kernel/ioport.c
18831 @@ -6,6 +6,7 @@
18832 #include <linux/sched.h>
18833 #include <linux/kernel.h>
18834 #include <linux/capability.h>
18835 +#include <linux/security.h>
18836 #include <linux/errno.h>
18837 #include <linux/types.h>
18838 #include <linux/ioport.h>
18839 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
18840
18841 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
18842 return -EINVAL;
18843 +#ifdef CONFIG_GRKERNSEC_IO
18844 + if (turn_on && grsec_disable_privio) {
18845 + gr_handle_ioperm();
18846 + return -EPERM;
18847 + }
18848 +#endif
18849 if (turn_on && !capable(CAP_SYS_RAWIO))
18850 return -EPERM;
18851
18852 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
18853 * because the ->io_bitmap_max value must match the bitmap
18854 * contents:
18855 */
18856 - tss = &per_cpu(init_tss, get_cpu());
18857 + tss = init_tss + get_cpu();
18858
18859 if (turn_on)
18860 bitmap_clear(t->io_bitmap_ptr, from, num);
18861 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
18862 return -EINVAL;
18863 /* Trying to gain more privileges? */
18864 if (level > old) {
18865 +#ifdef CONFIG_GRKERNSEC_IO
18866 + if (grsec_disable_privio) {
18867 + gr_handle_iopl();
18868 + return -EPERM;
18869 + }
18870 +#endif
18871 if (!capable(CAP_SYS_RAWIO))
18872 return -EPERM;
18873 }
18874 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
18875 index e4595f1..ee3bfb8 100644
18876 --- a/arch/x86/kernel/irq.c
18877 +++ b/arch/x86/kernel/irq.c
18878 @@ -18,7 +18,7 @@
18879 #include <asm/mce.h>
18880 #include <asm/hw_irq.h>
18881
18882 -atomic_t irq_err_count;
18883 +atomic_unchecked_t irq_err_count;
18884
18885 /* Function pointer for generic interrupt vector handling */
18886 void (*x86_platform_ipi_callback)(void) = NULL;
18887 @@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
18888 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
18889 seq_printf(p, " Machine check polls\n");
18890 #endif
18891 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
18892 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
18893 #if defined(CONFIG_X86_IO_APIC)
18894 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
18895 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
18896 #endif
18897 return 0;
18898 }
18899 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
18900
18901 u64 arch_irq_stat(void)
18902 {
18903 - u64 sum = atomic_read(&irq_err_count);
18904 + u64 sum = atomic_read_unchecked(&irq_err_count);
18905
18906 #ifdef CONFIG_X86_IO_APIC
18907 - sum += atomic_read(&irq_mis_count);
18908 + sum += atomic_read_unchecked(&irq_mis_count);
18909 #endif
18910 return sum;
18911 }
18912 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
18913 index 344faf8..355f60d 100644
18914 --- a/arch/x86/kernel/irq_32.c
18915 +++ b/arch/x86/kernel/irq_32.c
18916 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
18917 __asm__ __volatile__("andl %%esp,%0" :
18918 "=r" (sp) : "0" (THREAD_SIZE - 1));
18919
18920 - return sp < (sizeof(struct thread_info) + STACK_WARN);
18921 + return sp < STACK_WARN;
18922 }
18923
18924 static void print_stack_overflow(void)
18925 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
18926 * per-CPU IRQ handling contexts (thread information and stack)
18927 */
18928 union irq_ctx {
18929 - struct thread_info tinfo;
18930 - u32 stack[THREAD_SIZE/sizeof(u32)];
18931 + unsigned long previous_esp;
18932 + u32 stack[THREAD_SIZE/sizeof(u32)];
18933 } __attribute__((aligned(THREAD_SIZE)));
18934
18935 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
18936 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
18937 static inline int
18938 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18939 {
18940 - union irq_ctx *curctx, *irqctx;
18941 + union irq_ctx *irqctx;
18942 u32 *isp, arg1, arg2;
18943
18944 - curctx = (union irq_ctx *) current_thread_info();
18945 irqctx = __this_cpu_read(hardirq_ctx);
18946
18947 /*
18948 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18949 * handler) we can't do that and just have to keep using the
18950 * current stack (which is the irq stack already after all)
18951 */
18952 - if (unlikely(curctx == irqctx))
18953 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
18954 return 0;
18955
18956 /* build the stack frame on the IRQ stack */
18957 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
18958 - irqctx->tinfo.task = curctx->tinfo.task;
18959 - irqctx->tinfo.previous_esp = current_stack_pointer;
18960 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
18961 + irqctx->previous_esp = current_stack_pointer;
18962
18963 - /* Copy the preempt_count so that the [soft]irq checks work. */
18964 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
18965 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18966 + __set_fs(MAKE_MM_SEG(0));
18967 +#endif
18968
18969 if (unlikely(overflow))
18970 call_on_stack(print_stack_overflow, isp);
18971 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18972 : "0" (irq), "1" (desc), "2" (isp),
18973 "D" (desc->handle_irq)
18974 : "memory", "cc", "ecx");
18975 +
18976 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18977 + __set_fs(current_thread_info()->addr_limit);
18978 +#endif
18979 +
18980 return 1;
18981 }
18982
18983 @@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18984 */
18985 void __cpuinit irq_ctx_init(int cpu)
18986 {
18987 - union irq_ctx *irqctx;
18988 -
18989 if (per_cpu(hardirq_ctx, cpu))
18990 return;
18991
18992 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
18993 - THREADINFO_GFP,
18994 - THREAD_SIZE_ORDER));
18995 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
18996 - irqctx->tinfo.cpu = cpu;
18997 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
18998 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
18999 -
19000 - per_cpu(hardirq_ctx, cpu) = irqctx;
19001 -
19002 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
19003 - THREADINFO_GFP,
19004 - THREAD_SIZE_ORDER));
19005 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
19006 - irqctx->tinfo.cpu = cpu;
19007 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
19008 -
19009 - per_cpu(softirq_ctx, cpu) = irqctx;
19010 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
19011 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
19012 +
19013 + printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
19014 + cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
19015
19016 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
19017 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
19018 @@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
19019 asmlinkage void do_softirq(void)
19020 {
19021 unsigned long flags;
19022 - struct thread_info *curctx;
19023 union irq_ctx *irqctx;
19024 u32 *isp;
19025
19026 @@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
19027 local_irq_save(flags);
19028
19029 if (local_softirq_pending()) {
19030 - curctx = current_thread_info();
19031 irqctx = __this_cpu_read(softirq_ctx);
19032 - irqctx->tinfo.task = curctx->task;
19033 - irqctx->tinfo.previous_esp = current_stack_pointer;
19034 + irqctx->previous_esp = current_stack_pointer;
19035
19036 /* build the stack frame on the softirq stack */
19037 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
19038 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
19039 +
19040 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19041 + __set_fs(MAKE_MM_SEG(0));
19042 +#endif
19043
19044 call_on_stack(__do_softirq, isp);
19045 +
19046 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19047 + __set_fs(current_thread_info()->addr_limit);
19048 +#endif
19049 +
19050 /*
19051 * Shouldn't happen, we returned above if in_interrupt():
19052 */
19053 @@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
19054 if (unlikely(!desc))
19055 return false;
19056
19057 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
19058 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
19059 if (unlikely(overflow))
19060 print_stack_overflow();
19061 desc->handle_irq(irq, desc);
19062 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
19063 index d04d3ec..ea4b374 100644
19064 --- a/arch/x86/kernel/irq_64.c
19065 +++ b/arch/x86/kernel/irq_64.c
19066 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
19067 u64 estack_top, estack_bottom;
19068 u64 curbase = (u64)task_stack_page(current);
19069
19070 - if (user_mode_vm(regs))
19071 + if (user_mode(regs))
19072 return;
19073
19074 if (regs->sp >= curbase + sizeof(struct thread_info) +
19075 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
19076 index dc1404b..bbc43e7 100644
19077 --- a/arch/x86/kernel/kdebugfs.c
19078 +++ b/arch/x86/kernel/kdebugfs.c
19079 @@ -27,7 +27,7 @@ struct setup_data_node {
19080 u32 len;
19081 };
19082
19083 -static ssize_t setup_data_read(struct file *file, char __user *user_buf,
19084 +static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
19085 size_t count, loff_t *ppos)
19086 {
19087 struct setup_data_node *node = file->private_data;
19088 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
19089 index 836f832..a8bda67 100644
19090 --- a/arch/x86/kernel/kgdb.c
19091 +++ b/arch/x86/kernel/kgdb.c
19092 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
19093 #ifdef CONFIG_X86_32
19094 switch (regno) {
19095 case GDB_SS:
19096 - if (!user_mode_vm(regs))
19097 + if (!user_mode(regs))
19098 *(unsigned long *)mem = __KERNEL_DS;
19099 break;
19100 case GDB_SP:
19101 - if (!user_mode_vm(regs))
19102 + if (!user_mode(regs))
19103 *(unsigned long *)mem = kernel_stack_pointer(regs);
19104 break;
19105 case GDB_GS:
19106 @@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
19107 bp->attr.bp_addr = breakinfo[breakno].addr;
19108 bp->attr.bp_len = breakinfo[breakno].len;
19109 bp->attr.bp_type = breakinfo[breakno].type;
19110 - info->address = breakinfo[breakno].addr;
19111 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
19112 + info->address = ktla_ktva(breakinfo[breakno].addr);
19113 + else
19114 + info->address = breakinfo[breakno].addr;
19115 info->len = breakinfo[breakno].len;
19116 info->type = breakinfo[breakno].type;
19117 val = arch_install_hw_breakpoint(bp);
19118 @@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
19119 case 'k':
19120 /* clear the trace bit */
19121 linux_regs->flags &= ~X86_EFLAGS_TF;
19122 - atomic_set(&kgdb_cpu_doing_single_step, -1);
19123 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
19124
19125 /* set the trace bit if we're stepping */
19126 if (remcomInBuffer[0] == 's') {
19127 linux_regs->flags |= X86_EFLAGS_TF;
19128 - atomic_set(&kgdb_cpu_doing_single_step,
19129 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
19130 raw_smp_processor_id());
19131 }
19132
19133 @@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
19134
19135 switch (cmd) {
19136 case DIE_DEBUG:
19137 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
19138 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
19139 if (user_mode(regs))
19140 return single_step_cont(regs, args);
19141 break;
19142 @@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
19143 #endif /* CONFIG_DEBUG_RODATA */
19144
19145 bpt->type = BP_BREAKPOINT;
19146 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
19147 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
19148 BREAK_INSTR_SIZE);
19149 if (err)
19150 return err;
19151 - err = probe_kernel_write((char *)bpt->bpt_addr,
19152 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
19153 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
19154 #ifdef CONFIG_DEBUG_RODATA
19155 if (!err)
19156 @@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
19157 return -EBUSY;
19158 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
19159 BREAK_INSTR_SIZE);
19160 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
19161 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
19162 if (err)
19163 return err;
19164 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
19165 @@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
19166 if (mutex_is_locked(&text_mutex))
19167 goto knl_write;
19168 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
19169 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
19170 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
19171 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
19172 goto knl_write;
19173 return err;
19174 knl_write:
19175 #endif /* CONFIG_DEBUG_RODATA */
19176 - return probe_kernel_write((char *)bpt->bpt_addr,
19177 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
19178 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
19179 }
19180
19181 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
19182 index c5e410e..ed5a7f0 100644
19183 --- a/arch/x86/kernel/kprobes-opt.c
19184 +++ b/arch/x86/kernel/kprobes-opt.c
19185 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
19186 * Verify if the address gap is in 2GB range, because this uses
19187 * a relative jump.
19188 */
19189 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
19190 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
19191 if (abs(rel) > 0x7fffffff)
19192 return -ERANGE;
19193
19194 @@ -353,16 +353,16 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
19195 op->optinsn.size = ret;
19196
19197 /* Copy arch-dep-instance from template */
19198 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
19199 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
19200
19201 /* Set probe information */
19202 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
19203
19204 /* Set probe function call */
19205 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
19206 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
19207
19208 /* Set returning jmp instruction at the tail of out-of-line buffer */
19209 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
19210 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
19211 (u8 *)op->kp.addr + op->optinsn.size);
19212
19213 flush_icache_range((unsigned long) buf,
19214 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
19215 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
19216
19217 /* Backup instructions which will be replaced by jump address */
19218 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
19219 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
19220 RELATIVE_ADDR_SIZE);
19221
19222 insn_buf[0] = RELATIVEJUMP_OPCODE;
19223 @@ -483,7 +483,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
19224 /* This kprobe is really able to run optimized path. */
19225 op = container_of(p, struct optimized_kprobe, kp);
19226 /* Detour through copied instructions */
19227 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
19228 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
19229 if (!reenter)
19230 reset_current_kprobe();
19231 preempt_enable_no_resched();
19232 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
19233 index 57916c0..9e0b9d0 100644
19234 --- a/arch/x86/kernel/kprobes.c
19235 +++ b/arch/x86/kernel/kprobes.c
19236 @@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
19237 s32 raddr;
19238 } __attribute__((packed)) *insn;
19239
19240 - insn = (struct __arch_relative_insn *)from;
19241 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
19242 +
19243 + pax_open_kernel();
19244 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
19245 insn->op = op;
19246 + pax_close_kernel();
19247 }
19248
19249 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
19250 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
19251 kprobe_opcode_t opcode;
19252 kprobe_opcode_t *orig_opcodes = opcodes;
19253
19254 - if (search_exception_tables((unsigned long)opcodes))
19255 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
19256 return 0; /* Page fault may occur on this address. */
19257
19258 retry:
19259 @@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
19260 * for the first byte, we can recover the original instruction
19261 * from it and kp->opcode.
19262 */
19263 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
19264 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
19265 buf[0] = kp->opcode;
19266 - return (unsigned long)buf;
19267 + return ktva_ktla((unsigned long)buf);
19268 }
19269
19270 /*
19271 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
19272 /* Another subsystem puts a breakpoint, failed to recover */
19273 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
19274 return 0;
19275 + pax_open_kernel();
19276 memcpy(dest, insn.kaddr, insn.length);
19277 + pax_close_kernel();
19278
19279 #ifdef CONFIG_X86_64
19280 if (insn_rip_relative(&insn)) {
19281 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
19282 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
19283 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
19284 disp = (u8 *) dest + insn_offset_displacement(&insn);
19285 + pax_open_kernel();
19286 *(s32 *) disp = (s32) newdisp;
19287 + pax_close_kernel();
19288 }
19289 #endif
19290 return insn.length;
19291 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
19292 * nor set current_kprobe, because it doesn't use single
19293 * stepping.
19294 */
19295 - regs->ip = (unsigned long)p->ainsn.insn;
19296 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
19297 preempt_enable_no_resched();
19298 return;
19299 }
19300 @@ -502,9 +509,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
19301 regs->flags &= ~X86_EFLAGS_IF;
19302 /* single step inline if the instruction is an int3 */
19303 if (p->opcode == BREAKPOINT_INSTRUCTION)
19304 - regs->ip = (unsigned long)p->addr;
19305 + regs->ip = ktla_ktva((unsigned long)p->addr);
19306 else
19307 - regs->ip = (unsigned long)p->ainsn.insn;
19308 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
19309 }
19310
19311 /*
19312 @@ -600,7 +607,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
19313 setup_singlestep(p, regs, kcb, 0);
19314 return 1;
19315 }
19316 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
19317 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
19318 /*
19319 * The breakpoint instruction was removed right
19320 * after we hit it. Another cpu has removed
19321 @@ -651,6 +658,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
19322 " movq %rax, 152(%rsp)\n"
19323 RESTORE_REGS_STRING
19324 " popfq\n"
19325 +#ifdef KERNEXEC_PLUGIN
19326 + " btsq $63,(%rsp)\n"
19327 +#endif
19328 #else
19329 " pushf\n"
19330 SAVE_REGS_STRING
19331 @@ -788,7 +798,7 @@ static void __kprobes
19332 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
19333 {
19334 unsigned long *tos = stack_addr(regs);
19335 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
19336 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
19337 unsigned long orig_ip = (unsigned long)p->addr;
19338 kprobe_opcode_t *insn = p->ainsn.insn;
19339
19340 @@ -970,7 +980,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
19341 struct die_args *args = data;
19342 int ret = NOTIFY_DONE;
19343
19344 - if (args->regs && user_mode_vm(args->regs))
19345 + if (args->regs && user_mode(args->regs))
19346 return ret;
19347
19348 switch (val) {
19349 diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
19350 index 4180a87..4678e4f 100644
19351 --- a/arch/x86/kernel/kvm.c
19352 +++ b/arch/x86/kernel/kvm.c
19353 @@ -267,7 +267,7 @@ static void __init paravirt_ops_setup(void)
19354 pv_info.paravirt_enabled = 1;
19355
19356 if (kvm_para_has_feature(KVM_FEATURE_NOP_IO_DELAY))
19357 - pv_cpu_ops.io_delay = kvm_io_delay;
19358 + *(void **)&pv_cpu_ops.io_delay = kvm_io_delay;
19359
19360 #ifdef CONFIG_X86_IO_APIC
19361 no_timer_check = 1;
19362 @@ -461,18 +461,18 @@ void __init kvm_guest_init(void)
19363 for (i = 0; i < KVM_TASK_SLEEP_HASHSIZE; i++)
19364 spin_lock_init(&async_pf_sleepers[i].lock);
19365 if (kvm_para_has_feature(KVM_FEATURE_ASYNC_PF))
19366 - x86_init.irqs.trap_init = kvm_apf_trap_init;
19367 + *(void **)&x86_init.irqs.trap_init = kvm_apf_trap_init;
19368
19369 if (kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)) {
19370 has_steal_clock = 1;
19371 - pv_time_ops.steal_clock = kvm_steal_clock;
19372 + *(void **)&pv_time_ops.steal_clock = kvm_steal_clock;
19373 }
19374
19375 if (kvm_para_has_feature(KVM_FEATURE_PV_EOI))
19376 apic_set_eoi_write(kvm_guest_apic_eoi_write);
19377
19378 #ifdef CONFIG_SMP
19379 - smp_ops.smp_prepare_boot_cpu = kvm_smp_prepare_boot_cpu;
19380 + *(void **)&smp_ops.smp_prepare_boot_cpu = kvm_smp_prepare_boot_cpu;
19381 register_cpu_notifier(&kvm_cpu_notifier);
19382 #else
19383 kvm_guest_cpu_init();
19384 diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c
19385 index f1b42b3..27ac4e7 100644
19386 --- a/arch/x86/kernel/kvmclock.c
19387 +++ b/arch/x86/kernel/kvmclock.c
19388 @@ -211,19 +211,19 @@ void __init kvmclock_init(void)
19389
19390 if (kvm_register_clock("boot clock"))
19391 return;
19392 - pv_time_ops.sched_clock = kvm_clock_read;
19393 - x86_platform.calibrate_tsc = kvm_get_tsc_khz;
19394 - x86_platform.get_wallclock = kvm_get_wallclock;
19395 - x86_platform.set_wallclock = kvm_set_wallclock;
19396 + *(void **)&pv_time_ops.sched_clock = kvm_clock_read;
19397 + *(void **)&x86_platform.calibrate_tsc = kvm_get_tsc_khz;
19398 + *(void **)&x86_platform.get_wallclock = kvm_get_wallclock;
19399 + *(void **)&x86_platform.set_wallclock = kvm_set_wallclock;
19400 #ifdef CONFIG_X86_LOCAL_APIC
19401 - x86_cpuinit.early_percpu_clock_init =
19402 + *(void **)&x86_cpuinit.early_percpu_clock_init =
19403 kvm_setup_secondary_clock;
19404 #endif
19405 - x86_platform.save_sched_clock_state = kvm_save_sched_clock_state;
19406 - x86_platform.restore_sched_clock_state = kvm_restore_sched_clock_state;
19407 - machine_ops.shutdown = kvm_shutdown;
19408 + *(void **)&x86_platform.save_sched_clock_state = kvm_save_sched_clock_state;
19409 + *(void **)&x86_platform.restore_sched_clock_state = kvm_restore_sched_clock_state;
19410 + *(void **)&machine_ops.shutdown = kvm_shutdown;
19411 #ifdef CONFIG_KEXEC
19412 - machine_ops.crash_shutdown = kvm_crash_shutdown;
19413 + *(void **)&machine_ops.crash_shutdown = kvm_crash_shutdown;
19414 #endif
19415 kvm_get_preset_lpj();
19416 clocksource_register_hz(&kvm_clock, NSEC_PER_SEC);
19417 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
19418 index ebc9873..1b9724b 100644
19419 --- a/arch/x86/kernel/ldt.c
19420 +++ b/arch/x86/kernel/ldt.c
19421 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
19422 if (reload) {
19423 #ifdef CONFIG_SMP
19424 preempt_disable();
19425 - load_LDT(pc);
19426 + load_LDT_nolock(pc);
19427 if (!cpumask_equal(mm_cpumask(current->mm),
19428 cpumask_of(smp_processor_id())))
19429 smp_call_function(flush_ldt, current->mm, 1);
19430 preempt_enable();
19431 #else
19432 - load_LDT(pc);
19433 + load_LDT_nolock(pc);
19434 #endif
19435 }
19436 if (oldsize) {
19437 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
19438 return err;
19439
19440 for (i = 0; i < old->size; i++)
19441 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
19442 + write_ldt_entry(new->ldt, i, old->ldt + i);
19443 return 0;
19444 }
19445
19446 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
19447 retval = copy_ldt(&mm->context, &old_mm->context);
19448 mutex_unlock(&old_mm->context.lock);
19449 }
19450 +
19451 + if (tsk == current) {
19452 + mm->context.vdso = 0;
19453 +
19454 +#ifdef CONFIG_X86_32
19455 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
19456 + mm->context.user_cs_base = 0UL;
19457 + mm->context.user_cs_limit = ~0UL;
19458 +
19459 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
19460 + cpus_clear(mm->context.cpu_user_cs_mask);
19461 +#endif
19462 +
19463 +#endif
19464 +#endif
19465 +
19466 + }
19467 +
19468 return retval;
19469 }
19470
19471 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
19472 }
19473 }
19474
19475 +#ifdef CONFIG_PAX_SEGMEXEC
19476 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
19477 + error = -EINVAL;
19478 + goto out_unlock;
19479 + }
19480 +#endif
19481 +
19482 fill_ldt(&ldt, &ldt_info);
19483 if (oldmode)
19484 ldt.avl = 0;
19485 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
19486 index 5b19e4d..6476a76 100644
19487 --- a/arch/x86/kernel/machine_kexec_32.c
19488 +++ b/arch/x86/kernel/machine_kexec_32.c
19489 @@ -26,7 +26,7 @@
19490 #include <asm/cacheflush.h>
19491 #include <asm/debugreg.h>
19492
19493 -static void set_idt(void *newidt, __u16 limit)
19494 +static void set_idt(struct desc_struct *newidt, __u16 limit)
19495 {
19496 struct desc_ptr curidt;
19497
19498 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
19499 }
19500
19501
19502 -static void set_gdt(void *newgdt, __u16 limit)
19503 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
19504 {
19505 struct desc_ptr curgdt;
19506
19507 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
19508 }
19509
19510 control_page = page_address(image->control_code_page);
19511 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
19512 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
19513
19514 relocate_kernel_ptr = control_page;
19515 page_list[PA_CONTROL_PAGE] = __pa(control_page);
19516 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
19517 index 3544aed..01ddc1c 100644
19518 --- a/arch/x86/kernel/microcode_intel.c
19519 +++ b/arch/x86/kernel/microcode_intel.c
19520 @@ -431,13 +431,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
19521
19522 static int get_ucode_user(void *to, const void *from, size_t n)
19523 {
19524 - return copy_from_user(to, from, n);
19525 + return copy_from_user(to, (const void __force_user *)from, n);
19526 }
19527
19528 static enum ucode_state
19529 request_microcode_user(int cpu, const void __user *buf, size_t size)
19530 {
19531 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
19532 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
19533 }
19534
19535 static void microcode_fini_cpu(int cpu)
19536 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
19537 index 216a4d7..228255a 100644
19538 --- a/arch/x86/kernel/module.c
19539 +++ b/arch/x86/kernel/module.c
19540 @@ -43,15 +43,60 @@ do { \
19541 } while (0)
19542 #endif
19543
19544 -void *module_alloc(unsigned long size)
19545 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
19546 {
19547 - if (PAGE_ALIGN(size) > MODULES_LEN)
19548 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
19549 return NULL;
19550 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
19551 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
19552 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
19553 -1, __builtin_return_address(0));
19554 }
19555
19556 +void *module_alloc(unsigned long size)
19557 +{
19558 +
19559 +#ifdef CONFIG_PAX_KERNEXEC
19560 + return __module_alloc(size, PAGE_KERNEL);
19561 +#else
19562 + return __module_alloc(size, PAGE_KERNEL_EXEC);
19563 +#endif
19564 +
19565 +}
19566 +
19567 +#ifdef CONFIG_PAX_KERNEXEC
19568 +#ifdef CONFIG_X86_32
19569 +void *module_alloc_exec(unsigned long size)
19570 +{
19571 + struct vm_struct *area;
19572 +
19573 + if (size == 0)
19574 + return NULL;
19575 +
19576 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
19577 + return area ? area->addr : NULL;
19578 +}
19579 +EXPORT_SYMBOL(module_alloc_exec);
19580 +
19581 +void module_free_exec(struct module *mod, void *module_region)
19582 +{
19583 + vunmap(module_region);
19584 +}
19585 +EXPORT_SYMBOL(module_free_exec);
19586 +#else
19587 +void module_free_exec(struct module *mod, void *module_region)
19588 +{
19589 + module_free(mod, module_region);
19590 +}
19591 +EXPORT_SYMBOL(module_free_exec);
19592 +
19593 +void *module_alloc_exec(unsigned long size)
19594 +{
19595 + return __module_alloc(size, PAGE_KERNEL_RX);
19596 +}
19597 +EXPORT_SYMBOL(module_alloc_exec);
19598 +#endif
19599 +#endif
19600 +
19601 #ifdef CONFIG_X86_32
19602 int apply_relocate(Elf32_Shdr *sechdrs,
19603 const char *strtab,
19604 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
19605 unsigned int i;
19606 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
19607 Elf32_Sym *sym;
19608 - uint32_t *location;
19609 + uint32_t *plocation, location;
19610
19611 DEBUGP("Applying relocate section %u to %u\n",
19612 relsec, sechdrs[relsec].sh_info);
19613 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
19614 /* This is where to make the change */
19615 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
19616 - + rel[i].r_offset;
19617 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
19618 + location = (uint32_t)plocation;
19619 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
19620 + plocation = ktla_ktva((void *)plocation);
19621 /* This is the symbol it is referring to. Note that all
19622 undefined symbols have been resolved. */
19623 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
19624 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
19625 switch (ELF32_R_TYPE(rel[i].r_info)) {
19626 case R_386_32:
19627 /* We add the value into the location given */
19628 - *location += sym->st_value;
19629 + pax_open_kernel();
19630 + *plocation += sym->st_value;
19631 + pax_close_kernel();
19632 break;
19633 case R_386_PC32:
19634 /* Add the value, subtract its position */
19635 - *location += sym->st_value - (uint32_t)location;
19636 + pax_open_kernel();
19637 + *plocation += sym->st_value - location;
19638 + pax_close_kernel();
19639 break;
19640 default:
19641 pr_err("%s: Unknown relocation: %u\n",
19642 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
19643 case R_X86_64_NONE:
19644 break;
19645 case R_X86_64_64:
19646 + pax_open_kernel();
19647 *(u64 *)loc = val;
19648 + pax_close_kernel();
19649 break;
19650 case R_X86_64_32:
19651 + pax_open_kernel();
19652 *(u32 *)loc = val;
19653 + pax_close_kernel();
19654 if (val != *(u32 *)loc)
19655 goto overflow;
19656 break;
19657 case R_X86_64_32S:
19658 + pax_open_kernel();
19659 *(s32 *)loc = val;
19660 + pax_close_kernel();
19661 if ((s64)val != *(s32 *)loc)
19662 goto overflow;
19663 break;
19664 case R_X86_64_PC32:
19665 val -= (u64)loc;
19666 + pax_open_kernel();
19667 *(u32 *)loc = val;
19668 + pax_close_kernel();
19669 +
19670 #if 0
19671 if ((s64)val != *(s32 *)loc)
19672 goto overflow;
19673 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
19674 index f84f5c5..e27e54b 100644
19675 --- a/arch/x86/kernel/nmi.c
19676 +++ b/arch/x86/kernel/nmi.c
19677 @@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
19678 dotraplinkage notrace __kprobes void
19679 do_nmi(struct pt_regs *regs, long error_code)
19680 {
19681 +
19682 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19683 + if (!user_mode(regs)) {
19684 + unsigned long cs = regs->cs & 0xFFFF;
19685 + unsigned long ip = ktva_ktla(regs->ip);
19686 +
19687 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
19688 + regs->ip = ip;
19689 + }
19690 +#endif
19691 +
19692 nmi_nesting_preprocess(regs);
19693
19694 nmi_enter();
19695 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
19696 index 676b8c7..870ba04 100644
19697 --- a/arch/x86/kernel/paravirt-spinlocks.c
19698 +++ b/arch/x86/kernel/paravirt-spinlocks.c
19699 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
19700 arch_spin_lock(lock);
19701 }
19702
19703 -struct pv_lock_ops pv_lock_ops = {
19704 +struct pv_lock_ops pv_lock_ops __read_only = {
19705 #ifdef CONFIG_SMP
19706 .spin_is_locked = __ticket_spin_is_locked,
19707 .spin_is_contended = __ticket_spin_is_contended,
19708 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
19709 index 17fff18..0f5f957 100644
19710 --- a/arch/x86/kernel/paravirt.c
19711 +++ b/arch/x86/kernel/paravirt.c
19712 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
19713 {
19714 return x;
19715 }
19716 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
19717 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
19718 +#endif
19719
19720 void __init default_banner(void)
19721 {
19722 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
19723 if (opfunc == NULL)
19724 /* If there's no function, patch it with a ud2a (BUG) */
19725 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
19726 - else if (opfunc == _paravirt_nop)
19727 + else if (opfunc == (void *)_paravirt_nop)
19728 /* If the operation is a nop, then nop the callsite */
19729 ret = paravirt_patch_nop();
19730
19731 /* identity functions just return their single argument */
19732 - else if (opfunc == _paravirt_ident_32)
19733 + else if (opfunc == (void *)_paravirt_ident_32)
19734 ret = paravirt_patch_ident_32(insnbuf, len);
19735 - else if (opfunc == _paravirt_ident_64)
19736 + else if (opfunc == (void *)_paravirt_ident_64)
19737 ret = paravirt_patch_ident_64(insnbuf, len);
19738 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
19739 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
19740 + ret = paravirt_patch_ident_64(insnbuf, len);
19741 +#endif
19742
19743 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
19744 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
19745 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
19746 if (insn_len > len || start == NULL)
19747 insn_len = len;
19748 else
19749 - memcpy(insnbuf, start, insn_len);
19750 + memcpy(insnbuf, ktla_ktva(start), insn_len);
19751
19752 return insn_len;
19753 }
19754 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
19755 preempt_enable();
19756 }
19757
19758 -struct pv_info pv_info = {
19759 +struct pv_info pv_info __read_only = {
19760 .name = "bare hardware",
19761 .paravirt_enabled = 0,
19762 .kernel_rpl = 0,
19763 @@ -324,7 +331,7 @@ struct pv_time_ops pv_time_ops = {
19764 .steal_clock = native_steal_clock,
19765 };
19766
19767 -struct pv_irq_ops pv_irq_ops = {
19768 +struct pv_irq_ops pv_irq_ops __read_only = {
19769 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
19770 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
19771 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
19772 @@ -401,15 +408,20 @@ struct pv_apic_ops pv_apic_ops = {
19773 #endif
19774 };
19775
19776 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
19777 +#ifdef CONFIG_X86_32
19778 +#ifdef CONFIG_X86_PAE
19779 +/* 64-bit pagetable entries */
19780 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
19781 +#else
19782 /* 32-bit pagetable entries */
19783 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
19784 +#endif
19785 #else
19786 /* 64-bit pagetable entries */
19787 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
19788 #endif
19789
19790 -struct pv_mmu_ops pv_mmu_ops = {
19791 +struct pv_mmu_ops pv_mmu_ops __read_only = {
19792
19793 .read_cr2 = native_read_cr2,
19794 .write_cr2 = native_write_cr2,
19795 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
19796 .make_pud = PTE_IDENT,
19797
19798 .set_pgd = native_set_pgd,
19799 + .set_pgd_batched = native_set_pgd_batched,
19800 #endif
19801 #endif /* PAGETABLE_LEVELS >= 3 */
19802
19803 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
19804 },
19805
19806 .set_fixmap = native_set_fixmap,
19807 +
19808 +#ifdef CONFIG_PAX_KERNEXEC
19809 + .pax_open_kernel = native_pax_open_kernel,
19810 + .pax_close_kernel = native_pax_close_kernel,
19811 +#endif
19812 +
19813 };
19814
19815 EXPORT_SYMBOL_GPL(pv_time_ops);
19816 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
19817 index 299d493..79c13dd 100644
19818 --- a/arch/x86/kernel/pci-calgary_64.c
19819 +++ b/arch/x86/kernel/pci-calgary_64.c
19820 @@ -1461,7 +1461,7 @@ int __init detect_calgary(void)
19821 printk(KERN_INFO "PCI-DMA: Calgary TCE table spec is %d\n",
19822 specified_table_size);
19823
19824 - x86_init.iommu.iommu_init = calgary_iommu_init;
19825 + *(void **)&x86_init.iommu.iommu_init = calgary_iommu_init;
19826 }
19827 return calgary_found;
19828
19829 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
19830 index 35ccf75..7a15747 100644
19831 --- a/arch/x86/kernel/pci-iommu_table.c
19832 +++ b/arch/x86/kernel/pci-iommu_table.c
19833 @@ -2,7 +2,7 @@
19834 #include <asm/iommu_table.h>
19835 #include <linux/string.h>
19836 #include <linux/kallsyms.h>
19837 -
19838 +#include <linux/sched.h>
19839
19840 #define DEBUG 1
19841
19842 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
19843 index b644e1c..4a6d379 100644
19844 --- a/arch/x86/kernel/process.c
19845 +++ b/arch/x86/kernel/process.c
19846 @@ -36,7 +36,8 @@
19847 * section. Since TSS's are completely CPU-local, we want them
19848 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
19849 */
19850 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
19851 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
19852 +EXPORT_SYMBOL(init_tss);
19853
19854 #ifdef CONFIG_X86_64
19855 static DEFINE_PER_CPU(unsigned char, is_idle);
19856 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
19857 task_xstate_cachep =
19858 kmem_cache_create("task_xstate", xstate_size,
19859 __alignof__(union thread_xstate),
19860 - SLAB_PANIC | SLAB_NOTRACK, NULL);
19861 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
19862 }
19863
19864 /*
19865 @@ -105,7 +106,7 @@ void exit_thread(void)
19866 unsigned long *bp = t->io_bitmap_ptr;
19867
19868 if (bp) {
19869 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
19870 + struct tss_struct *tss = init_tss + get_cpu();
19871
19872 t->io_bitmap_ptr = NULL;
19873 clear_thread_flag(TIF_IO_BITMAP);
19874 @@ -136,7 +137,7 @@ void show_regs_common(void)
19875 board = dmi_get_system_info(DMI_BOARD_NAME);
19876
19877 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
19878 - current->pid, current->comm, print_tainted(),
19879 + task_pid_nr(current), current->comm, print_tainted(),
19880 init_utsname()->release,
19881 (int)strcspn(init_utsname()->version, " "),
19882 init_utsname()->version,
19883 @@ -149,6 +150,9 @@ void flush_thread(void)
19884 {
19885 struct task_struct *tsk = current;
19886
19887 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19888 + loadsegment(gs, 0);
19889 +#endif
19890 flush_ptrace_hw_breakpoint(tsk);
19891 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
19892 drop_init_fpu(tsk);
19893 @@ -336,7 +340,7 @@ static void __exit_idle(void)
19894 void exit_idle(void)
19895 {
19896 /* idle loop has pid 0 */
19897 - if (current->pid)
19898 + if (task_pid_nr(current))
19899 return;
19900 __exit_idle();
19901 }
19902 @@ -445,7 +449,7 @@ bool set_pm_idle_to_default(void)
19903
19904 return ret;
19905 }
19906 -void stop_this_cpu(void *dummy)
19907 +__noreturn void stop_this_cpu(void *dummy)
19908 {
19909 local_irq_disable();
19910 /*
19911 @@ -673,16 +677,37 @@ static int __init idle_setup(char *str)
19912 }
19913 early_param("idle", idle_setup);
19914
19915 -unsigned long arch_align_stack(unsigned long sp)
19916 +#ifdef CONFIG_PAX_RANDKSTACK
19917 +void pax_randomize_kstack(struct pt_regs *regs)
19918 {
19919 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
19920 - sp -= get_random_int() % 8192;
19921 - return sp & ~0xf;
19922 -}
19923 + struct thread_struct *thread = &current->thread;
19924 + unsigned long time;
19925
19926 -unsigned long arch_randomize_brk(struct mm_struct *mm)
19927 -{
19928 - unsigned long range_end = mm->brk + 0x02000000;
19929 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
19930 -}
19931 + if (!randomize_va_space)
19932 + return;
19933 +
19934 + if (v8086_mode(regs))
19935 + return;
19936
19937 + rdtscl(time);
19938 +
19939 + /* P4 seems to return a 0 LSB, ignore it */
19940 +#ifdef CONFIG_MPENTIUM4
19941 + time &= 0x3EUL;
19942 + time <<= 2;
19943 +#elif defined(CONFIG_X86_64)
19944 + time &= 0xFUL;
19945 + time <<= 4;
19946 +#else
19947 + time &= 0x1FUL;
19948 + time <<= 3;
19949 +#endif
19950 +
19951 + thread->sp0 ^= time;
19952 + load_sp0(init_tss + smp_processor_id(), thread);
19953 +
19954 +#ifdef CONFIG_X86_64
19955 + this_cpu_write(kernel_stack, thread->sp0);
19956 +#endif
19957 +}
19958 +#endif
19959 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
19960 index 44e0bff..5ceb99c 100644
19961 --- a/arch/x86/kernel/process_32.c
19962 +++ b/arch/x86/kernel/process_32.c
19963 @@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
19964 unsigned long thread_saved_pc(struct task_struct *tsk)
19965 {
19966 return ((unsigned long *)tsk->thread.sp)[3];
19967 +//XXX return tsk->thread.eip;
19968 }
19969
19970 void __show_regs(struct pt_regs *regs, int all)
19971 @@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
19972 unsigned long sp;
19973 unsigned short ss, gs;
19974
19975 - if (user_mode_vm(regs)) {
19976 + if (user_mode(regs)) {
19977 sp = regs->sp;
19978 ss = regs->ss & 0xffff;
19979 - gs = get_user_gs(regs);
19980 } else {
19981 sp = kernel_stack_pointer(regs);
19982 savesegment(ss, ss);
19983 - savesegment(gs, gs);
19984 }
19985 + gs = get_user_gs(regs);
19986
19987 show_regs_common();
19988
19989 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
19990 (u16)regs->cs, regs->ip, regs->flags,
19991 - smp_processor_id());
19992 + raw_smp_processor_id());
19993 print_symbol("EIP is at %s\n", regs->ip);
19994
19995 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
19996 @@ -131,20 +131,21 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
19997 unsigned long arg,
19998 struct task_struct *p, struct pt_regs *regs)
19999 {
20000 - struct pt_regs *childregs = task_pt_regs(p);
20001 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
20002 struct task_struct *tsk;
20003 int err;
20004
20005 p->thread.sp = (unsigned long) childregs;
20006 p->thread.sp0 = (unsigned long) (childregs+1);
20007 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
20008
20009 if (unlikely(!regs)) {
20010 /* kernel thread */
20011 memset(childregs, 0, sizeof(struct pt_regs));
20012 p->thread.ip = (unsigned long) ret_from_kernel_thread;
20013 - task_user_gs(p) = __KERNEL_STACK_CANARY;
20014 - childregs->ds = __USER_DS;
20015 - childregs->es = __USER_DS;
20016 + savesegment(gs, childregs->gs);
20017 + childregs->ds = __KERNEL_DS;
20018 + childregs->es = __KERNEL_DS;
20019 childregs->fs = __KERNEL_PERCPU;
20020 childregs->bx = sp; /* function */
20021 childregs->bp = arg;
20022 @@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20023 struct thread_struct *prev = &prev_p->thread,
20024 *next = &next_p->thread;
20025 int cpu = smp_processor_id();
20026 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
20027 + struct tss_struct *tss = init_tss + cpu;
20028 fpu_switch_t fpu;
20029
20030 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
20031 @@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20032 */
20033 lazy_save_gs(prev->gs);
20034
20035 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20036 + __set_fs(task_thread_info(next_p)->addr_limit);
20037 +#endif
20038 +
20039 /*
20040 * Load the per-thread Thread-Local Storage descriptor.
20041 */
20042 @@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20043 */
20044 arch_end_context_switch(next_p);
20045
20046 + this_cpu_write(current_task, next_p);
20047 + this_cpu_write(current_tinfo, &next_p->tinfo);
20048 +
20049 /*
20050 * Restore %gs if needed (which is common)
20051 */
20052 @@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20053
20054 switch_fpu_finish(next_p, fpu);
20055
20056 - this_cpu_write(current_task, next_p);
20057 -
20058 return prev_p;
20059 }
20060
20061 @@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
20062 } while (count++ < 16);
20063 return 0;
20064 }
20065 -
20066 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
20067 index 16c6365..5d32218 100644
20068 --- a/arch/x86/kernel/process_64.c
20069 +++ b/arch/x86/kernel/process_64.c
20070 @@ -153,10 +153,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
20071 struct pt_regs *childregs;
20072 struct task_struct *me = current;
20073
20074 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
20075 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
20076 childregs = task_pt_regs(p);
20077 p->thread.sp = (unsigned long) childregs;
20078 p->thread.usersp = me->thread.usersp;
20079 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
20080 set_tsk_thread_flag(p, TIF_FORK);
20081 p->fpu_counter = 0;
20082 p->thread.io_bitmap_ptr = NULL;
20083 @@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20084 struct thread_struct *prev = &prev_p->thread;
20085 struct thread_struct *next = &next_p->thread;
20086 int cpu = smp_processor_id();
20087 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
20088 + struct tss_struct *tss = init_tss + cpu;
20089 unsigned fsindex, gsindex;
20090 fpu_switch_t fpu;
20091
20092 @@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20093 prev->usersp = this_cpu_read(old_rsp);
20094 this_cpu_write(old_rsp, next->usersp);
20095 this_cpu_write(current_task, next_p);
20096 + this_cpu_write(current_tinfo, &next_p->tinfo);
20097
20098 - this_cpu_write(kernel_stack,
20099 - (unsigned long)task_stack_page(next_p) +
20100 - THREAD_SIZE - KERNEL_STACK_OFFSET);
20101 + this_cpu_write(kernel_stack, next->sp0);
20102
20103 /*
20104 * Now maybe reload the debug registers and handle I/O bitmaps
20105 @@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
20106 if (!p || p == current || p->state == TASK_RUNNING)
20107 return 0;
20108 stack = (unsigned long)task_stack_page(p);
20109 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
20110 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
20111 return 0;
20112 fp = *(u64 *)(p->thread.sp);
20113 do {
20114 - if (fp < (unsigned long)stack ||
20115 - fp >= (unsigned long)stack+THREAD_SIZE)
20116 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
20117 return 0;
20118 ip = *(u64 *)(fp+8);
20119 if (!in_sched_functions(ip))
20120 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
20121 index 974b67e..12cb2b5 100644
20122 --- a/arch/x86/kernel/ptrace.c
20123 +++ b/arch/x86/kernel/ptrace.c
20124 @@ -183,14 +183,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
20125 {
20126 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
20127 unsigned long sp = (unsigned long)&regs->sp;
20128 - struct thread_info *tinfo;
20129
20130 - if (context == (sp & ~(THREAD_SIZE - 1)))
20131 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
20132 return sp;
20133
20134 - tinfo = (struct thread_info *)context;
20135 - if (tinfo->previous_esp)
20136 - return tinfo->previous_esp;
20137 + sp = *(unsigned long *)context;
20138 + if (sp)
20139 + return sp;
20140
20141 return (unsigned long)regs;
20142 }
20143 @@ -587,7 +586,7 @@ static void ptrace_triggered(struct perf_event *bp,
20144 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
20145 {
20146 int i;
20147 - int dr7 = 0;
20148 + unsigned long dr7 = 0;
20149 struct arch_hw_breakpoint *info;
20150
20151 for (i = 0; i < HBP_NUM; i++) {
20152 @@ -855,7 +854,7 @@ long arch_ptrace(struct task_struct *child, long request,
20153 unsigned long addr, unsigned long data)
20154 {
20155 int ret;
20156 - unsigned long __user *datap = (unsigned long __user *)data;
20157 + unsigned long __user *datap = (__force unsigned long __user *)data;
20158
20159 switch (request) {
20160 /* read the word at location addr in the USER area. */
20161 @@ -940,14 +939,14 @@ long arch_ptrace(struct task_struct *child, long request,
20162 if ((int) addr < 0)
20163 return -EIO;
20164 ret = do_get_thread_area(child, addr,
20165 - (struct user_desc __user *)data);
20166 + (__force struct user_desc __user *) data);
20167 break;
20168
20169 case PTRACE_SET_THREAD_AREA:
20170 if ((int) addr < 0)
20171 return -EIO;
20172 ret = do_set_thread_area(child, addr,
20173 - (struct user_desc __user *)data, 0);
20174 + (__force struct user_desc __user *) data, 0);
20175 break;
20176 #endif
20177
20178 @@ -1325,7 +1324,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
20179
20180 #ifdef CONFIG_X86_64
20181
20182 -static struct user_regset x86_64_regsets[] __read_mostly = {
20183 +static struct user_regset x86_64_regsets[] = {
20184 [REGSET_GENERAL] = {
20185 .core_note_type = NT_PRSTATUS,
20186 .n = sizeof(struct user_regs_struct) / sizeof(long),
20187 @@ -1366,7 +1365,7 @@ static const struct user_regset_view user_x86_64_view = {
20188 #endif /* CONFIG_X86_64 */
20189
20190 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
20191 -static struct user_regset x86_32_regsets[] __read_mostly = {
20192 +static struct user_regset x86_32_regsets[] = {
20193 [REGSET_GENERAL] = {
20194 .core_note_type = NT_PRSTATUS,
20195 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
20196 @@ -1419,13 +1418,13 @@ static const struct user_regset_view user_x86_32_view = {
20197 */
20198 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
20199
20200 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
20201 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
20202 {
20203 #ifdef CONFIG_X86_64
20204 - x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
20205 + *(unsigned int *)&x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
20206 #endif
20207 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
20208 - x86_32_regsets[REGSET_XSTATE].n = size / sizeof(u64);
20209 + *(unsigned int *)&x86_32_regsets[REGSET_XSTATE].n = size / sizeof(u64);
20210 #endif
20211 xstate_fx_sw_bytes[USER_XSTATE_XCR0_WORD] = xstate_mask;
20212 }
20213 @@ -1454,7 +1453,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
20214 memset(info, 0, sizeof(*info));
20215 info->si_signo = SIGTRAP;
20216 info->si_code = si_code;
20217 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
20218 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
20219 }
20220
20221 void user_single_step_siginfo(struct task_struct *tsk,
20222 @@ -1483,6 +1482,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
20223 # define IS_IA32 0
20224 #endif
20225
20226 +#ifdef CONFIG_GRKERNSEC_SETXID
20227 +extern void gr_delayed_cred_worker(void);
20228 +#endif
20229 +
20230 /*
20231 * We must return the syscall number to actually look up in the table.
20232 * This can be -1L to skip running any syscall at all.
20233 @@ -1493,6 +1496,11 @@ long syscall_trace_enter(struct pt_regs *regs)
20234
20235 rcu_user_exit();
20236
20237 +#ifdef CONFIG_GRKERNSEC_SETXID
20238 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
20239 + gr_delayed_cred_worker();
20240 +#endif
20241 +
20242 /*
20243 * If we stepped into a sysenter/syscall insn, it trapped in
20244 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
20245 @@ -1548,6 +1556,11 @@ void syscall_trace_leave(struct pt_regs *regs)
20246 */
20247 rcu_user_exit();
20248
20249 +#ifdef CONFIG_GRKERNSEC_SETXID
20250 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
20251 + gr_delayed_cred_worker();
20252 +#endif
20253 +
20254 audit_syscall_exit(regs);
20255
20256 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
20257 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
20258 index 42eb330..139955c 100644
20259 --- a/arch/x86/kernel/pvclock.c
20260 +++ b/arch/x86/kernel/pvclock.c
20261 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
20262 return pv_tsc_khz;
20263 }
20264
20265 -static atomic64_t last_value = ATOMIC64_INIT(0);
20266 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
20267
20268 void pvclock_resume(void)
20269 {
20270 - atomic64_set(&last_value, 0);
20271 + atomic64_set_unchecked(&last_value, 0);
20272 }
20273
20274 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
20275 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
20276 * updating at the same time, and one of them could be slightly behind,
20277 * making the assumption that last_value always go forward fail to hold.
20278 */
20279 - last = atomic64_read(&last_value);
20280 + last = atomic64_read_unchecked(&last_value);
20281 do {
20282 if (ret < last)
20283 return last;
20284 - last = atomic64_cmpxchg(&last_value, last, ret);
20285 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
20286 } while (unlikely(last != ret));
20287
20288 return ret;
20289 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
20290 index 76fa1e9..a93c759 100644
20291 --- a/arch/x86/kernel/reboot.c
20292 +++ b/arch/x86/kernel/reboot.c
20293 @@ -36,7 +36,7 @@ void (*pm_power_off)(void);
20294 EXPORT_SYMBOL(pm_power_off);
20295
20296 static const struct desc_ptr no_idt = {};
20297 -static int reboot_mode;
20298 +static unsigned short reboot_mode;
20299 enum reboot_type reboot_type = BOOT_ACPI;
20300 int reboot_force;
20301
20302 @@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
20303
20304 void __noreturn machine_real_restart(unsigned int type)
20305 {
20306 +
20307 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
20308 + struct desc_struct *gdt;
20309 +#endif
20310 +
20311 local_irq_disable();
20312
20313 /*
20314 @@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
20315
20316 /* Jump to the identity-mapped low memory code */
20317 #ifdef CONFIG_X86_32
20318 - asm volatile("jmpl *%0" : :
20319 +
20320 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
20321 + gdt = get_cpu_gdt_table(smp_processor_id());
20322 + pax_open_kernel();
20323 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20324 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
20325 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
20326 + loadsegment(ds, __KERNEL_DS);
20327 + loadsegment(es, __KERNEL_DS);
20328 + loadsegment(ss, __KERNEL_DS);
20329 +#endif
20330 +#ifdef CONFIG_PAX_KERNEXEC
20331 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
20332 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
20333 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
20334 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
20335 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
20336 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
20337 +#endif
20338 + pax_close_kernel();
20339 +#endif
20340 +
20341 + asm volatile("ljmpl *%0" : :
20342 "rm" (real_mode_header->machine_real_restart_asm),
20343 "a" (type));
20344 #else
20345 @@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
20346 * try to force a triple fault and then cycle between hitting the keyboard
20347 * controller and doing that
20348 */
20349 -static void native_machine_emergency_restart(void)
20350 +static void __noreturn native_machine_emergency_restart(void)
20351 {
20352 int i;
20353 int attempt = 0;
20354 @@ -654,13 +681,13 @@ void native_machine_shutdown(void)
20355 #endif
20356 }
20357
20358 -static void __machine_emergency_restart(int emergency)
20359 +static void __noreturn __machine_emergency_restart(int emergency)
20360 {
20361 reboot_emergency = emergency;
20362 machine_ops.emergency_restart();
20363 }
20364
20365 -static void native_machine_restart(char *__unused)
20366 +static void __noreturn native_machine_restart(char *__unused)
20367 {
20368 pr_notice("machine restart\n");
20369
20370 @@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
20371 __machine_emergency_restart(0);
20372 }
20373
20374 -static void native_machine_halt(void)
20375 +static void __noreturn native_machine_halt(void)
20376 {
20377 /* Stop other cpus and apics */
20378 machine_shutdown();
20379 @@ -679,7 +706,7 @@ static void native_machine_halt(void)
20380 stop_this_cpu(NULL);
20381 }
20382
20383 -static void native_machine_power_off(void)
20384 +static void __noreturn native_machine_power_off(void)
20385 {
20386 if (pm_power_off) {
20387 if (!reboot_force)
20388 @@ -688,6 +715,7 @@ static void native_machine_power_off(void)
20389 }
20390 /* A fallback in case there is no PM info available */
20391 tboot_shutdown(TB_SHUTDOWN_HALT);
20392 + unreachable();
20393 }
20394
20395 struct machine_ops machine_ops = {
20396 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
20397 index 7a6f3b3..bed145d7 100644
20398 --- a/arch/x86/kernel/relocate_kernel_64.S
20399 +++ b/arch/x86/kernel/relocate_kernel_64.S
20400 @@ -11,6 +11,7 @@
20401 #include <asm/kexec.h>
20402 #include <asm/processor-flags.h>
20403 #include <asm/pgtable_types.h>
20404 +#include <asm/alternative-asm.h>
20405
20406 /*
20407 * Must be relocatable PIC code callable as a C function
20408 @@ -160,13 +161,14 @@ identity_mapped:
20409 xorq %rbp, %rbp
20410 xorq %r8, %r8
20411 xorq %r9, %r9
20412 - xorq %r10, %r9
20413 + xorq %r10, %r10
20414 xorq %r11, %r11
20415 xorq %r12, %r12
20416 xorq %r13, %r13
20417 xorq %r14, %r14
20418 xorq %r15, %r15
20419
20420 + pax_force_retaddr 0, 1
20421 ret
20422
20423 1:
20424 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
20425 index aeacb0e..f9d4c02 100644
20426 --- a/arch/x86/kernel/setup.c
20427 +++ b/arch/x86/kernel/setup.c
20428 @@ -441,7 +441,7 @@ static void __init parse_setup_data(void)
20429
20430 switch (data->type) {
20431 case SETUP_E820_EXT:
20432 - parse_e820_ext(data);
20433 + parse_e820_ext((struct setup_data __force_kernel *)data);
20434 break;
20435 case SETUP_DTB:
20436 add_dtb(pa_data);
20437 @@ -710,7 +710,7 @@ static void __init trim_bios_range(void)
20438 * area (640->1Mb) as ram even though it is not.
20439 * take them out.
20440 */
20441 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
20442 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
20443
20444 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
20445 }
20446 @@ -834,14 +834,14 @@ void __init setup_arch(char **cmdline_p)
20447
20448 if (!boot_params.hdr.root_flags)
20449 root_mountflags &= ~MS_RDONLY;
20450 - init_mm.start_code = (unsigned long) _text;
20451 - init_mm.end_code = (unsigned long) _etext;
20452 + init_mm.start_code = ktla_ktva((unsigned long) _text);
20453 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
20454 init_mm.end_data = (unsigned long) _edata;
20455 init_mm.brk = _brk_end;
20456
20457 - code_resource.start = virt_to_phys(_text);
20458 - code_resource.end = virt_to_phys(_etext)-1;
20459 - data_resource.start = virt_to_phys(_etext);
20460 + code_resource.start = virt_to_phys(ktla_ktva(_text));
20461 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
20462 + data_resource.start = virt_to_phys(_sdata);
20463 data_resource.end = virt_to_phys(_edata)-1;
20464 bss_resource.start = virt_to_phys(&__bss_start);
20465 bss_resource.end = virt_to_phys(&__bss_stop)-1;
20466 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
20467 index 5cdff03..5810740 100644
20468 --- a/arch/x86/kernel/setup_percpu.c
20469 +++ b/arch/x86/kernel/setup_percpu.c
20470 @@ -21,19 +21,17 @@
20471 #include <asm/cpu.h>
20472 #include <asm/stackprotector.h>
20473
20474 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
20475 +#ifdef CONFIG_SMP
20476 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
20477 EXPORT_PER_CPU_SYMBOL(cpu_number);
20478 +#endif
20479
20480 -#ifdef CONFIG_X86_64
20481 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
20482 -#else
20483 -#define BOOT_PERCPU_OFFSET 0
20484 -#endif
20485
20486 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
20487 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
20488
20489 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
20490 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
20491 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
20492 };
20493 EXPORT_SYMBOL(__per_cpu_offset);
20494 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
20495 {
20496 #ifdef CONFIG_X86_32
20497 struct desc_struct gdt;
20498 + unsigned long base = per_cpu_offset(cpu);
20499
20500 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
20501 - 0x2 | DESCTYPE_S, 0x8);
20502 - gdt.s = 1;
20503 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
20504 + 0x83 | DESCTYPE_S, 0xC);
20505 write_gdt_entry(get_cpu_gdt_table(cpu),
20506 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
20507 #endif
20508 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
20509 /* alrighty, percpu areas up and running */
20510 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
20511 for_each_possible_cpu(cpu) {
20512 +#ifdef CONFIG_CC_STACKPROTECTOR
20513 +#ifdef CONFIG_X86_32
20514 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
20515 +#endif
20516 +#endif
20517 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
20518 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
20519 per_cpu(cpu_number, cpu) = cpu;
20520 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
20521 */
20522 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
20523 #endif
20524 +#ifdef CONFIG_CC_STACKPROTECTOR
20525 +#ifdef CONFIG_X86_32
20526 + if (!cpu)
20527 + per_cpu(stack_canary.canary, cpu) = canary;
20528 +#endif
20529 +#endif
20530 /*
20531 * Up to this point, the boot CPU has been using .init.data
20532 * area. Reload any changed state for the boot CPU.
20533 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
20534 index 70b27ee..fcf827f 100644
20535 --- a/arch/x86/kernel/signal.c
20536 +++ b/arch/x86/kernel/signal.c
20537 @@ -195,7 +195,7 @@ static unsigned long align_sigframe(unsigned long sp)
20538 * Align the stack pointer according to the i386 ABI,
20539 * i.e. so that on function entry ((sp + 4) & 15) == 0.
20540 */
20541 - sp = ((sp + 4) & -16ul) - 4;
20542 + sp = ((sp - 12) & -16ul) - 4;
20543 #else /* !CONFIG_X86_32 */
20544 sp = round_down(sp, 16) - 8;
20545 #endif
20546 @@ -303,9 +303,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
20547 }
20548
20549 if (current->mm->context.vdso)
20550 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
20551 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
20552 else
20553 - restorer = &frame->retcode;
20554 + restorer = (void __user *)&frame->retcode;
20555 if (ka->sa.sa_flags & SA_RESTORER)
20556 restorer = ka->sa.sa_restorer;
20557
20558 @@ -319,7 +319,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
20559 * reasons and because gdb uses it as a signature to notice
20560 * signal handler stack frames.
20561 */
20562 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
20563 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
20564
20565 if (err)
20566 return -EFAULT;
20567 @@ -369,7 +369,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
20568 put_user_ex(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
20569
20570 /* Set up to return from userspace. */
20571 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
20572 + if (current->mm->context.vdso)
20573 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
20574 + else
20575 + restorer = (void __user *)&frame->retcode;
20576 if (ka->sa.sa_flags & SA_RESTORER)
20577 restorer = ka->sa.sa_restorer;
20578 put_user_ex(restorer, &frame->pretcode);
20579 @@ -381,7 +384,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
20580 * reasons and because gdb uses it as a signature to notice
20581 * signal handler stack frames.
20582 */
20583 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
20584 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
20585 } put_user_catch(err);
20586
20587 err |= copy_siginfo_to_user(&frame->info, info);
20588 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
20589 index f3e2ec8..ad5287a 100644
20590 --- a/arch/x86/kernel/smpboot.c
20591 +++ b/arch/x86/kernel/smpboot.c
20592 @@ -673,6 +673,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
20593 idle->thread.sp = (unsigned long) (((struct pt_regs *)
20594 (THREAD_SIZE + task_stack_page(idle))) - 1);
20595 per_cpu(current_task, cpu) = idle;
20596 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
20597
20598 #ifdef CONFIG_X86_32
20599 /* Stack for startup_32 can be just as for start_secondary onwards */
20600 @@ -680,11 +681,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
20601 #else
20602 clear_tsk_thread_flag(idle, TIF_FORK);
20603 initial_gs = per_cpu_offset(cpu);
20604 - per_cpu(kernel_stack, cpu) =
20605 - (unsigned long)task_stack_page(idle) -
20606 - KERNEL_STACK_OFFSET + THREAD_SIZE;
20607 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
20608 #endif
20609 +
20610 + pax_open_kernel();
20611 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
20612 + pax_close_kernel();
20613 +
20614 initial_code = (unsigned long)start_secondary;
20615 stack_start = idle->thread.sp;
20616
20617 @@ -823,6 +826,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
20618 /* the FPU context is blank, nobody can own it */
20619 __cpu_disable_lazy_restore(cpu);
20620
20621 +#ifdef CONFIG_PAX_PER_CPU_PGD
20622 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
20623 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
20624 + KERNEL_PGD_PTRS);
20625 +#endif
20626 +
20627 + /* the FPU context is blank, nobody can own it */
20628 + __cpu_disable_lazy_restore(cpu);
20629 +
20630 err = do_boot_cpu(apicid, cpu, tidle);
20631 if (err) {
20632 pr_debug("do_boot_cpu failed %d\n", err);
20633 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
20634 index 9b4d51d..5d28b58 100644
20635 --- a/arch/x86/kernel/step.c
20636 +++ b/arch/x86/kernel/step.c
20637 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
20638 struct desc_struct *desc;
20639 unsigned long base;
20640
20641 - seg &= ~7UL;
20642 + seg >>= 3;
20643
20644 mutex_lock(&child->mm->context.lock);
20645 - if (unlikely((seg >> 3) >= child->mm->context.size))
20646 + if (unlikely(seg >= child->mm->context.size))
20647 addr = -1L; /* bogus selector, access would fault */
20648 else {
20649 desc = child->mm->context.ldt + seg;
20650 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
20651 addr += base;
20652 }
20653 mutex_unlock(&child->mm->context.lock);
20654 - }
20655 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
20656 + addr = ktla_ktva(addr);
20657
20658 return addr;
20659 }
20660 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
20661 unsigned char opcode[15];
20662 unsigned long addr = convert_ip_to_linear(child, regs);
20663
20664 + if (addr == -EINVAL)
20665 + return 0;
20666 +
20667 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
20668 for (i = 0; i < copied; i++) {
20669 switch (opcode[i]) {
20670 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
20671 new file mode 100644
20672 index 0000000..26bb1af
20673 --- /dev/null
20674 +++ b/arch/x86/kernel/sys_i386_32.c
20675 @@ -0,0 +1,249 @@
20676 +/*
20677 + * This file contains various random system calls that
20678 + * have a non-standard calling sequence on the Linux/i386
20679 + * platform.
20680 + */
20681 +
20682 +#include <linux/errno.h>
20683 +#include <linux/sched.h>
20684 +#include <linux/mm.h>
20685 +#include <linux/fs.h>
20686 +#include <linux/smp.h>
20687 +#include <linux/sem.h>
20688 +#include <linux/msg.h>
20689 +#include <linux/shm.h>
20690 +#include <linux/stat.h>
20691 +#include <linux/syscalls.h>
20692 +#include <linux/mman.h>
20693 +#include <linux/file.h>
20694 +#include <linux/utsname.h>
20695 +#include <linux/ipc.h>
20696 +
20697 +#include <linux/uaccess.h>
20698 +#include <linux/unistd.h>
20699 +
20700 +#include <asm/syscalls.h>
20701 +
20702 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
20703 +{
20704 + unsigned long pax_task_size = TASK_SIZE;
20705 +
20706 +#ifdef CONFIG_PAX_SEGMEXEC
20707 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
20708 + pax_task_size = SEGMEXEC_TASK_SIZE;
20709 +#endif
20710 +
20711 + if (len > pax_task_size || addr > pax_task_size - len)
20712 + return -EINVAL;
20713 +
20714 + return 0;
20715 +}
20716 +
20717 +unsigned long
20718 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
20719 + unsigned long len, unsigned long pgoff, unsigned long flags)
20720 +{
20721 + struct mm_struct *mm = current->mm;
20722 + struct vm_area_struct *vma;
20723 + unsigned long start_addr, pax_task_size = TASK_SIZE;
20724 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
20725 +
20726 +#ifdef CONFIG_PAX_SEGMEXEC
20727 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
20728 + pax_task_size = SEGMEXEC_TASK_SIZE;
20729 +#endif
20730 +
20731 + pax_task_size -= PAGE_SIZE;
20732 +
20733 + if (len > pax_task_size)
20734 + return -ENOMEM;
20735 +
20736 + if (flags & MAP_FIXED)
20737 + return addr;
20738 +
20739 +#ifdef CONFIG_PAX_RANDMMAP
20740 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20741 +#endif
20742 +
20743 + if (addr) {
20744 + addr = PAGE_ALIGN(addr);
20745 + if (pax_task_size - len >= addr) {
20746 + vma = find_vma(mm, addr);
20747 + if (check_heap_stack_gap(vma, addr, len, offset))
20748 + return addr;
20749 + }
20750 + }
20751 + if (len > mm->cached_hole_size) {
20752 + start_addr = addr = mm->free_area_cache;
20753 + } else {
20754 + start_addr = addr = mm->mmap_base;
20755 + mm->cached_hole_size = 0;
20756 + }
20757 +
20758 +#ifdef CONFIG_PAX_PAGEEXEC
20759 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
20760 + start_addr = 0x00110000UL;
20761 +
20762 +#ifdef CONFIG_PAX_RANDMMAP
20763 + if (mm->pax_flags & MF_PAX_RANDMMAP)
20764 + start_addr += mm->delta_mmap & 0x03FFF000UL;
20765 +#endif
20766 +
20767 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
20768 + start_addr = addr = mm->mmap_base;
20769 + else
20770 + addr = start_addr;
20771 + }
20772 +#endif
20773 +
20774 +full_search:
20775 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
20776 + /* At this point: (!vma || addr < vma->vm_end). */
20777 + if (pax_task_size - len < addr) {
20778 + /*
20779 + * Start a new search - just in case we missed
20780 + * some holes.
20781 + */
20782 + if (start_addr != mm->mmap_base) {
20783 + start_addr = addr = mm->mmap_base;
20784 + mm->cached_hole_size = 0;
20785 + goto full_search;
20786 + }
20787 + return -ENOMEM;
20788 + }
20789 + if (check_heap_stack_gap(vma, addr, len, offset))
20790 + break;
20791 + if (addr + mm->cached_hole_size < vma->vm_start)
20792 + mm->cached_hole_size = vma->vm_start - addr;
20793 + addr = vma->vm_end;
20794 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
20795 + start_addr = addr = mm->mmap_base;
20796 + mm->cached_hole_size = 0;
20797 + goto full_search;
20798 + }
20799 + }
20800 +
20801 + /*
20802 + * Remember the place where we stopped the search:
20803 + */
20804 + mm->free_area_cache = addr + len;
20805 + return addr;
20806 +}
20807 +
20808 +unsigned long
20809 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
20810 + const unsigned long len, const unsigned long pgoff,
20811 + const unsigned long flags)
20812 +{
20813 + struct vm_area_struct *vma;
20814 + struct mm_struct *mm = current->mm;
20815 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
20816 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
20817 +
20818 +#ifdef CONFIG_PAX_SEGMEXEC
20819 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
20820 + pax_task_size = SEGMEXEC_TASK_SIZE;
20821 +#endif
20822 +
20823 + pax_task_size -= PAGE_SIZE;
20824 +
20825 + /* requested length too big for entire address space */
20826 + if (len > pax_task_size)
20827 + return -ENOMEM;
20828 +
20829 + if (flags & MAP_FIXED)
20830 + return addr;
20831 +
20832 +#ifdef CONFIG_PAX_PAGEEXEC
20833 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
20834 + goto bottomup;
20835 +#endif
20836 +
20837 +#ifdef CONFIG_PAX_RANDMMAP
20838 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20839 +#endif
20840 +
20841 + /* requesting a specific address */
20842 + if (addr) {
20843 + addr = PAGE_ALIGN(addr);
20844 + if (pax_task_size - len >= addr) {
20845 + vma = find_vma(mm, addr);
20846 + if (check_heap_stack_gap(vma, addr, len, offset))
20847 + return addr;
20848 + }
20849 + }
20850 +
20851 + /* check if free_area_cache is useful for us */
20852 + if (len <= mm->cached_hole_size) {
20853 + mm->cached_hole_size = 0;
20854 + mm->free_area_cache = mm->mmap_base;
20855 + }
20856 +
20857 + /* either no address requested or can't fit in requested address hole */
20858 + addr = mm->free_area_cache;
20859 +
20860 + /* make sure it can fit in the remaining address space */
20861 + if (addr > len) {
20862 + vma = find_vma(mm, addr-len);
20863 + if (check_heap_stack_gap(vma, addr - len, len, offset))
20864 + /* remember the address as a hint for next time */
20865 + return (mm->free_area_cache = addr-len);
20866 + }
20867 +
20868 + if (mm->mmap_base < len)
20869 + goto bottomup;
20870 +
20871 + addr = mm->mmap_base-len;
20872 +
20873 + do {
20874 + /*
20875 + * Lookup failure means no vma is above this address,
20876 + * else if new region fits below vma->vm_start,
20877 + * return with success:
20878 + */
20879 + vma = find_vma(mm, addr);
20880 + if (check_heap_stack_gap(vma, addr, len, offset))
20881 + /* remember the address as a hint for next time */
20882 + return (mm->free_area_cache = addr);
20883 +
20884 + /* remember the largest hole we saw so far */
20885 + if (addr + mm->cached_hole_size < vma->vm_start)
20886 + mm->cached_hole_size = vma->vm_start - addr;
20887 +
20888 + /* try just below the current vma->vm_start */
20889 + addr = skip_heap_stack_gap(vma, len, offset);
20890 + } while (!IS_ERR_VALUE(addr));
20891 +
20892 +bottomup:
20893 + /*
20894 + * A failed mmap() very likely causes application failure,
20895 + * so fall back to the bottom-up function here. This scenario
20896 + * can happen with large stack limits and large mmap()
20897 + * allocations.
20898 + */
20899 +
20900 +#ifdef CONFIG_PAX_SEGMEXEC
20901 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
20902 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
20903 + else
20904 +#endif
20905 +
20906 + mm->mmap_base = TASK_UNMAPPED_BASE;
20907 +
20908 +#ifdef CONFIG_PAX_RANDMMAP
20909 + if (mm->pax_flags & MF_PAX_RANDMMAP)
20910 + mm->mmap_base += mm->delta_mmap;
20911 +#endif
20912 +
20913 + mm->free_area_cache = mm->mmap_base;
20914 + mm->cached_hole_size = ~0UL;
20915 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
20916 + /*
20917 + * Restore the topdown base:
20918 + */
20919 + mm->mmap_base = base;
20920 + mm->free_area_cache = base;
20921 + mm->cached_hole_size = ~0UL;
20922 +
20923 + return addr;
20924 +}
20925 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
20926 index b4d3c39..d699d77 100644
20927 --- a/arch/x86/kernel/sys_x86_64.c
20928 +++ b/arch/x86/kernel/sys_x86_64.c
20929 @@ -95,8 +95,8 @@ out:
20930 return error;
20931 }
20932
20933 -static void find_start_end(unsigned long flags, unsigned long *begin,
20934 - unsigned long *end)
20935 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
20936 + unsigned long *begin, unsigned long *end)
20937 {
20938 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
20939 unsigned long new_begin;
20940 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
20941 *begin = new_begin;
20942 }
20943 } else {
20944 - *begin = TASK_UNMAPPED_BASE;
20945 + *begin = mm->mmap_base;
20946 *end = TASK_SIZE;
20947 }
20948 }
20949 @@ -128,20 +128,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
20950 struct vm_area_struct *vma;
20951 unsigned long start_addr;
20952 unsigned long begin, end;
20953 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
20954
20955 if (flags & MAP_FIXED)
20956 return addr;
20957
20958 - find_start_end(flags, &begin, &end);
20959 + find_start_end(mm, flags, &begin, &end);
20960
20961 if (len > end)
20962 return -ENOMEM;
20963
20964 +#ifdef CONFIG_PAX_RANDMMAP
20965 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20966 +#endif
20967 +
20968 if (addr) {
20969 addr = PAGE_ALIGN(addr);
20970 vma = find_vma(mm, addr);
20971 - if (end - len >= addr &&
20972 - (!vma || addr + len <= vma->vm_start))
20973 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
20974 return addr;
20975 }
20976 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
20977 @@ -172,7 +176,7 @@ full_search:
20978 }
20979 return -ENOMEM;
20980 }
20981 - if (!vma || addr + len <= vma->vm_start) {
20982 + if (check_heap_stack_gap(vma, addr, len, offset)) {
20983 /*
20984 * Remember the place where we stopped the search:
20985 */
20986 @@ -195,7 +199,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
20987 {
20988 struct vm_area_struct *vma;
20989 struct mm_struct *mm = current->mm;
20990 - unsigned long addr = addr0, start_addr;
20991 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
20992 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
20993
20994 /* requested length too big for entire address space */
20995 if (len > TASK_SIZE)
20996 @@ -208,13 +213,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
20997 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
20998 goto bottomup;
20999
21000 +#ifdef CONFIG_PAX_RANDMMAP
21001 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
21002 +#endif
21003 +
21004 /* requesting a specific address */
21005 if (addr) {
21006 addr = PAGE_ALIGN(addr);
21007 - vma = find_vma(mm, addr);
21008 - if (TASK_SIZE - len >= addr &&
21009 - (!vma || addr + len <= vma->vm_start))
21010 - return addr;
21011 + if (TASK_SIZE - len >= addr) {
21012 + vma = find_vma(mm, addr);
21013 + if (check_heap_stack_gap(vma, addr, len, offset))
21014 + return addr;
21015 + }
21016 }
21017
21018 /* check if free_area_cache is useful for us */
21019 @@ -240,7 +250,7 @@ try_again:
21020 * return with success:
21021 */
21022 vma = find_vma(mm, addr);
21023 - if (!vma || addr+len <= vma->vm_start)
21024 + if (check_heap_stack_gap(vma, addr, len, offset))
21025 /* remember the address as a hint for next time */
21026 return mm->free_area_cache = addr;
21027
21028 @@ -249,8 +259,8 @@ try_again:
21029 mm->cached_hole_size = vma->vm_start - addr;
21030
21031 /* try just below the current vma->vm_start */
21032 - addr = vma->vm_start-len;
21033 - } while (len < vma->vm_start);
21034 + addr = skip_heap_stack_gap(vma, len, offset);
21035 + } while (!IS_ERR_VALUE(addr));
21036
21037 fail:
21038 /*
21039 @@ -270,13 +280,21 @@ bottomup:
21040 * can happen with large stack limits and large mmap()
21041 * allocations.
21042 */
21043 + mm->mmap_base = TASK_UNMAPPED_BASE;
21044 +
21045 +#ifdef CONFIG_PAX_RANDMMAP
21046 + if (mm->pax_flags & MF_PAX_RANDMMAP)
21047 + mm->mmap_base += mm->delta_mmap;
21048 +#endif
21049 +
21050 + mm->free_area_cache = mm->mmap_base;
21051 mm->cached_hole_size = ~0UL;
21052 - mm->free_area_cache = TASK_UNMAPPED_BASE;
21053 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
21054 /*
21055 * Restore the topdown base:
21056 */
21057 - mm->free_area_cache = mm->mmap_base;
21058 + mm->mmap_base = base;
21059 + mm->free_area_cache = base;
21060 mm->cached_hole_size = ~0UL;
21061
21062 return addr;
21063 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
21064 index f84fe00..93fe08f 100644
21065 --- a/arch/x86/kernel/tboot.c
21066 +++ b/arch/x86/kernel/tboot.c
21067 @@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
21068
21069 void tboot_shutdown(u32 shutdown_type)
21070 {
21071 - void (*shutdown)(void);
21072 + void (* __noreturn shutdown)(void);
21073
21074 if (!tboot_enabled())
21075 return;
21076 @@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
21077
21078 switch_to_tboot_pt();
21079
21080 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
21081 + shutdown = (void *)tboot->shutdown_entry;
21082 shutdown();
21083
21084 /* should not reach here */
21085 @@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
21086 return 0;
21087 }
21088
21089 -static atomic_t ap_wfs_count;
21090 +static atomic_unchecked_t ap_wfs_count;
21091
21092 static int tboot_wait_for_aps(int num_aps)
21093 {
21094 @@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
21095 {
21096 switch (action) {
21097 case CPU_DYING:
21098 - atomic_inc(&ap_wfs_count);
21099 + atomic_inc_unchecked(&ap_wfs_count);
21100 if (num_online_cpus() == 1)
21101 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
21102 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
21103 return NOTIFY_BAD;
21104 break;
21105 }
21106 @@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
21107
21108 tboot_create_trampoline();
21109
21110 - atomic_set(&ap_wfs_count, 0);
21111 + atomic_set_unchecked(&ap_wfs_count, 0);
21112 register_hotcpu_notifier(&tboot_cpu_notifier);
21113
21114 acpi_os_set_prepare_sleep(&tboot_sleep);
21115 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
21116 index 24d3c91..d06b473 100644
21117 --- a/arch/x86/kernel/time.c
21118 +++ b/arch/x86/kernel/time.c
21119 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
21120 {
21121 unsigned long pc = instruction_pointer(regs);
21122
21123 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
21124 + if (!user_mode(regs) && in_lock_functions(pc)) {
21125 #ifdef CONFIG_FRAME_POINTER
21126 - return *(unsigned long *)(regs->bp + sizeof(long));
21127 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
21128 #else
21129 unsigned long *sp =
21130 (unsigned long *)kernel_stack_pointer(regs);
21131 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
21132 * or above a saved flags. Eflags has bits 22-31 zero,
21133 * kernel addresses don't.
21134 */
21135 +
21136 +#ifdef CONFIG_PAX_KERNEXEC
21137 + return ktla_ktva(sp[0]);
21138 +#else
21139 if (sp[0] >> 22)
21140 return sp[0];
21141 if (sp[1] >> 22)
21142 return sp[1];
21143 #endif
21144 +
21145 +#endif
21146 }
21147 return pc;
21148 }
21149 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
21150 index 9d9d2f9..cad418a 100644
21151 --- a/arch/x86/kernel/tls.c
21152 +++ b/arch/x86/kernel/tls.c
21153 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
21154 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
21155 return -EINVAL;
21156
21157 +#ifdef CONFIG_PAX_SEGMEXEC
21158 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
21159 + return -EINVAL;
21160 +#endif
21161 +
21162 set_tls_desc(p, idx, &info, 1);
21163
21164 return 0;
21165 @@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
21166
21167 if (kbuf)
21168 info = kbuf;
21169 - else if (__copy_from_user(infobuf, ubuf, count))
21170 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
21171 return -EFAULT;
21172 else
21173 info = infobuf;
21174 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
21175 index 8276dc6..4ca48a2 100644
21176 --- a/arch/x86/kernel/traps.c
21177 +++ b/arch/x86/kernel/traps.c
21178 @@ -71,12 +71,6 @@ asmlinkage int system_call(void);
21179
21180 /* Do we ignore FPU interrupts ? */
21181 char ignore_fpu_irq;
21182 -
21183 -/*
21184 - * The IDT has to be page-aligned to simplify the Pentium
21185 - * F0 0F bug workaround.
21186 - */
21187 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
21188 #endif
21189
21190 DECLARE_BITMAP(used_vectors, NR_VECTORS);
21191 @@ -109,11 +103,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
21192 }
21193
21194 static int __kprobes
21195 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
21196 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
21197 struct pt_regs *regs, long error_code)
21198 {
21199 #ifdef CONFIG_X86_32
21200 - if (regs->flags & X86_VM_MASK) {
21201 + if (v8086_mode(regs)) {
21202 /*
21203 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
21204 * On nmi (interrupt 2), do_trap should not be called.
21205 @@ -126,12 +120,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
21206 return -1;
21207 }
21208 #endif
21209 - if (!user_mode(regs)) {
21210 + if (!user_mode_novm(regs)) {
21211 if (!fixup_exception(regs)) {
21212 tsk->thread.error_code = error_code;
21213 tsk->thread.trap_nr = trapnr;
21214 +
21215 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21216 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
21217 + str = "PAX: suspicious stack segment fault";
21218 +#endif
21219 +
21220 die(str, regs, error_code);
21221 }
21222 +
21223 +#ifdef CONFIG_PAX_REFCOUNT
21224 + if (trapnr == 4)
21225 + pax_report_refcount_overflow(regs);
21226 +#endif
21227 +
21228 return 0;
21229 }
21230
21231 @@ -139,7 +145,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
21232 }
21233
21234 static void __kprobes
21235 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
21236 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
21237 long error_code, siginfo_t *info)
21238 {
21239 struct task_struct *tsk = current;
21240 @@ -163,7 +169,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
21241 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
21242 printk_ratelimit()) {
21243 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
21244 - tsk->comm, tsk->pid, str,
21245 + tsk->comm, task_pid_nr(tsk), str,
21246 regs->ip, regs->sp, error_code);
21247 print_vma_addr(" in ", regs->ip);
21248 pr_cont("\n");
21249 @@ -269,7 +275,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
21250 conditional_sti(regs);
21251
21252 #ifdef CONFIG_X86_32
21253 - if (regs->flags & X86_VM_MASK) {
21254 + if (v8086_mode(regs)) {
21255 local_irq_enable();
21256 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
21257 goto exit;
21258 @@ -277,18 +283,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
21259 #endif
21260
21261 tsk = current;
21262 - if (!user_mode(regs)) {
21263 + if (!user_mode_novm(regs)) {
21264 if (fixup_exception(regs))
21265 goto exit;
21266
21267 tsk->thread.error_code = error_code;
21268 tsk->thread.trap_nr = X86_TRAP_GP;
21269 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
21270 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
21271 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
21272 +
21273 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21274 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
21275 + die("PAX: suspicious general protection fault", regs, error_code);
21276 + else
21277 +#endif
21278 +
21279 die("general protection fault", regs, error_code);
21280 + }
21281 goto exit;
21282 }
21283
21284 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
21285 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
21286 + struct mm_struct *mm = tsk->mm;
21287 + unsigned long limit;
21288 +
21289 + down_write(&mm->mmap_sem);
21290 + limit = mm->context.user_cs_limit;
21291 + if (limit < TASK_SIZE) {
21292 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
21293 + up_write(&mm->mmap_sem);
21294 + return;
21295 + }
21296 + up_write(&mm->mmap_sem);
21297 + }
21298 +#endif
21299 +
21300 tsk->thread.error_code = error_code;
21301 tsk->thread.trap_nr = X86_TRAP_GP;
21302
21303 @@ -443,7 +473,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
21304 /* It's safe to allow irq's after DR6 has been saved */
21305 preempt_conditional_sti(regs);
21306
21307 - if (regs->flags & X86_VM_MASK) {
21308 + if (v8086_mode(regs)) {
21309 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
21310 X86_TRAP_DB);
21311 preempt_conditional_cli(regs);
21312 @@ -458,7 +488,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
21313 * We already checked v86 mode above, so we can check for kernel mode
21314 * by just checking the CPL of CS.
21315 */
21316 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
21317 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
21318 tsk->thread.debugreg6 &= ~DR_STEP;
21319 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
21320 regs->flags &= ~X86_EFLAGS_TF;
21321 @@ -490,7 +520,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
21322 return;
21323 conditional_sti(regs);
21324
21325 - if (!user_mode_vm(regs))
21326 + if (!user_mode(regs))
21327 {
21328 if (!fixup_exception(regs)) {
21329 task->thread.error_code = error_code;
21330 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
21331 index aafa555..a04691a 100644
21332 --- a/arch/x86/kernel/uprobes.c
21333 +++ b/arch/x86/kernel/uprobes.c
21334 @@ -614,7 +614,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
21335 int ret = NOTIFY_DONE;
21336
21337 /* We are only interested in userspace traps */
21338 - if (regs && !user_mode_vm(regs))
21339 + if (regs && !user_mode(regs))
21340 return NOTIFY_DONE;
21341
21342 switch (val) {
21343 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
21344 index b9242ba..50c5edd 100644
21345 --- a/arch/x86/kernel/verify_cpu.S
21346 +++ b/arch/x86/kernel/verify_cpu.S
21347 @@ -20,6 +20,7 @@
21348 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
21349 * arch/x86/kernel/trampoline_64.S: secondary processor verification
21350 * arch/x86/kernel/head_32.S: processor startup
21351 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
21352 *
21353 * verify_cpu, returns the status of longmode and SSE in register %eax.
21354 * 0: Success 1: Failure
21355 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
21356 index 5c9687b..5f857d3 100644
21357 --- a/arch/x86/kernel/vm86_32.c
21358 +++ b/arch/x86/kernel/vm86_32.c
21359 @@ -43,6 +43,7 @@
21360 #include <linux/ptrace.h>
21361 #include <linux/audit.h>
21362 #include <linux/stddef.h>
21363 +#include <linux/grsecurity.h>
21364
21365 #include <asm/uaccess.h>
21366 #include <asm/io.h>
21367 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
21368 do_exit(SIGSEGV);
21369 }
21370
21371 - tss = &per_cpu(init_tss, get_cpu());
21372 + tss = init_tss + get_cpu();
21373 current->thread.sp0 = current->thread.saved_sp0;
21374 current->thread.sysenter_cs = __KERNEL_CS;
21375 load_sp0(tss, &current->thread);
21376 @@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
21377 struct task_struct *tsk;
21378 int tmp, ret = -EPERM;
21379
21380 +#ifdef CONFIG_GRKERNSEC_VM86
21381 + if (!capable(CAP_SYS_RAWIO)) {
21382 + gr_handle_vm86();
21383 + goto out;
21384 + }
21385 +#endif
21386 +
21387 tsk = current;
21388 if (tsk->thread.saved_sp0)
21389 goto out;
21390 @@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
21391 int tmp, ret;
21392 struct vm86plus_struct __user *v86;
21393
21394 +#ifdef CONFIG_GRKERNSEC_VM86
21395 + if (!capable(CAP_SYS_RAWIO)) {
21396 + gr_handle_vm86();
21397 + ret = -EPERM;
21398 + goto out;
21399 + }
21400 +#endif
21401 +
21402 tsk = current;
21403 switch (cmd) {
21404 case VM86_REQUEST_IRQ:
21405 @@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
21406 tsk->thread.saved_fs = info->regs32->fs;
21407 tsk->thread.saved_gs = get_user_gs(info->regs32);
21408
21409 - tss = &per_cpu(init_tss, get_cpu());
21410 + tss = init_tss + get_cpu();
21411 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
21412 if (cpu_has_sep)
21413 tsk->thread.sysenter_cs = 0;
21414 @@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
21415 goto cannot_handle;
21416 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
21417 goto cannot_handle;
21418 - intr_ptr = (unsigned long __user *) (i << 2);
21419 + intr_ptr = (__force unsigned long __user *) (i << 2);
21420 if (get_user(segoffs, intr_ptr))
21421 goto cannot_handle;
21422 if ((segoffs >> 16) == BIOSSEG)
21423 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
21424 index 22a1530..8fbaaad 100644
21425 --- a/arch/x86/kernel/vmlinux.lds.S
21426 +++ b/arch/x86/kernel/vmlinux.lds.S
21427 @@ -26,6 +26,13 @@
21428 #include <asm/page_types.h>
21429 #include <asm/cache.h>
21430 #include <asm/boot.h>
21431 +#include <asm/segment.h>
21432 +
21433 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21434 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
21435 +#else
21436 +#define __KERNEL_TEXT_OFFSET 0
21437 +#endif
21438
21439 #undef i386 /* in case the preprocessor is a 32bit one */
21440
21441 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
21442
21443 PHDRS {
21444 text PT_LOAD FLAGS(5); /* R_E */
21445 +#ifdef CONFIG_X86_32
21446 + module PT_LOAD FLAGS(5); /* R_E */
21447 +#endif
21448 +#ifdef CONFIG_XEN
21449 + rodata PT_LOAD FLAGS(5); /* R_E */
21450 +#else
21451 + rodata PT_LOAD FLAGS(4); /* R__ */
21452 +#endif
21453 data PT_LOAD FLAGS(6); /* RW_ */
21454 -#ifdef CONFIG_X86_64
21455 + init.begin PT_LOAD FLAGS(6); /* RW_ */
21456 #ifdef CONFIG_SMP
21457 percpu PT_LOAD FLAGS(6); /* RW_ */
21458 #endif
21459 + text.init PT_LOAD FLAGS(5); /* R_E */
21460 + text.exit PT_LOAD FLAGS(5); /* R_E */
21461 init PT_LOAD FLAGS(7); /* RWE */
21462 -#endif
21463 note PT_NOTE FLAGS(0); /* ___ */
21464 }
21465
21466 SECTIONS
21467 {
21468 #ifdef CONFIG_X86_32
21469 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
21470 - phys_startup_32 = startup_32 - LOAD_OFFSET;
21471 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
21472 #else
21473 - . = __START_KERNEL;
21474 - phys_startup_64 = startup_64 - LOAD_OFFSET;
21475 + . = __START_KERNEL;
21476 #endif
21477
21478 /* Text and read-only data */
21479 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
21480 - _text = .;
21481 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
21482 /* bootstrapping code */
21483 +#ifdef CONFIG_X86_32
21484 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
21485 +#else
21486 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
21487 +#endif
21488 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
21489 + _text = .;
21490 HEAD_TEXT
21491 #ifdef CONFIG_X86_32
21492 . = ALIGN(PAGE_SIZE);
21493 @@ -108,13 +128,48 @@ SECTIONS
21494 IRQENTRY_TEXT
21495 *(.fixup)
21496 *(.gnu.warning)
21497 - /* End of text section */
21498 - _etext = .;
21499 } :text = 0x9090
21500
21501 - NOTES :text :note
21502 + . += __KERNEL_TEXT_OFFSET;
21503
21504 - EXCEPTION_TABLE(16) :text = 0x9090
21505 +#ifdef CONFIG_X86_32
21506 + . = ALIGN(PAGE_SIZE);
21507 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
21508 +
21509 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
21510 + MODULES_EXEC_VADDR = .;
21511 + BYTE(0)
21512 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
21513 + . = ALIGN(HPAGE_SIZE) - 1;
21514 + MODULES_EXEC_END = .;
21515 +#endif
21516 +
21517 + } :module
21518 +#endif
21519 +
21520 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
21521 + /* End of text section */
21522 + BYTE(0)
21523 + _etext = . - __KERNEL_TEXT_OFFSET;
21524 + }
21525 +
21526 +#ifdef CONFIG_X86_32
21527 + . = ALIGN(PAGE_SIZE);
21528 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
21529 + *(.idt)
21530 + . = ALIGN(PAGE_SIZE);
21531 + *(.empty_zero_page)
21532 + *(.initial_pg_fixmap)
21533 + *(.initial_pg_pmd)
21534 + *(.initial_page_table)
21535 + *(.swapper_pg_dir)
21536 + } :rodata
21537 +#endif
21538 +
21539 + . = ALIGN(PAGE_SIZE);
21540 + NOTES :rodata :note
21541 +
21542 + EXCEPTION_TABLE(16) :rodata
21543
21544 #if defined(CONFIG_DEBUG_RODATA)
21545 /* .text should occupy whole number of pages */
21546 @@ -126,16 +181,20 @@ SECTIONS
21547
21548 /* Data */
21549 .data : AT(ADDR(.data) - LOAD_OFFSET) {
21550 +
21551 +#ifdef CONFIG_PAX_KERNEXEC
21552 + . = ALIGN(HPAGE_SIZE);
21553 +#else
21554 + . = ALIGN(PAGE_SIZE);
21555 +#endif
21556 +
21557 /* Start of data section */
21558 _sdata = .;
21559
21560 /* init_task */
21561 INIT_TASK_DATA(THREAD_SIZE)
21562
21563 -#ifdef CONFIG_X86_32
21564 - /* 32 bit has nosave before _edata */
21565 NOSAVE_DATA
21566 -#endif
21567
21568 PAGE_ALIGNED_DATA(PAGE_SIZE)
21569
21570 @@ -176,12 +235,19 @@ SECTIONS
21571 #endif /* CONFIG_X86_64 */
21572
21573 /* Init code and data - will be freed after init */
21574 - . = ALIGN(PAGE_SIZE);
21575 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
21576 + BYTE(0)
21577 +
21578 +#ifdef CONFIG_PAX_KERNEXEC
21579 + . = ALIGN(HPAGE_SIZE);
21580 +#else
21581 + . = ALIGN(PAGE_SIZE);
21582 +#endif
21583 +
21584 __init_begin = .; /* paired with __init_end */
21585 - }
21586 + } :init.begin
21587
21588 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
21589 +#ifdef CONFIG_SMP
21590 /*
21591 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
21592 * output PHDR, so the next output section - .init.text - should
21593 @@ -190,12 +256,27 @@ SECTIONS
21594 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
21595 #endif
21596
21597 - INIT_TEXT_SECTION(PAGE_SIZE)
21598 -#ifdef CONFIG_X86_64
21599 - :init
21600 -#endif
21601 + . = ALIGN(PAGE_SIZE);
21602 + init_begin = .;
21603 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
21604 + VMLINUX_SYMBOL(_sinittext) = .;
21605 + INIT_TEXT
21606 + VMLINUX_SYMBOL(_einittext) = .;
21607 + . = ALIGN(PAGE_SIZE);
21608 + } :text.init
21609
21610 - INIT_DATA_SECTION(16)
21611 + /*
21612 + * .exit.text is discard at runtime, not link time, to deal with
21613 + * references from .altinstructions and .eh_frame
21614 + */
21615 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
21616 + EXIT_TEXT
21617 + . = ALIGN(16);
21618 + } :text.exit
21619 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
21620 +
21621 + . = ALIGN(PAGE_SIZE);
21622 + INIT_DATA_SECTION(16) :init
21623
21624 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
21625 __x86_cpu_dev_start = .;
21626 @@ -257,19 +338,12 @@ SECTIONS
21627 }
21628
21629 . = ALIGN(8);
21630 - /*
21631 - * .exit.text is discard at runtime, not link time, to deal with
21632 - * references from .altinstructions and .eh_frame
21633 - */
21634 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
21635 - EXIT_TEXT
21636 - }
21637
21638 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
21639 EXIT_DATA
21640 }
21641
21642 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
21643 +#ifndef CONFIG_SMP
21644 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
21645 #endif
21646
21647 @@ -288,16 +362,10 @@ SECTIONS
21648 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
21649 __smp_locks = .;
21650 *(.smp_locks)
21651 - . = ALIGN(PAGE_SIZE);
21652 __smp_locks_end = .;
21653 + . = ALIGN(PAGE_SIZE);
21654 }
21655
21656 -#ifdef CONFIG_X86_64
21657 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
21658 - NOSAVE_DATA
21659 - }
21660 -#endif
21661 -
21662 /* BSS */
21663 . = ALIGN(PAGE_SIZE);
21664 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
21665 @@ -313,6 +381,7 @@ SECTIONS
21666 __brk_base = .;
21667 . += 64 * 1024; /* 64k alignment slop space */
21668 *(.brk_reservation) /* areas brk users have reserved */
21669 + . = ALIGN(HPAGE_SIZE);
21670 __brk_limit = .;
21671 }
21672
21673 @@ -339,13 +408,12 @@ SECTIONS
21674 * for the boot processor.
21675 */
21676 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
21677 -INIT_PER_CPU(gdt_page);
21678 INIT_PER_CPU(irq_stack_union);
21679
21680 /*
21681 * Build-time check on the image size:
21682 */
21683 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
21684 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
21685 "kernel image bigger than KERNEL_IMAGE_SIZE");
21686
21687 #ifdef CONFIG_SMP
21688 diff --git a/arch/x86/kernel/vsmp_64.c b/arch/x86/kernel/vsmp_64.c
21689 index 992f890..0ab1aae 100644
21690 --- a/arch/x86/kernel/vsmp_64.c
21691 +++ b/arch/x86/kernel/vsmp_64.c
21692 @@ -114,7 +114,7 @@ static void __init set_vsmp_pv_ops(void)
21693 pv_irq_ops.irq_enable = PV_CALLEE_SAVE(vsmp_irq_enable);
21694 pv_irq_ops.save_fl = PV_CALLEE_SAVE(vsmp_save_fl);
21695 pv_irq_ops.restore_fl = PV_CALLEE_SAVE(vsmp_restore_fl);
21696 - pv_init_ops.patch = vsmp_patch;
21697 + *(void **)&pv_init_ops.patch = vsmp_patch;
21698 ctl &= ~(1 << 4);
21699 }
21700 writel(ctl, address + 4);
21701 @@ -217,8 +217,8 @@ static void fill_vector_allocation_domain(int cpu, struct cpumask *retmask,
21702 static void vsmp_apic_post_init(void)
21703 {
21704 /* need to update phys_pkg_id */
21705 - apic->phys_pkg_id = apicid_phys_pkg_id;
21706 - apic->vector_allocation_domain = fill_vector_allocation_domain;
21707 + *(void **)&apic->phys_pkg_id = apicid_phys_pkg_id;
21708 + *(void **)&apic->vector_allocation_domain = fill_vector_allocation_domain;
21709 }
21710
21711 void __init vsmp_init(void)
21712 @@ -227,7 +227,7 @@ void __init vsmp_init(void)
21713 if (!is_vsmp_box())
21714 return;
21715
21716 - x86_platform.apic_post_init = vsmp_apic_post_init;
21717 + *(void **)&x86_platform.apic_post_init = vsmp_apic_post_init;
21718
21719 vsmp_cap_cpus();
21720
21721 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
21722 index 3a3e8c9..1af9465 100644
21723 --- a/arch/x86/kernel/vsyscall_64.c
21724 +++ b/arch/x86/kernel/vsyscall_64.c
21725 @@ -56,15 +56,13 @@
21726 DEFINE_VVAR(int, vgetcpu_mode);
21727 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
21728
21729 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
21730 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
21731
21732 static int __init vsyscall_setup(char *str)
21733 {
21734 if (str) {
21735 if (!strcmp("emulate", str))
21736 vsyscall_mode = EMULATE;
21737 - else if (!strcmp("native", str))
21738 - vsyscall_mode = NATIVE;
21739 else if (!strcmp("none", str))
21740 vsyscall_mode = NONE;
21741 else
21742 @@ -315,8 +313,7 @@ done:
21743 return true;
21744
21745 sigsegv:
21746 - force_sig(SIGSEGV, current);
21747 - return true;
21748 + do_group_exit(SIGKILL);
21749 }
21750
21751 /*
21752 @@ -369,10 +366,7 @@ void __init map_vsyscall(void)
21753 extern char __vvar_page;
21754 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
21755
21756 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
21757 - vsyscall_mode == NATIVE
21758 - ? PAGE_KERNEL_VSYSCALL
21759 - : PAGE_KERNEL_VVAR);
21760 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
21761 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
21762 (unsigned long)VSYSCALL_START);
21763
21764 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
21765 index 1330dd1..d220b99 100644
21766 --- a/arch/x86/kernel/x8664_ksyms_64.c
21767 +++ b/arch/x86/kernel/x8664_ksyms_64.c
21768 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
21769 EXPORT_SYMBOL(copy_user_generic_unrolled);
21770 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
21771 EXPORT_SYMBOL(__copy_user_nocache);
21772 -EXPORT_SYMBOL(_copy_from_user);
21773 -EXPORT_SYMBOL(_copy_to_user);
21774
21775 EXPORT_SYMBOL(copy_page);
21776 EXPORT_SYMBOL(clear_page);
21777 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
21778 index ada87a3..afea76d 100644
21779 --- a/arch/x86/kernel/xsave.c
21780 +++ b/arch/x86/kernel/xsave.c
21781 @@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
21782 {
21783 int err;
21784
21785 + buf = (struct xsave_struct __user *)____m(buf);
21786 if (use_xsave())
21787 err = xsave_user(buf);
21788 else if (use_fxsr())
21789 @@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
21790 */
21791 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
21792 {
21793 + buf = (void __user *)____m(buf);
21794 if (use_xsave()) {
21795 if ((unsigned long)buf % 64 || fx_only) {
21796 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
21797 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
21798 index ec79e77..420f5cc 100644
21799 --- a/arch/x86/kvm/cpuid.c
21800 +++ b/arch/x86/kvm/cpuid.c
21801 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
21802 struct kvm_cpuid2 *cpuid,
21803 struct kvm_cpuid_entry2 __user *entries)
21804 {
21805 - int r;
21806 + int r, i;
21807
21808 r = -E2BIG;
21809 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
21810 goto out;
21811 r = -EFAULT;
21812 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
21813 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
21814 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
21815 goto out;
21816 + for (i = 0; i < cpuid->nent; ++i) {
21817 + struct kvm_cpuid_entry2 cpuid_entry;
21818 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
21819 + goto out;
21820 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
21821 + }
21822 vcpu->arch.cpuid_nent = cpuid->nent;
21823 kvm_apic_set_version(vcpu);
21824 kvm_x86_ops->cpuid_update(vcpu);
21825 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
21826 struct kvm_cpuid2 *cpuid,
21827 struct kvm_cpuid_entry2 __user *entries)
21828 {
21829 - int r;
21830 + int r, i;
21831
21832 r = -E2BIG;
21833 if (cpuid->nent < vcpu->arch.cpuid_nent)
21834 goto out;
21835 r = -EFAULT;
21836 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
21837 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
21838 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
21839 goto out;
21840 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
21841 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
21842 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
21843 + goto out;
21844 + }
21845 return 0;
21846
21847 out:
21848 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
21849 index bba39bf..296540a 100644
21850 --- a/arch/x86/kvm/emulate.c
21851 +++ b/arch/x86/kvm/emulate.c
21852 @@ -292,6 +292,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
21853
21854 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
21855 do { \
21856 + unsigned long _tmp; \
21857 __asm__ __volatile__ ( \
21858 _PRE_EFLAGS("0", "4", "2") \
21859 _op _suffix " %"_x"3,%1; " \
21860 @@ -306,8 +307,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
21861 /* Raw emulation: instruction has two explicit operands. */
21862 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
21863 do { \
21864 - unsigned long _tmp; \
21865 - \
21866 switch ((ctxt)->dst.bytes) { \
21867 case 2: \
21868 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
21869 @@ -323,7 +322,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
21870
21871 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
21872 do { \
21873 - unsigned long _tmp; \
21874 switch ((ctxt)->dst.bytes) { \
21875 case 1: \
21876 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
21877 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
21878 index 43e9fad..3b7c059 100644
21879 --- a/arch/x86/kvm/lapic.c
21880 +++ b/arch/x86/kvm/lapic.c
21881 @@ -55,7 +55,7 @@
21882 #define APIC_BUS_CYCLE_NS 1
21883
21884 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
21885 -#define apic_debug(fmt, arg...)
21886 +#define apic_debug(fmt, arg...) do {} while (0)
21887
21888 #define APIC_LVT_NUM 6
21889 /* 14 is the version for Xeon and Pentium 8.4.8*/
21890 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
21891 index 714e2c0..3f7a086 100644
21892 --- a/arch/x86/kvm/paging_tmpl.h
21893 +++ b/arch/x86/kvm/paging_tmpl.h
21894 @@ -208,7 +208,7 @@ retry_walk:
21895 if (unlikely(kvm_is_error_hva(host_addr)))
21896 goto error;
21897
21898 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
21899 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
21900 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
21901 goto error;
21902 walker->ptep_user[walker->level - 1] = ptep_user;
21903 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
21904 index d017df3..61ae42e 100644
21905 --- a/arch/x86/kvm/svm.c
21906 +++ b/arch/x86/kvm/svm.c
21907 @@ -3500,7 +3500,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
21908 int cpu = raw_smp_processor_id();
21909
21910 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
21911 +
21912 + pax_open_kernel();
21913 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
21914 + pax_close_kernel();
21915 +
21916 load_TR_desc();
21917 }
21918
21919 @@ -3874,6 +3878,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
21920 #endif
21921 #endif
21922
21923 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21924 + __set_fs(current_thread_info()->addr_limit);
21925 +#endif
21926 +
21927 reload_tss(vcpu);
21928
21929 local_irq_disable();
21930 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
21931 index f858159..4ab7dba 100644
21932 --- a/arch/x86/kvm/vmx.c
21933 +++ b/arch/x86/kvm/vmx.c
21934 @@ -1332,7 +1332,11 @@ static void reload_tss(void)
21935 struct desc_struct *descs;
21936
21937 descs = (void *)gdt->address;
21938 +
21939 + pax_open_kernel();
21940 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
21941 + pax_close_kernel();
21942 +
21943 load_TR_desc();
21944 }
21945
21946 @@ -1546,6 +1550,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
21947 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
21948 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
21949
21950 +#ifdef CONFIG_PAX_PER_CPU_PGD
21951 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
21952 +#endif
21953 +
21954 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
21955 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
21956 vmx->loaded_vmcs->cpu = cpu;
21957 @@ -2669,8 +2677,11 @@ static __init int hardware_setup(void)
21958 if (!cpu_has_vmx_flexpriority())
21959 flexpriority_enabled = 0;
21960
21961 - if (!cpu_has_vmx_tpr_shadow())
21962 - kvm_x86_ops->update_cr8_intercept = NULL;
21963 + if (!cpu_has_vmx_tpr_shadow()) {
21964 + pax_open_kernel();
21965 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
21966 + pax_close_kernel();
21967 + }
21968
21969 if (enable_ept && !cpu_has_vmx_ept_2m_page())
21970 kvm_disable_largepages();
21971 @@ -3712,7 +3723,10 @@ static void vmx_set_constant_host_state(void)
21972
21973 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
21974 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
21975 +
21976 +#ifndef CONFIG_PAX_PER_CPU_PGD
21977 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
21978 +#endif
21979
21980 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
21981 #ifdef CONFIG_X86_64
21982 @@ -3733,7 +3747,7 @@ static void vmx_set_constant_host_state(void)
21983 native_store_idt(&dt);
21984 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
21985
21986 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
21987 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
21988
21989 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
21990 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
21991 @@ -6279,6 +6293,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
21992 "jmp 2f \n\t"
21993 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
21994 "2: "
21995 +
21996 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21997 + "ljmp %[cs],$3f\n\t"
21998 + "3: "
21999 +#endif
22000 +
22001 /* Save guest registers, load host registers, keep flags */
22002 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
22003 "pop %0 \n\t"
22004 @@ -6331,6 +6351,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
22005 #endif
22006 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
22007 [wordsize]"i"(sizeof(ulong))
22008 +
22009 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22010 + ,[cs]"i"(__KERNEL_CS)
22011 +#endif
22012 +
22013 : "cc", "memory"
22014 #ifdef CONFIG_X86_64
22015 , "rax", "rbx", "rdi", "rsi"
22016 @@ -6344,7 +6369,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
22017 if (debugctlmsr)
22018 update_debugctlmsr(debugctlmsr);
22019
22020 -#ifndef CONFIG_X86_64
22021 +#ifdef CONFIG_X86_32
22022 /*
22023 * The sysexit path does not restore ds/es, so we must set them to
22024 * a reasonable value ourselves.
22025 @@ -6353,8 +6378,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
22026 * may be executed in interrupt context, which saves and restore segments
22027 * around it, nullifying its effect.
22028 */
22029 - loadsegment(ds, __USER_DS);
22030 - loadsegment(es, __USER_DS);
22031 + loadsegment(ds, __KERNEL_DS);
22032 + loadsegment(es, __KERNEL_DS);
22033 + loadsegment(ss, __KERNEL_DS);
22034 +
22035 +#ifdef CONFIG_PAX_KERNEXEC
22036 + loadsegment(fs, __KERNEL_PERCPU);
22037 +#endif
22038 +
22039 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22040 + __set_fs(current_thread_info()->addr_limit);
22041 +#endif
22042 +
22043 #endif
22044
22045 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
22046 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
22047 index 4f76417..93429b5 100644
22048 --- a/arch/x86/kvm/x86.c
22049 +++ b/arch/x86/kvm/x86.c
22050 @@ -1390,8 +1390,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
22051 {
22052 struct kvm *kvm = vcpu->kvm;
22053 int lm = is_long_mode(vcpu);
22054 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
22055 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
22056 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
22057 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
22058 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
22059 : kvm->arch.xen_hvm_config.blob_size_32;
22060 u32 page_num = data & ~PAGE_MASK;
22061 @@ -2255,6 +2255,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
22062 if (n < msr_list.nmsrs)
22063 goto out;
22064 r = -EFAULT;
22065 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
22066 + goto out;
22067 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
22068 num_msrs_to_save * sizeof(u32)))
22069 goto out;
22070 @@ -2379,7 +2381,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
22071 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
22072 struct kvm_interrupt *irq)
22073 {
22074 - if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
22075 + if (irq->irq >= KVM_NR_INTERRUPTS)
22076 return -EINVAL;
22077 if (irqchip_in_kernel(vcpu->kvm))
22078 return -ENXIO;
22079 @@ -4881,7 +4883,7 @@ static void kvm_set_mmio_spte_mask(void)
22080 kvm_mmu_set_mmio_spte_mask(mask);
22081 }
22082
22083 -int kvm_arch_init(void *opaque)
22084 +int kvm_arch_init(const void *opaque)
22085 {
22086 int r;
22087 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
22088 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
22089 index 642d880..5dd034e 100644
22090 --- a/arch/x86/lguest/boot.c
22091 +++ b/arch/x86/lguest/boot.c
22092 @@ -1116,12 +1116,12 @@ static u32 lguest_apic_safe_wait_icr_idle(void)
22093
22094 static void set_lguest_basic_apic_ops(void)
22095 {
22096 - apic->read = lguest_apic_read;
22097 - apic->write = lguest_apic_write;
22098 - apic->icr_read = lguest_apic_icr_read;
22099 - apic->icr_write = lguest_apic_icr_write;
22100 - apic->wait_icr_idle = lguest_apic_wait_icr_idle;
22101 - apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
22102 + *(void **)&apic->read = lguest_apic_read;
22103 + *(void **)&apic->write = lguest_apic_write;
22104 + *(void **)&apic->icr_read = lguest_apic_icr_read;
22105 + *(void **)&apic->icr_write = lguest_apic_icr_write;
22106 + *(void **)&apic->wait_icr_idle = lguest_apic_wait_icr_idle;
22107 + *(void **)&apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
22108 };
22109 #endif
22110
22111 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
22112 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
22113 * Launcher to reboot us.
22114 */
22115 -static void lguest_restart(char *reason)
22116 +static __noreturn void lguest_restart(char *reason)
22117 {
22118 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
22119 + BUG();
22120 }
22121
22122 /*G:050
22123 @@ -1292,28 +1293,28 @@ __init void lguest_init(void)
22124 pv_irq_ops.safe_halt = lguest_safe_halt;
22125
22126 /* Setup operations */
22127 - pv_init_ops.patch = lguest_patch;
22128 + *(void **)&pv_init_ops.patch = lguest_patch;
22129
22130 /* Intercepts of various CPU instructions */
22131 - pv_cpu_ops.load_gdt = lguest_load_gdt;
22132 - pv_cpu_ops.cpuid = lguest_cpuid;
22133 - pv_cpu_ops.load_idt = lguest_load_idt;
22134 - pv_cpu_ops.iret = lguest_iret;
22135 - pv_cpu_ops.load_sp0 = lguest_load_sp0;
22136 - pv_cpu_ops.load_tr_desc = lguest_load_tr_desc;
22137 - pv_cpu_ops.set_ldt = lguest_set_ldt;
22138 - pv_cpu_ops.load_tls = lguest_load_tls;
22139 - pv_cpu_ops.set_debugreg = lguest_set_debugreg;
22140 - pv_cpu_ops.clts = lguest_clts;
22141 - pv_cpu_ops.read_cr0 = lguest_read_cr0;
22142 - pv_cpu_ops.write_cr0 = lguest_write_cr0;
22143 - pv_cpu_ops.read_cr4 = lguest_read_cr4;
22144 - pv_cpu_ops.write_cr4 = lguest_write_cr4;
22145 - pv_cpu_ops.write_gdt_entry = lguest_write_gdt_entry;
22146 - pv_cpu_ops.write_idt_entry = lguest_write_idt_entry;
22147 - pv_cpu_ops.wbinvd = lguest_wbinvd;
22148 - pv_cpu_ops.start_context_switch = paravirt_start_context_switch;
22149 - pv_cpu_ops.end_context_switch = lguest_end_context_switch;
22150 + *(void **)&pv_cpu_ops.load_gdt = lguest_load_gdt;
22151 + *(void **)&pv_cpu_ops.cpuid = lguest_cpuid;
22152 + *(void **)&pv_cpu_ops.load_idt = lguest_load_idt;
22153 + *(void **)&pv_cpu_ops.iret = lguest_iret;
22154 + *(void **)&pv_cpu_ops.load_sp0 = lguest_load_sp0;
22155 + *(void **)&pv_cpu_ops.load_tr_desc = lguest_load_tr_desc;
22156 + *(void **)&pv_cpu_ops.set_ldt = lguest_set_ldt;
22157 + *(void **)&pv_cpu_ops.load_tls = lguest_load_tls;
22158 + *(void **)&pv_cpu_ops.set_debugreg = lguest_set_debugreg;
22159 + *(void **)&pv_cpu_ops.clts = lguest_clts;
22160 + *(void **)&pv_cpu_ops.read_cr0 = lguest_read_cr0;
22161 + *(void **)&pv_cpu_ops.write_cr0 = lguest_write_cr0;
22162 + *(void **)&pv_cpu_ops.read_cr4 = lguest_read_cr4;
22163 + *(void **)&pv_cpu_ops.write_cr4 = lguest_write_cr4;
22164 + *(void **)&pv_cpu_ops.write_gdt_entry = lguest_write_gdt_entry;
22165 + *(void **)&pv_cpu_ops.write_idt_entry = lguest_write_idt_entry;
22166 + *(void **)&pv_cpu_ops.wbinvd = lguest_wbinvd;
22167 + *(void **)&pv_cpu_ops.start_context_switch = paravirt_start_context_switch;
22168 + *(void **)&pv_cpu_ops.end_context_switch = lguest_end_context_switch;
22169
22170 /* Pagetable management */
22171 pv_mmu_ops.write_cr3 = lguest_write_cr3;
22172 @@ -1341,11 +1342,11 @@ __init void lguest_init(void)
22173 set_lguest_basic_apic_ops();
22174 #endif
22175
22176 - x86_init.resources.memory_setup = lguest_memory_setup;
22177 - x86_init.irqs.intr_init = lguest_init_IRQ;
22178 - x86_init.timers.timer_init = lguest_time_init;
22179 - x86_platform.calibrate_tsc = lguest_tsc_khz;
22180 - x86_platform.get_wallclock = lguest_get_wallclock;
22181 + *(void **)&x86_init.resources.memory_setup = lguest_memory_setup;
22182 + *(void **)&x86_init.irqs.intr_init = lguest_init_IRQ;
22183 + *(void **)&x86_init.timers.timer_init = lguest_time_init;
22184 + *(void **)&x86_platform.calibrate_tsc = lguest_tsc_khz;
22185 + *(void **)&x86_platform.get_wallclock = lguest_get_wallclock;
22186
22187 /*
22188 * Now is a good time to look at the implementations of these functions
22189 @@ -1434,7 +1435,7 @@ __init void lguest_init(void)
22190 * routine.
22191 */
22192 pm_power_off = lguest_power_off;
22193 - machine_ops.restart = lguest_restart;
22194 + *(void **)&machine_ops.restart = lguest_restart;
22195
22196 /*
22197 * Now we're set up, call i386_start_kernel() in head32.c and we proceed
22198 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
22199 index 00933d5..3a64af9 100644
22200 --- a/arch/x86/lib/atomic64_386_32.S
22201 +++ b/arch/x86/lib/atomic64_386_32.S
22202 @@ -48,6 +48,10 @@ BEGIN(read)
22203 movl (v), %eax
22204 movl 4(v), %edx
22205 RET_ENDP
22206 +BEGIN(read_unchecked)
22207 + movl (v), %eax
22208 + movl 4(v), %edx
22209 +RET_ENDP
22210 #undef v
22211
22212 #define v %esi
22213 @@ -55,6 +59,10 @@ BEGIN(set)
22214 movl %ebx, (v)
22215 movl %ecx, 4(v)
22216 RET_ENDP
22217 +BEGIN(set_unchecked)
22218 + movl %ebx, (v)
22219 + movl %ecx, 4(v)
22220 +RET_ENDP
22221 #undef v
22222
22223 #define v %esi
22224 @@ -70,6 +78,20 @@ RET_ENDP
22225 BEGIN(add)
22226 addl %eax, (v)
22227 adcl %edx, 4(v)
22228 +
22229 +#ifdef CONFIG_PAX_REFCOUNT
22230 + jno 0f
22231 + subl %eax, (v)
22232 + sbbl %edx, 4(v)
22233 + int $4
22234 +0:
22235 + _ASM_EXTABLE(0b, 0b)
22236 +#endif
22237 +
22238 +RET_ENDP
22239 +BEGIN(add_unchecked)
22240 + addl %eax, (v)
22241 + adcl %edx, 4(v)
22242 RET_ENDP
22243 #undef v
22244
22245 @@ -77,6 +99,24 @@ RET_ENDP
22246 BEGIN(add_return)
22247 addl (v), %eax
22248 adcl 4(v), %edx
22249 +
22250 +#ifdef CONFIG_PAX_REFCOUNT
22251 + into
22252 +1234:
22253 + _ASM_EXTABLE(1234b, 2f)
22254 +#endif
22255 +
22256 + movl %eax, (v)
22257 + movl %edx, 4(v)
22258 +
22259 +#ifdef CONFIG_PAX_REFCOUNT
22260 +2:
22261 +#endif
22262 +
22263 +RET_ENDP
22264 +BEGIN(add_return_unchecked)
22265 + addl (v), %eax
22266 + adcl 4(v), %edx
22267 movl %eax, (v)
22268 movl %edx, 4(v)
22269 RET_ENDP
22270 @@ -86,6 +126,20 @@ RET_ENDP
22271 BEGIN(sub)
22272 subl %eax, (v)
22273 sbbl %edx, 4(v)
22274 +
22275 +#ifdef CONFIG_PAX_REFCOUNT
22276 + jno 0f
22277 + addl %eax, (v)
22278 + adcl %edx, 4(v)
22279 + int $4
22280 +0:
22281 + _ASM_EXTABLE(0b, 0b)
22282 +#endif
22283 +
22284 +RET_ENDP
22285 +BEGIN(sub_unchecked)
22286 + subl %eax, (v)
22287 + sbbl %edx, 4(v)
22288 RET_ENDP
22289 #undef v
22290
22291 @@ -96,6 +150,27 @@ BEGIN(sub_return)
22292 sbbl $0, %edx
22293 addl (v), %eax
22294 adcl 4(v), %edx
22295 +
22296 +#ifdef CONFIG_PAX_REFCOUNT
22297 + into
22298 +1234:
22299 + _ASM_EXTABLE(1234b, 2f)
22300 +#endif
22301 +
22302 + movl %eax, (v)
22303 + movl %edx, 4(v)
22304 +
22305 +#ifdef CONFIG_PAX_REFCOUNT
22306 +2:
22307 +#endif
22308 +
22309 +RET_ENDP
22310 +BEGIN(sub_return_unchecked)
22311 + negl %edx
22312 + negl %eax
22313 + sbbl $0, %edx
22314 + addl (v), %eax
22315 + adcl 4(v), %edx
22316 movl %eax, (v)
22317 movl %edx, 4(v)
22318 RET_ENDP
22319 @@ -105,6 +180,20 @@ RET_ENDP
22320 BEGIN(inc)
22321 addl $1, (v)
22322 adcl $0, 4(v)
22323 +
22324 +#ifdef CONFIG_PAX_REFCOUNT
22325 + jno 0f
22326 + subl $1, (v)
22327 + sbbl $0, 4(v)
22328 + int $4
22329 +0:
22330 + _ASM_EXTABLE(0b, 0b)
22331 +#endif
22332 +
22333 +RET_ENDP
22334 +BEGIN(inc_unchecked)
22335 + addl $1, (v)
22336 + adcl $0, 4(v)
22337 RET_ENDP
22338 #undef v
22339
22340 @@ -114,6 +203,26 @@ BEGIN(inc_return)
22341 movl 4(v), %edx
22342 addl $1, %eax
22343 adcl $0, %edx
22344 +
22345 +#ifdef CONFIG_PAX_REFCOUNT
22346 + into
22347 +1234:
22348 + _ASM_EXTABLE(1234b, 2f)
22349 +#endif
22350 +
22351 + movl %eax, (v)
22352 + movl %edx, 4(v)
22353 +
22354 +#ifdef CONFIG_PAX_REFCOUNT
22355 +2:
22356 +#endif
22357 +
22358 +RET_ENDP
22359 +BEGIN(inc_return_unchecked)
22360 + movl (v), %eax
22361 + movl 4(v), %edx
22362 + addl $1, %eax
22363 + adcl $0, %edx
22364 movl %eax, (v)
22365 movl %edx, 4(v)
22366 RET_ENDP
22367 @@ -123,6 +232,20 @@ RET_ENDP
22368 BEGIN(dec)
22369 subl $1, (v)
22370 sbbl $0, 4(v)
22371 +
22372 +#ifdef CONFIG_PAX_REFCOUNT
22373 + jno 0f
22374 + addl $1, (v)
22375 + adcl $0, 4(v)
22376 + int $4
22377 +0:
22378 + _ASM_EXTABLE(0b, 0b)
22379 +#endif
22380 +
22381 +RET_ENDP
22382 +BEGIN(dec_unchecked)
22383 + subl $1, (v)
22384 + sbbl $0, 4(v)
22385 RET_ENDP
22386 #undef v
22387
22388 @@ -132,6 +255,26 @@ BEGIN(dec_return)
22389 movl 4(v), %edx
22390 subl $1, %eax
22391 sbbl $0, %edx
22392 +
22393 +#ifdef CONFIG_PAX_REFCOUNT
22394 + into
22395 +1234:
22396 + _ASM_EXTABLE(1234b, 2f)
22397 +#endif
22398 +
22399 + movl %eax, (v)
22400 + movl %edx, 4(v)
22401 +
22402 +#ifdef CONFIG_PAX_REFCOUNT
22403 +2:
22404 +#endif
22405 +
22406 +RET_ENDP
22407 +BEGIN(dec_return_unchecked)
22408 + movl (v), %eax
22409 + movl 4(v), %edx
22410 + subl $1, %eax
22411 + sbbl $0, %edx
22412 movl %eax, (v)
22413 movl %edx, 4(v)
22414 RET_ENDP
22415 @@ -143,6 +286,13 @@ BEGIN(add_unless)
22416 adcl %edx, %edi
22417 addl (v), %eax
22418 adcl 4(v), %edx
22419 +
22420 +#ifdef CONFIG_PAX_REFCOUNT
22421 + into
22422 +1234:
22423 + _ASM_EXTABLE(1234b, 2f)
22424 +#endif
22425 +
22426 cmpl %eax, %ecx
22427 je 3f
22428 1:
22429 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
22430 1:
22431 addl $1, %eax
22432 adcl $0, %edx
22433 +
22434 +#ifdef CONFIG_PAX_REFCOUNT
22435 + into
22436 +1234:
22437 + _ASM_EXTABLE(1234b, 2f)
22438 +#endif
22439 +
22440 movl %eax, (v)
22441 movl %edx, 4(v)
22442 movl $1, %eax
22443 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
22444 movl 4(v), %edx
22445 subl $1, %eax
22446 sbbl $0, %edx
22447 +
22448 +#ifdef CONFIG_PAX_REFCOUNT
22449 + into
22450 +1234:
22451 + _ASM_EXTABLE(1234b, 1f)
22452 +#endif
22453 +
22454 js 1f
22455 movl %eax, (v)
22456 movl %edx, 4(v)
22457 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
22458 index f5cc9eb..51fa319 100644
22459 --- a/arch/x86/lib/atomic64_cx8_32.S
22460 +++ b/arch/x86/lib/atomic64_cx8_32.S
22461 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
22462 CFI_STARTPROC
22463
22464 read64 %ecx
22465 + pax_force_retaddr
22466 ret
22467 CFI_ENDPROC
22468 ENDPROC(atomic64_read_cx8)
22469
22470 +ENTRY(atomic64_read_unchecked_cx8)
22471 + CFI_STARTPROC
22472 +
22473 + read64 %ecx
22474 + pax_force_retaddr
22475 + ret
22476 + CFI_ENDPROC
22477 +ENDPROC(atomic64_read_unchecked_cx8)
22478 +
22479 ENTRY(atomic64_set_cx8)
22480 CFI_STARTPROC
22481
22482 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
22483 cmpxchg8b (%esi)
22484 jne 1b
22485
22486 + pax_force_retaddr
22487 ret
22488 CFI_ENDPROC
22489 ENDPROC(atomic64_set_cx8)
22490
22491 +ENTRY(atomic64_set_unchecked_cx8)
22492 + CFI_STARTPROC
22493 +
22494 +1:
22495 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
22496 + * are atomic on 586 and newer */
22497 + cmpxchg8b (%esi)
22498 + jne 1b
22499 +
22500 + pax_force_retaddr
22501 + ret
22502 + CFI_ENDPROC
22503 +ENDPROC(atomic64_set_unchecked_cx8)
22504 +
22505 ENTRY(atomic64_xchg_cx8)
22506 CFI_STARTPROC
22507
22508 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
22509 cmpxchg8b (%esi)
22510 jne 1b
22511
22512 + pax_force_retaddr
22513 ret
22514 CFI_ENDPROC
22515 ENDPROC(atomic64_xchg_cx8)
22516
22517 -.macro addsub_return func ins insc
22518 -ENTRY(atomic64_\func\()_return_cx8)
22519 +.macro addsub_return func ins insc unchecked=""
22520 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
22521 CFI_STARTPROC
22522 SAVE ebp
22523 SAVE ebx
22524 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
22525 movl %edx, %ecx
22526 \ins\()l %esi, %ebx
22527 \insc\()l %edi, %ecx
22528 +
22529 +.ifb \unchecked
22530 +#ifdef CONFIG_PAX_REFCOUNT
22531 + into
22532 +2:
22533 + _ASM_EXTABLE(2b, 3f)
22534 +#endif
22535 +.endif
22536 +
22537 LOCK_PREFIX
22538 cmpxchg8b (%ebp)
22539 jne 1b
22540 -
22541 -10:
22542 movl %ebx, %eax
22543 movl %ecx, %edx
22544 +
22545 +.ifb \unchecked
22546 +#ifdef CONFIG_PAX_REFCOUNT
22547 +3:
22548 +#endif
22549 +.endif
22550 +
22551 RESTORE edi
22552 RESTORE esi
22553 RESTORE ebx
22554 RESTORE ebp
22555 + pax_force_retaddr
22556 ret
22557 CFI_ENDPROC
22558 -ENDPROC(atomic64_\func\()_return_cx8)
22559 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
22560 .endm
22561
22562 addsub_return add add adc
22563 addsub_return sub sub sbb
22564 +addsub_return add add adc _unchecked
22565 +addsub_return sub sub sbb _unchecked
22566
22567 -.macro incdec_return func ins insc
22568 -ENTRY(atomic64_\func\()_return_cx8)
22569 +.macro incdec_return func ins insc unchecked=""
22570 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
22571 CFI_STARTPROC
22572 SAVE ebx
22573
22574 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
22575 movl %edx, %ecx
22576 \ins\()l $1, %ebx
22577 \insc\()l $0, %ecx
22578 +
22579 +.ifb \unchecked
22580 +#ifdef CONFIG_PAX_REFCOUNT
22581 + into
22582 +2:
22583 + _ASM_EXTABLE(2b, 3f)
22584 +#endif
22585 +.endif
22586 +
22587 LOCK_PREFIX
22588 cmpxchg8b (%esi)
22589 jne 1b
22590
22591 -10:
22592 movl %ebx, %eax
22593 movl %ecx, %edx
22594 +
22595 +.ifb \unchecked
22596 +#ifdef CONFIG_PAX_REFCOUNT
22597 +3:
22598 +#endif
22599 +.endif
22600 +
22601 RESTORE ebx
22602 + pax_force_retaddr
22603 ret
22604 CFI_ENDPROC
22605 -ENDPROC(atomic64_\func\()_return_cx8)
22606 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
22607 .endm
22608
22609 incdec_return inc add adc
22610 incdec_return dec sub sbb
22611 +incdec_return inc add adc _unchecked
22612 +incdec_return dec sub sbb _unchecked
22613
22614 ENTRY(atomic64_dec_if_positive_cx8)
22615 CFI_STARTPROC
22616 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
22617 movl %edx, %ecx
22618 subl $1, %ebx
22619 sbb $0, %ecx
22620 +
22621 +#ifdef CONFIG_PAX_REFCOUNT
22622 + into
22623 +1234:
22624 + _ASM_EXTABLE(1234b, 2f)
22625 +#endif
22626 +
22627 js 2f
22628 LOCK_PREFIX
22629 cmpxchg8b (%esi)
22630 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
22631 movl %ebx, %eax
22632 movl %ecx, %edx
22633 RESTORE ebx
22634 + pax_force_retaddr
22635 ret
22636 CFI_ENDPROC
22637 ENDPROC(atomic64_dec_if_positive_cx8)
22638 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
22639 movl %edx, %ecx
22640 addl %ebp, %ebx
22641 adcl %edi, %ecx
22642 +
22643 +#ifdef CONFIG_PAX_REFCOUNT
22644 + into
22645 +1234:
22646 + _ASM_EXTABLE(1234b, 3f)
22647 +#endif
22648 +
22649 LOCK_PREFIX
22650 cmpxchg8b (%esi)
22651 jne 1b
22652 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
22653 CFI_ADJUST_CFA_OFFSET -8
22654 RESTORE ebx
22655 RESTORE ebp
22656 + pax_force_retaddr
22657 ret
22658 4:
22659 cmpl %edx, 4(%esp)
22660 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
22661 xorl %ecx, %ecx
22662 addl $1, %ebx
22663 adcl %edx, %ecx
22664 +
22665 +#ifdef CONFIG_PAX_REFCOUNT
22666 + into
22667 +1234:
22668 + _ASM_EXTABLE(1234b, 3f)
22669 +#endif
22670 +
22671 LOCK_PREFIX
22672 cmpxchg8b (%esi)
22673 jne 1b
22674 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
22675 movl $1, %eax
22676 3:
22677 RESTORE ebx
22678 + pax_force_retaddr
22679 ret
22680 CFI_ENDPROC
22681 ENDPROC(atomic64_inc_not_zero_cx8)
22682 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
22683 index 2af5df3..62b1a5a 100644
22684 --- a/arch/x86/lib/checksum_32.S
22685 +++ b/arch/x86/lib/checksum_32.S
22686 @@ -29,7 +29,8 @@
22687 #include <asm/dwarf2.h>
22688 #include <asm/errno.h>
22689 #include <asm/asm.h>
22690 -
22691 +#include <asm/segment.h>
22692 +
22693 /*
22694 * computes a partial checksum, e.g. for TCP/UDP fragments
22695 */
22696 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
22697
22698 #define ARGBASE 16
22699 #define FP 12
22700 -
22701 -ENTRY(csum_partial_copy_generic)
22702 +
22703 +ENTRY(csum_partial_copy_generic_to_user)
22704 CFI_STARTPROC
22705 +
22706 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22707 + pushl_cfi %gs
22708 + popl_cfi %es
22709 + jmp csum_partial_copy_generic
22710 +#endif
22711 +
22712 +ENTRY(csum_partial_copy_generic_from_user)
22713 +
22714 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22715 + pushl_cfi %gs
22716 + popl_cfi %ds
22717 +#endif
22718 +
22719 +ENTRY(csum_partial_copy_generic)
22720 subl $4,%esp
22721 CFI_ADJUST_CFA_OFFSET 4
22722 pushl_cfi %edi
22723 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
22724 jmp 4f
22725 SRC(1: movw (%esi), %bx )
22726 addl $2, %esi
22727 -DST( movw %bx, (%edi) )
22728 +DST( movw %bx, %es:(%edi) )
22729 addl $2, %edi
22730 addw %bx, %ax
22731 adcl $0, %eax
22732 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
22733 SRC(1: movl (%esi), %ebx )
22734 SRC( movl 4(%esi), %edx )
22735 adcl %ebx, %eax
22736 -DST( movl %ebx, (%edi) )
22737 +DST( movl %ebx, %es:(%edi) )
22738 adcl %edx, %eax
22739 -DST( movl %edx, 4(%edi) )
22740 +DST( movl %edx, %es:4(%edi) )
22741
22742 SRC( movl 8(%esi), %ebx )
22743 SRC( movl 12(%esi), %edx )
22744 adcl %ebx, %eax
22745 -DST( movl %ebx, 8(%edi) )
22746 +DST( movl %ebx, %es:8(%edi) )
22747 adcl %edx, %eax
22748 -DST( movl %edx, 12(%edi) )
22749 +DST( movl %edx, %es:12(%edi) )
22750
22751 SRC( movl 16(%esi), %ebx )
22752 SRC( movl 20(%esi), %edx )
22753 adcl %ebx, %eax
22754 -DST( movl %ebx, 16(%edi) )
22755 +DST( movl %ebx, %es:16(%edi) )
22756 adcl %edx, %eax
22757 -DST( movl %edx, 20(%edi) )
22758 +DST( movl %edx, %es:20(%edi) )
22759
22760 SRC( movl 24(%esi), %ebx )
22761 SRC( movl 28(%esi), %edx )
22762 adcl %ebx, %eax
22763 -DST( movl %ebx, 24(%edi) )
22764 +DST( movl %ebx, %es:24(%edi) )
22765 adcl %edx, %eax
22766 -DST( movl %edx, 28(%edi) )
22767 +DST( movl %edx, %es:28(%edi) )
22768
22769 lea 32(%esi), %esi
22770 lea 32(%edi), %edi
22771 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
22772 shrl $2, %edx # This clears CF
22773 SRC(3: movl (%esi), %ebx )
22774 adcl %ebx, %eax
22775 -DST( movl %ebx, (%edi) )
22776 +DST( movl %ebx, %es:(%edi) )
22777 lea 4(%esi), %esi
22778 lea 4(%edi), %edi
22779 dec %edx
22780 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
22781 jb 5f
22782 SRC( movw (%esi), %cx )
22783 leal 2(%esi), %esi
22784 -DST( movw %cx, (%edi) )
22785 +DST( movw %cx, %es:(%edi) )
22786 leal 2(%edi), %edi
22787 je 6f
22788 shll $16,%ecx
22789 SRC(5: movb (%esi), %cl )
22790 -DST( movb %cl, (%edi) )
22791 +DST( movb %cl, %es:(%edi) )
22792 6: addl %ecx, %eax
22793 adcl $0, %eax
22794 7:
22795 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
22796
22797 6001:
22798 movl ARGBASE+20(%esp), %ebx # src_err_ptr
22799 - movl $-EFAULT, (%ebx)
22800 + movl $-EFAULT, %ss:(%ebx)
22801
22802 # zero the complete destination - computing the rest
22803 # is too much work
22804 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
22805
22806 6002:
22807 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
22808 - movl $-EFAULT,(%ebx)
22809 + movl $-EFAULT,%ss:(%ebx)
22810 jmp 5000b
22811
22812 .previous
22813
22814 + pushl_cfi %ss
22815 + popl_cfi %ds
22816 + pushl_cfi %ss
22817 + popl_cfi %es
22818 popl_cfi %ebx
22819 CFI_RESTORE ebx
22820 popl_cfi %esi
22821 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
22822 popl_cfi %ecx # equivalent to addl $4,%esp
22823 ret
22824 CFI_ENDPROC
22825 -ENDPROC(csum_partial_copy_generic)
22826 +ENDPROC(csum_partial_copy_generic_to_user)
22827
22828 #else
22829
22830 /* Version for PentiumII/PPro */
22831
22832 #define ROUND1(x) \
22833 + nop; nop; nop; \
22834 SRC(movl x(%esi), %ebx ) ; \
22835 addl %ebx, %eax ; \
22836 - DST(movl %ebx, x(%edi) ) ;
22837 + DST(movl %ebx, %es:x(%edi)) ;
22838
22839 #define ROUND(x) \
22840 + nop; nop; nop; \
22841 SRC(movl x(%esi), %ebx ) ; \
22842 adcl %ebx, %eax ; \
22843 - DST(movl %ebx, x(%edi) ) ;
22844 + DST(movl %ebx, %es:x(%edi)) ;
22845
22846 #define ARGBASE 12
22847 -
22848 -ENTRY(csum_partial_copy_generic)
22849 +
22850 +ENTRY(csum_partial_copy_generic_to_user)
22851 CFI_STARTPROC
22852 +
22853 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22854 + pushl_cfi %gs
22855 + popl_cfi %es
22856 + jmp csum_partial_copy_generic
22857 +#endif
22858 +
22859 +ENTRY(csum_partial_copy_generic_from_user)
22860 +
22861 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22862 + pushl_cfi %gs
22863 + popl_cfi %ds
22864 +#endif
22865 +
22866 +ENTRY(csum_partial_copy_generic)
22867 pushl_cfi %ebx
22868 CFI_REL_OFFSET ebx, 0
22869 pushl_cfi %edi
22870 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
22871 subl %ebx, %edi
22872 lea -1(%esi),%edx
22873 andl $-32,%edx
22874 - lea 3f(%ebx,%ebx), %ebx
22875 + lea 3f(%ebx,%ebx,2), %ebx
22876 testl %esi, %esi
22877 jmp *%ebx
22878 1: addl $64,%esi
22879 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
22880 jb 5f
22881 SRC( movw (%esi), %dx )
22882 leal 2(%esi), %esi
22883 -DST( movw %dx, (%edi) )
22884 +DST( movw %dx, %es:(%edi) )
22885 leal 2(%edi), %edi
22886 je 6f
22887 shll $16,%edx
22888 5:
22889 SRC( movb (%esi), %dl )
22890 -DST( movb %dl, (%edi) )
22891 +DST( movb %dl, %es:(%edi) )
22892 6: addl %edx, %eax
22893 adcl $0, %eax
22894 7:
22895 .section .fixup, "ax"
22896 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
22897 - movl $-EFAULT, (%ebx)
22898 + movl $-EFAULT, %ss:(%ebx)
22899 # zero the complete destination (computing the rest is too much work)
22900 movl ARGBASE+8(%esp),%edi # dst
22901 movl ARGBASE+12(%esp),%ecx # len
22902 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
22903 rep; stosb
22904 jmp 7b
22905 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
22906 - movl $-EFAULT, (%ebx)
22907 + movl $-EFAULT, %ss:(%ebx)
22908 jmp 7b
22909 .previous
22910
22911 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22912 + pushl_cfi %ss
22913 + popl_cfi %ds
22914 + pushl_cfi %ss
22915 + popl_cfi %es
22916 +#endif
22917 +
22918 popl_cfi %esi
22919 CFI_RESTORE esi
22920 popl_cfi %edi
22921 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
22922 CFI_RESTORE ebx
22923 ret
22924 CFI_ENDPROC
22925 -ENDPROC(csum_partial_copy_generic)
22926 +ENDPROC(csum_partial_copy_generic_to_user)
22927
22928 #undef ROUND
22929 #undef ROUND1
22930 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
22931 index f2145cf..cea889d 100644
22932 --- a/arch/x86/lib/clear_page_64.S
22933 +++ b/arch/x86/lib/clear_page_64.S
22934 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
22935 movl $4096/8,%ecx
22936 xorl %eax,%eax
22937 rep stosq
22938 + pax_force_retaddr
22939 ret
22940 CFI_ENDPROC
22941 ENDPROC(clear_page_c)
22942 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
22943 movl $4096,%ecx
22944 xorl %eax,%eax
22945 rep stosb
22946 + pax_force_retaddr
22947 ret
22948 CFI_ENDPROC
22949 ENDPROC(clear_page_c_e)
22950 @@ -43,6 +45,7 @@ ENTRY(clear_page)
22951 leaq 64(%rdi),%rdi
22952 jnz .Lloop
22953 nop
22954 + pax_force_retaddr
22955 ret
22956 CFI_ENDPROC
22957 .Lclear_page_end:
22958 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
22959
22960 #include <asm/cpufeature.h>
22961
22962 - .section .altinstr_replacement,"ax"
22963 + .section .altinstr_replacement,"a"
22964 1: .byte 0xeb /* jmp <disp8> */
22965 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
22966 2: .byte 0xeb /* jmp <disp8> */
22967 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
22968 index 1e572c5..2a162cd 100644
22969 --- a/arch/x86/lib/cmpxchg16b_emu.S
22970 +++ b/arch/x86/lib/cmpxchg16b_emu.S
22971 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
22972
22973 popf
22974 mov $1, %al
22975 + pax_force_retaddr
22976 ret
22977
22978 not_same:
22979 popf
22980 xor %al,%al
22981 + pax_force_retaddr
22982 ret
22983
22984 CFI_ENDPROC
22985 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
22986 index 6b34d04..dccb07f 100644
22987 --- a/arch/x86/lib/copy_page_64.S
22988 +++ b/arch/x86/lib/copy_page_64.S
22989 @@ -9,6 +9,7 @@ copy_page_c:
22990 CFI_STARTPROC
22991 movl $4096/8,%ecx
22992 rep movsq
22993 + pax_force_retaddr
22994 ret
22995 CFI_ENDPROC
22996 ENDPROC(copy_page_c)
22997 @@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
22998
22999 ENTRY(copy_page)
23000 CFI_STARTPROC
23001 - subq $2*8,%rsp
23002 - CFI_ADJUST_CFA_OFFSET 2*8
23003 + subq $3*8,%rsp
23004 + CFI_ADJUST_CFA_OFFSET 3*8
23005 movq %rbx,(%rsp)
23006 CFI_REL_OFFSET rbx, 0
23007 movq %r12,1*8(%rsp)
23008 CFI_REL_OFFSET r12, 1*8
23009 + movq %r13,2*8(%rsp)
23010 + CFI_REL_OFFSET r13, 2*8
23011
23012 movl $(4096/64)-5,%ecx
23013 .p2align 4
23014 @@ -37,7 +40,7 @@ ENTRY(copy_page)
23015 movq 16 (%rsi), %rdx
23016 movq 24 (%rsi), %r8
23017 movq 32 (%rsi), %r9
23018 - movq 40 (%rsi), %r10
23019 + movq 40 (%rsi), %r13
23020 movq 48 (%rsi), %r11
23021 movq 56 (%rsi), %r12
23022
23023 @@ -48,7 +51,7 @@ ENTRY(copy_page)
23024 movq %rdx, 16 (%rdi)
23025 movq %r8, 24 (%rdi)
23026 movq %r9, 32 (%rdi)
23027 - movq %r10, 40 (%rdi)
23028 + movq %r13, 40 (%rdi)
23029 movq %r11, 48 (%rdi)
23030 movq %r12, 56 (%rdi)
23031
23032 @@ -67,7 +70,7 @@ ENTRY(copy_page)
23033 movq 16 (%rsi), %rdx
23034 movq 24 (%rsi), %r8
23035 movq 32 (%rsi), %r9
23036 - movq 40 (%rsi), %r10
23037 + movq 40 (%rsi), %r13
23038 movq 48 (%rsi), %r11
23039 movq 56 (%rsi), %r12
23040
23041 @@ -76,7 +79,7 @@ ENTRY(copy_page)
23042 movq %rdx, 16 (%rdi)
23043 movq %r8, 24 (%rdi)
23044 movq %r9, 32 (%rdi)
23045 - movq %r10, 40 (%rdi)
23046 + movq %r13, 40 (%rdi)
23047 movq %r11, 48 (%rdi)
23048 movq %r12, 56 (%rdi)
23049
23050 @@ -89,8 +92,11 @@ ENTRY(copy_page)
23051 CFI_RESTORE rbx
23052 movq 1*8(%rsp),%r12
23053 CFI_RESTORE r12
23054 - addq $2*8,%rsp
23055 - CFI_ADJUST_CFA_OFFSET -2*8
23056 + movq 2*8(%rsp),%r13
23057 + CFI_RESTORE r13
23058 + addq $3*8,%rsp
23059 + CFI_ADJUST_CFA_OFFSET -3*8
23060 + pax_force_retaddr
23061 ret
23062 .Lcopy_page_end:
23063 CFI_ENDPROC
23064 @@ -101,7 +107,7 @@ ENDPROC(copy_page)
23065
23066 #include <asm/cpufeature.h>
23067
23068 - .section .altinstr_replacement,"ax"
23069 + .section .altinstr_replacement,"a"
23070 1: .byte 0xeb /* jmp <disp8> */
23071 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
23072 2:
23073 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
23074 index a30ca15..d25fab6 100644
23075 --- a/arch/x86/lib/copy_user_64.S
23076 +++ b/arch/x86/lib/copy_user_64.S
23077 @@ -18,6 +18,7 @@
23078 #include <asm/alternative-asm.h>
23079 #include <asm/asm.h>
23080 #include <asm/smap.h>
23081 +#include <asm/pgtable.h>
23082
23083 /*
23084 * By placing feature2 after feature1 in altinstructions section, we logically
23085 @@ -31,7 +32,7 @@
23086 .byte 0xe9 /* 32bit jump */
23087 .long \orig-1f /* by default jump to orig */
23088 1:
23089 - .section .altinstr_replacement,"ax"
23090 + .section .altinstr_replacement,"a"
23091 2: .byte 0xe9 /* near jump with 32bit immediate */
23092 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
23093 3: .byte 0xe9 /* near jump with 32bit immediate */
23094 @@ -70,47 +71,20 @@
23095 #endif
23096 .endm
23097
23098 -/* Standard copy_to_user with segment limit checking */
23099 -ENTRY(_copy_to_user)
23100 - CFI_STARTPROC
23101 - GET_THREAD_INFO(%rax)
23102 - movq %rdi,%rcx
23103 - addq %rdx,%rcx
23104 - jc bad_to_user
23105 - cmpq TI_addr_limit(%rax),%rcx
23106 - ja bad_to_user
23107 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
23108 - copy_user_generic_unrolled,copy_user_generic_string, \
23109 - copy_user_enhanced_fast_string
23110 - CFI_ENDPROC
23111 -ENDPROC(_copy_to_user)
23112 -
23113 -/* Standard copy_from_user with segment limit checking */
23114 -ENTRY(_copy_from_user)
23115 - CFI_STARTPROC
23116 - GET_THREAD_INFO(%rax)
23117 - movq %rsi,%rcx
23118 - addq %rdx,%rcx
23119 - jc bad_from_user
23120 - cmpq TI_addr_limit(%rax),%rcx
23121 - ja bad_from_user
23122 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
23123 - copy_user_generic_unrolled,copy_user_generic_string, \
23124 - copy_user_enhanced_fast_string
23125 - CFI_ENDPROC
23126 -ENDPROC(_copy_from_user)
23127 -
23128 .section .fixup,"ax"
23129 /* must zero dest */
23130 ENTRY(bad_from_user)
23131 bad_from_user:
23132 CFI_STARTPROC
23133 + testl %edx,%edx
23134 + js bad_to_user
23135 movl %edx,%ecx
23136 xorl %eax,%eax
23137 rep
23138 stosb
23139 bad_to_user:
23140 movl %edx,%eax
23141 + pax_force_retaddr
23142 ret
23143 CFI_ENDPROC
23144 ENDPROC(bad_from_user)
23145 @@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
23146 jz 17f
23147 1: movq (%rsi),%r8
23148 2: movq 1*8(%rsi),%r9
23149 -3: movq 2*8(%rsi),%r10
23150 +3: movq 2*8(%rsi),%rax
23151 4: movq 3*8(%rsi),%r11
23152 5: movq %r8,(%rdi)
23153 6: movq %r9,1*8(%rdi)
23154 -7: movq %r10,2*8(%rdi)
23155 +7: movq %rax,2*8(%rdi)
23156 8: movq %r11,3*8(%rdi)
23157 9: movq 4*8(%rsi),%r8
23158 10: movq 5*8(%rsi),%r9
23159 -11: movq 6*8(%rsi),%r10
23160 +11: movq 6*8(%rsi),%rax
23161 12: movq 7*8(%rsi),%r11
23162 13: movq %r8,4*8(%rdi)
23163 14: movq %r9,5*8(%rdi)
23164 -15: movq %r10,6*8(%rdi)
23165 +15: movq %rax,6*8(%rdi)
23166 16: movq %r11,7*8(%rdi)
23167 leaq 64(%rsi),%rsi
23168 leaq 64(%rdi),%rdi
23169 @@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
23170 jnz 21b
23171 23: xor %eax,%eax
23172 ASM_CLAC
23173 + pax_force_retaddr
23174 ret
23175
23176 .section .fixup,"ax"
23177 @@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
23178 movsb
23179 4: xorl %eax,%eax
23180 ASM_CLAC
23181 + pax_force_retaddr
23182 ret
23183
23184 .section .fixup,"ax"
23185 @@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
23186 movsb
23187 2: xorl %eax,%eax
23188 ASM_CLAC
23189 + pax_force_retaddr
23190 ret
23191
23192 .section .fixup,"ax"
23193 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
23194 index 6a4f43c..f5f9e26 100644
23195 --- a/arch/x86/lib/copy_user_nocache_64.S
23196 +++ b/arch/x86/lib/copy_user_nocache_64.S
23197 @@ -8,6 +8,7 @@
23198
23199 #include <linux/linkage.h>
23200 #include <asm/dwarf2.h>
23201 +#include <asm/alternative-asm.h>
23202
23203 #define FIX_ALIGNMENT 1
23204
23205 @@ -16,6 +17,7 @@
23206 #include <asm/thread_info.h>
23207 #include <asm/asm.h>
23208 #include <asm/smap.h>
23209 +#include <asm/pgtable.h>
23210
23211 .macro ALIGN_DESTINATION
23212 #ifdef FIX_ALIGNMENT
23213 @@ -49,6 +51,15 @@
23214 */
23215 ENTRY(__copy_user_nocache)
23216 CFI_STARTPROC
23217 +
23218 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23219 + mov $PAX_USER_SHADOW_BASE,%rcx
23220 + cmp %rcx,%rsi
23221 + jae 1f
23222 + add %rcx,%rsi
23223 +1:
23224 +#endif
23225 +
23226 ASM_STAC
23227 cmpl $8,%edx
23228 jb 20f /* less then 8 bytes, go to byte copy loop */
23229 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
23230 jz 17f
23231 1: movq (%rsi),%r8
23232 2: movq 1*8(%rsi),%r9
23233 -3: movq 2*8(%rsi),%r10
23234 +3: movq 2*8(%rsi),%rax
23235 4: movq 3*8(%rsi),%r11
23236 5: movnti %r8,(%rdi)
23237 6: movnti %r9,1*8(%rdi)
23238 -7: movnti %r10,2*8(%rdi)
23239 +7: movnti %rax,2*8(%rdi)
23240 8: movnti %r11,3*8(%rdi)
23241 9: movq 4*8(%rsi),%r8
23242 10: movq 5*8(%rsi),%r9
23243 -11: movq 6*8(%rsi),%r10
23244 +11: movq 6*8(%rsi),%rax
23245 12: movq 7*8(%rsi),%r11
23246 13: movnti %r8,4*8(%rdi)
23247 14: movnti %r9,5*8(%rdi)
23248 -15: movnti %r10,6*8(%rdi)
23249 +15: movnti %rax,6*8(%rdi)
23250 16: movnti %r11,7*8(%rdi)
23251 leaq 64(%rsi),%rsi
23252 leaq 64(%rdi),%rdi
23253 @@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
23254 23: xorl %eax,%eax
23255 ASM_CLAC
23256 sfence
23257 + pax_force_retaddr
23258 ret
23259
23260 .section .fixup,"ax"
23261 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
23262 index 2419d5f..953ee51 100644
23263 --- a/arch/x86/lib/csum-copy_64.S
23264 +++ b/arch/x86/lib/csum-copy_64.S
23265 @@ -9,6 +9,7 @@
23266 #include <asm/dwarf2.h>
23267 #include <asm/errno.h>
23268 #include <asm/asm.h>
23269 +#include <asm/alternative-asm.h>
23270
23271 /*
23272 * Checksum copy with exception handling.
23273 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
23274 CFI_RESTORE rbp
23275 addq $7*8, %rsp
23276 CFI_ADJUST_CFA_OFFSET -7*8
23277 + pax_force_retaddr 0, 1
23278 ret
23279 CFI_RESTORE_STATE
23280
23281 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
23282 index 25b7ae8..169fafc 100644
23283 --- a/arch/x86/lib/csum-wrappers_64.c
23284 +++ b/arch/x86/lib/csum-wrappers_64.c
23285 @@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
23286 len -= 2;
23287 }
23288 }
23289 - isum = csum_partial_copy_generic((__force const void *)src,
23290 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
23291 dst, len, isum, errp, NULL);
23292 if (unlikely(*errp))
23293 goto out_err;
23294 @@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
23295 }
23296
23297 *errp = 0;
23298 - return csum_partial_copy_generic(src, (void __force *)dst,
23299 + return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
23300 len, isum, NULL, errp);
23301 }
23302 EXPORT_SYMBOL(csum_partial_copy_to_user);
23303 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
23304 index 156b9c8..b144132 100644
23305 --- a/arch/x86/lib/getuser.S
23306 +++ b/arch/x86/lib/getuser.S
23307 @@ -34,17 +34,40 @@
23308 #include <asm/thread_info.h>
23309 #include <asm/asm.h>
23310 #include <asm/smap.h>
23311 +#include <asm/segment.h>
23312 +#include <asm/pgtable.h>
23313 +#include <asm/alternative-asm.h>
23314 +
23315 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
23316 +#define __copyuser_seg gs;
23317 +#else
23318 +#define __copyuser_seg
23319 +#endif
23320
23321 .text
23322 ENTRY(__get_user_1)
23323 CFI_STARTPROC
23324 +
23325 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23326 GET_THREAD_INFO(%_ASM_DX)
23327 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23328 jae bad_get_user
23329 ASM_STAC
23330 -1: movzb (%_ASM_AX),%edx
23331 +
23332 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23333 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23334 + cmp %_ASM_DX,%_ASM_AX
23335 + jae 1234f
23336 + add %_ASM_DX,%_ASM_AX
23337 +1234:
23338 +#endif
23339 +
23340 +#endif
23341 +
23342 +1: __copyuser_seg movzb (%_ASM_AX),%edx
23343 xor %eax,%eax
23344 ASM_CLAC
23345 + pax_force_retaddr
23346 ret
23347 CFI_ENDPROC
23348 ENDPROC(__get_user_1)
23349 @@ -52,14 +75,28 @@ ENDPROC(__get_user_1)
23350 ENTRY(__get_user_2)
23351 CFI_STARTPROC
23352 add $1,%_ASM_AX
23353 +
23354 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23355 jc bad_get_user
23356 GET_THREAD_INFO(%_ASM_DX)
23357 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23358 jae bad_get_user
23359 ASM_STAC
23360 -2: movzwl -1(%_ASM_AX),%edx
23361 +
23362 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23363 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23364 + cmp %_ASM_DX,%_ASM_AX
23365 + jae 1234f
23366 + add %_ASM_DX,%_ASM_AX
23367 +1234:
23368 +#endif
23369 +
23370 +#endif
23371 +
23372 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
23373 xor %eax,%eax
23374 ASM_CLAC
23375 + pax_force_retaddr
23376 ret
23377 CFI_ENDPROC
23378 ENDPROC(__get_user_2)
23379 @@ -67,14 +104,28 @@ ENDPROC(__get_user_2)
23380 ENTRY(__get_user_4)
23381 CFI_STARTPROC
23382 add $3,%_ASM_AX
23383 +
23384 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23385 jc bad_get_user
23386 GET_THREAD_INFO(%_ASM_DX)
23387 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23388 jae bad_get_user
23389 ASM_STAC
23390 -3: mov -3(%_ASM_AX),%edx
23391 +
23392 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23393 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23394 + cmp %_ASM_DX,%_ASM_AX
23395 + jae 1234f
23396 + add %_ASM_DX,%_ASM_AX
23397 +1234:
23398 +#endif
23399 +
23400 +#endif
23401 +
23402 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
23403 xor %eax,%eax
23404 ASM_CLAC
23405 + pax_force_retaddr
23406 ret
23407 CFI_ENDPROC
23408 ENDPROC(__get_user_4)
23409 @@ -87,10 +138,20 @@ ENTRY(__get_user_8)
23410 GET_THREAD_INFO(%_ASM_DX)
23411 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23412 jae bad_get_user
23413 +
23414 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23415 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23416 + cmp %_ASM_DX,%_ASM_AX
23417 + jae 1234f
23418 + add %_ASM_DX,%_ASM_AX
23419 +1234:
23420 +#endif
23421 +
23422 ASM_STAC
23423 4: movq -7(%_ASM_AX),%_ASM_DX
23424 xor %eax,%eax
23425 ASM_CLAC
23426 + pax_force_retaddr
23427 ret
23428 CFI_ENDPROC
23429 ENDPROC(__get_user_8)
23430 @@ -101,6 +162,7 @@ bad_get_user:
23431 xor %edx,%edx
23432 mov $(-EFAULT),%_ASM_AX
23433 ASM_CLAC
23434 + pax_force_retaddr
23435 ret
23436 CFI_ENDPROC
23437 END(bad_get_user)
23438 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
23439 index 54fcffe..7be149e 100644
23440 --- a/arch/x86/lib/insn.c
23441 +++ b/arch/x86/lib/insn.c
23442 @@ -20,8 +20,10 @@
23443
23444 #ifdef __KERNEL__
23445 #include <linux/string.h>
23446 +#include <asm/pgtable_types.h>
23447 #else
23448 #include <string.h>
23449 +#define ktla_ktva(addr) addr
23450 #endif
23451 #include <asm/inat.h>
23452 #include <asm/insn.h>
23453 @@ -53,8 +55,8 @@
23454 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
23455 {
23456 memset(insn, 0, sizeof(*insn));
23457 - insn->kaddr = kaddr;
23458 - insn->next_byte = kaddr;
23459 + insn->kaddr = ktla_ktva(kaddr);
23460 + insn->next_byte = ktla_ktva(kaddr);
23461 insn->x86_64 = x86_64 ? 1 : 0;
23462 insn->opnd_bytes = 4;
23463 if (x86_64)
23464 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
23465 index 05a95e7..326f2fa 100644
23466 --- a/arch/x86/lib/iomap_copy_64.S
23467 +++ b/arch/x86/lib/iomap_copy_64.S
23468 @@ -17,6 +17,7 @@
23469
23470 #include <linux/linkage.h>
23471 #include <asm/dwarf2.h>
23472 +#include <asm/alternative-asm.h>
23473
23474 /*
23475 * override generic version in lib/iomap_copy.c
23476 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
23477 CFI_STARTPROC
23478 movl %edx,%ecx
23479 rep movsd
23480 + pax_force_retaddr
23481 ret
23482 CFI_ENDPROC
23483 ENDPROC(__iowrite32_copy)
23484 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
23485 index 1c273be..da9cc0e 100644
23486 --- a/arch/x86/lib/memcpy_64.S
23487 +++ b/arch/x86/lib/memcpy_64.S
23488 @@ -33,6 +33,7 @@
23489 rep movsq
23490 movl %edx, %ecx
23491 rep movsb
23492 + pax_force_retaddr
23493 ret
23494 .Lmemcpy_e:
23495 .previous
23496 @@ -49,6 +50,7 @@
23497 movq %rdi, %rax
23498 movq %rdx, %rcx
23499 rep movsb
23500 + pax_force_retaddr
23501 ret
23502 .Lmemcpy_e_e:
23503 .previous
23504 @@ -76,13 +78,13 @@ ENTRY(memcpy)
23505 */
23506 movq 0*8(%rsi), %r8
23507 movq 1*8(%rsi), %r9
23508 - movq 2*8(%rsi), %r10
23509 + movq 2*8(%rsi), %rcx
23510 movq 3*8(%rsi), %r11
23511 leaq 4*8(%rsi), %rsi
23512
23513 movq %r8, 0*8(%rdi)
23514 movq %r9, 1*8(%rdi)
23515 - movq %r10, 2*8(%rdi)
23516 + movq %rcx, 2*8(%rdi)
23517 movq %r11, 3*8(%rdi)
23518 leaq 4*8(%rdi), %rdi
23519 jae .Lcopy_forward_loop
23520 @@ -105,12 +107,12 @@ ENTRY(memcpy)
23521 subq $0x20, %rdx
23522 movq -1*8(%rsi), %r8
23523 movq -2*8(%rsi), %r9
23524 - movq -3*8(%rsi), %r10
23525 + movq -3*8(%rsi), %rcx
23526 movq -4*8(%rsi), %r11
23527 leaq -4*8(%rsi), %rsi
23528 movq %r8, -1*8(%rdi)
23529 movq %r9, -2*8(%rdi)
23530 - movq %r10, -3*8(%rdi)
23531 + movq %rcx, -3*8(%rdi)
23532 movq %r11, -4*8(%rdi)
23533 leaq -4*8(%rdi), %rdi
23534 jae .Lcopy_backward_loop
23535 @@ -130,12 +132,13 @@ ENTRY(memcpy)
23536 */
23537 movq 0*8(%rsi), %r8
23538 movq 1*8(%rsi), %r9
23539 - movq -2*8(%rsi, %rdx), %r10
23540 + movq -2*8(%rsi, %rdx), %rcx
23541 movq -1*8(%rsi, %rdx), %r11
23542 movq %r8, 0*8(%rdi)
23543 movq %r9, 1*8(%rdi)
23544 - movq %r10, -2*8(%rdi, %rdx)
23545 + movq %rcx, -2*8(%rdi, %rdx)
23546 movq %r11, -1*8(%rdi, %rdx)
23547 + pax_force_retaddr
23548 retq
23549 .p2align 4
23550 .Lless_16bytes:
23551 @@ -148,6 +151,7 @@ ENTRY(memcpy)
23552 movq -1*8(%rsi, %rdx), %r9
23553 movq %r8, 0*8(%rdi)
23554 movq %r9, -1*8(%rdi, %rdx)
23555 + pax_force_retaddr
23556 retq
23557 .p2align 4
23558 .Lless_8bytes:
23559 @@ -161,6 +165,7 @@ ENTRY(memcpy)
23560 movl -4(%rsi, %rdx), %r8d
23561 movl %ecx, (%rdi)
23562 movl %r8d, -4(%rdi, %rdx)
23563 + pax_force_retaddr
23564 retq
23565 .p2align 4
23566 .Lless_3bytes:
23567 @@ -179,6 +184,7 @@ ENTRY(memcpy)
23568 movb %cl, (%rdi)
23569
23570 .Lend:
23571 + pax_force_retaddr
23572 retq
23573 CFI_ENDPROC
23574 ENDPROC(memcpy)
23575 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
23576 index ee16461..c39c199 100644
23577 --- a/arch/x86/lib/memmove_64.S
23578 +++ b/arch/x86/lib/memmove_64.S
23579 @@ -61,13 +61,13 @@ ENTRY(memmove)
23580 5:
23581 sub $0x20, %rdx
23582 movq 0*8(%rsi), %r11
23583 - movq 1*8(%rsi), %r10
23584 + movq 1*8(%rsi), %rcx
23585 movq 2*8(%rsi), %r9
23586 movq 3*8(%rsi), %r8
23587 leaq 4*8(%rsi), %rsi
23588
23589 movq %r11, 0*8(%rdi)
23590 - movq %r10, 1*8(%rdi)
23591 + movq %rcx, 1*8(%rdi)
23592 movq %r9, 2*8(%rdi)
23593 movq %r8, 3*8(%rdi)
23594 leaq 4*8(%rdi), %rdi
23595 @@ -81,10 +81,10 @@ ENTRY(memmove)
23596 4:
23597 movq %rdx, %rcx
23598 movq -8(%rsi, %rdx), %r11
23599 - lea -8(%rdi, %rdx), %r10
23600 + lea -8(%rdi, %rdx), %r9
23601 shrq $3, %rcx
23602 rep movsq
23603 - movq %r11, (%r10)
23604 + movq %r11, (%r9)
23605 jmp 13f
23606 .Lmemmove_end_forward:
23607
23608 @@ -95,14 +95,14 @@ ENTRY(memmove)
23609 7:
23610 movq %rdx, %rcx
23611 movq (%rsi), %r11
23612 - movq %rdi, %r10
23613 + movq %rdi, %r9
23614 leaq -8(%rsi, %rdx), %rsi
23615 leaq -8(%rdi, %rdx), %rdi
23616 shrq $3, %rcx
23617 std
23618 rep movsq
23619 cld
23620 - movq %r11, (%r10)
23621 + movq %r11, (%r9)
23622 jmp 13f
23623
23624 /*
23625 @@ -127,13 +127,13 @@ ENTRY(memmove)
23626 8:
23627 subq $0x20, %rdx
23628 movq -1*8(%rsi), %r11
23629 - movq -2*8(%rsi), %r10
23630 + movq -2*8(%rsi), %rcx
23631 movq -3*8(%rsi), %r9
23632 movq -4*8(%rsi), %r8
23633 leaq -4*8(%rsi), %rsi
23634
23635 movq %r11, -1*8(%rdi)
23636 - movq %r10, -2*8(%rdi)
23637 + movq %rcx, -2*8(%rdi)
23638 movq %r9, -3*8(%rdi)
23639 movq %r8, -4*8(%rdi)
23640 leaq -4*8(%rdi), %rdi
23641 @@ -151,11 +151,11 @@ ENTRY(memmove)
23642 * Move data from 16 bytes to 31 bytes.
23643 */
23644 movq 0*8(%rsi), %r11
23645 - movq 1*8(%rsi), %r10
23646 + movq 1*8(%rsi), %rcx
23647 movq -2*8(%rsi, %rdx), %r9
23648 movq -1*8(%rsi, %rdx), %r8
23649 movq %r11, 0*8(%rdi)
23650 - movq %r10, 1*8(%rdi)
23651 + movq %rcx, 1*8(%rdi)
23652 movq %r9, -2*8(%rdi, %rdx)
23653 movq %r8, -1*8(%rdi, %rdx)
23654 jmp 13f
23655 @@ -167,9 +167,9 @@ ENTRY(memmove)
23656 * Move data from 8 bytes to 15 bytes.
23657 */
23658 movq 0*8(%rsi), %r11
23659 - movq -1*8(%rsi, %rdx), %r10
23660 + movq -1*8(%rsi, %rdx), %r9
23661 movq %r11, 0*8(%rdi)
23662 - movq %r10, -1*8(%rdi, %rdx)
23663 + movq %r9, -1*8(%rdi, %rdx)
23664 jmp 13f
23665 10:
23666 cmpq $4, %rdx
23667 @@ -178,9 +178,9 @@ ENTRY(memmove)
23668 * Move data from 4 bytes to 7 bytes.
23669 */
23670 movl (%rsi), %r11d
23671 - movl -4(%rsi, %rdx), %r10d
23672 + movl -4(%rsi, %rdx), %r9d
23673 movl %r11d, (%rdi)
23674 - movl %r10d, -4(%rdi, %rdx)
23675 + movl %r9d, -4(%rdi, %rdx)
23676 jmp 13f
23677 11:
23678 cmp $2, %rdx
23679 @@ -189,9 +189,9 @@ ENTRY(memmove)
23680 * Move data from 2 bytes to 3 bytes.
23681 */
23682 movw (%rsi), %r11w
23683 - movw -2(%rsi, %rdx), %r10w
23684 + movw -2(%rsi, %rdx), %r9w
23685 movw %r11w, (%rdi)
23686 - movw %r10w, -2(%rdi, %rdx)
23687 + movw %r9w, -2(%rdi, %rdx)
23688 jmp 13f
23689 12:
23690 cmp $1, %rdx
23691 @@ -202,6 +202,7 @@ ENTRY(memmove)
23692 movb (%rsi), %r11b
23693 movb %r11b, (%rdi)
23694 13:
23695 + pax_force_retaddr
23696 retq
23697 CFI_ENDPROC
23698
23699 @@ -210,6 +211,7 @@ ENTRY(memmove)
23700 /* Forward moving data. */
23701 movq %rdx, %rcx
23702 rep movsb
23703 + pax_force_retaddr
23704 retq
23705 .Lmemmove_end_forward_efs:
23706 .previous
23707 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
23708 index 2dcb380..963660a 100644
23709 --- a/arch/x86/lib/memset_64.S
23710 +++ b/arch/x86/lib/memset_64.S
23711 @@ -30,6 +30,7 @@
23712 movl %edx,%ecx
23713 rep stosb
23714 movq %r9,%rax
23715 + pax_force_retaddr
23716 ret
23717 .Lmemset_e:
23718 .previous
23719 @@ -52,6 +53,7 @@
23720 movq %rdx,%rcx
23721 rep stosb
23722 movq %r9,%rax
23723 + pax_force_retaddr
23724 ret
23725 .Lmemset_e_e:
23726 .previous
23727 @@ -59,7 +61,7 @@
23728 ENTRY(memset)
23729 ENTRY(__memset)
23730 CFI_STARTPROC
23731 - movq %rdi,%r10
23732 + movq %rdi,%r11
23733
23734 /* expand byte value */
23735 movzbl %sil,%ecx
23736 @@ -117,7 +119,8 @@ ENTRY(__memset)
23737 jnz .Lloop_1
23738
23739 .Lende:
23740 - movq %r10,%rax
23741 + movq %r11,%rax
23742 + pax_force_retaddr
23743 ret
23744
23745 CFI_RESTORE_STATE
23746 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
23747 index c9f2d9b..e7fd2c0 100644
23748 --- a/arch/x86/lib/mmx_32.c
23749 +++ b/arch/x86/lib/mmx_32.c
23750 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
23751 {
23752 void *p;
23753 int i;
23754 + unsigned long cr0;
23755
23756 if (unlikely(in_interrupt()))
23757 return __memcpy(to, from, len);
23758 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
23759 kernel_fpu_begin();
23760
23761 __asm__ __volatile__ (
23762 - "1: prefetch (%0)\n" /* This set is 28 bytes */
23763 - " prefetch 64(%0)\n"
23764 - " prefetch 128(%0)\n"
23765 - " prefetch 192(%0)\n"
23766 - " prefetch 256(%0)\n"
23767 + "1: prefetch (%1)\n" /* This set is 28 bytes */
23768 + " prefetch 64(%1)\n"
23769 + " prefetch 128(%1)\n"
23770 + " prefetch 192(%1)\n"
23771 + " prefetch 256(%1)\n"
23772 "2: \n"
23773 ".section .fixup, \"ax\"\n"
23774 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23775 + "3: \n"
23776 +
23777 +#ifdef CONFIG_PAX_KERNEXEC
23778 + " movl %%cr0, %0\n"
23779 + " movl %0, %%eax\n"
23780 + " andl $0xFFFEFFFF, %%eax\n"
23781 + " movl %%eax, %%cr0\n"
23782 +#endif
23783 +
23784 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23785 +
23786 +#ifdef CONFIG_PAX_KERNEXEC
23787 + " movl %0, %%cr0\n"
23788 +#endif
23789 +
23790 " jmp 2b\n"
23791 ".previous\n"
23792 _ASM_EXTABLE(1b, 3b)
23793 - : : "r" (from));
23794 + : "=&r" (cr0) : "r" (from) : "ax");
23795
23796 for ( ; i > 5; i--) {
23797 __asm__ __volatile__ (
23798 - "1: prefetch 320(%0)\n"
23799 - "2: movq (%0), %%mm0\n"
23800 - " movq 8(%0), %%mm1\n"
23801 - " movq 16(%0), %%mm2\n"
23802 - " movq 24(%0), %%mm3\n"
23803 - " movq %%mm0, (%1)\n"
23804 - " movq %%mm1, 8(%1)\n"
23805 - " movq %%mm2, 16(%1)\n"
23806 - " movq %%mm3, 24(%1)\n"
23807 - " movq 32(%0), %%mm0\n"
23808 - " movq 40(%0), %%mm1\n"
23809 - " movq 48(%0), %%mm2\n"
23810 - " movq 56(%0), %%mm3\n"
23811 - " movq %%mm0, 32(%1)\n"
23812 - " movq %%mm1, 40(%1)\n"
23813 - " movq %%mm2, 48(%1)\n"
23814 - " movq %%mm3, 56(%1)\n"
23815 + "1: prefetch 320(%1)\n"
23816 + "2: movq (%1), %%mm0\n"
23817 + " movq 8(%1), %%mm1\n"
23818 + " movq 16(%1), %%mm2\n"
23819 + " movq 24(%1), %%mm3\n"
23820 + " movq %%mm0, (%2)\n"
23821 + " movq %%mm1, 8(%2)\n"
23822 + " movq %%mm2, 16(%2)\n"
23823 + " movq %%mm3, 24(%2)\n"
23824 + " movq 32(%1), %%mm0\n"
23825 + " movq 40(%1), %%mm1\n"
23826 + " movq 48(%1), %%mm2\n"
23827 + " movq 56(%1), %%mm3\n"
23828 + " movq %%mm0, 32(%2)\n"
23829 + " movq %%mm1, 40(%2)\n"
23830 + " movq %%mm2, 48(%2)\n"
23831 + " movq %%mm3, 56(%2)\n"
23832 ".section .fixup, \"ax\"\n"
23833 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23834 + "3:\n"
23835 +
23836 +#ifdef CONFIG_PAX_KERNEXEC
23837 + " movl %%cr0, %0\n"
23838 + " movl %0, %%eax\n"
23839 + " andl $0xFFFEFFFF, %%eax\n"
23840 + " movl %%eax, %%cr0\n"
23841 +#endif
23842 +
23843 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23844 +
23845 +#ifdef CONFIG_PAX_KERNEXEC
23846 + " movl %0, %%cr0\n"
23847 +#endif
23848 +
23849 " jmp 2b\n"
23850 ".previous\n"
23851 _ASM_EXTABLE(1b, 3b)
23852 - : : "r" (from), "r" (to) : "memory");
23853 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
23854
23855 from += 64;
23856 to += 64;
23857 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
23858 static void fast_copy_page(void *to, void *from)
23859 {
23860 int i;
23861 + unsigned long cr0;
23862
23863 kernel_fpu_begin();
23864
23865 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
23866 * but that is for later. -AV
23867 */
23868 __asm__ __volatile__(
23869 - "1: prefetch (%0)\n"
23870 - " prefetch 64(%0)\n"
23871 - " prefetch 128(%0)\n"
23872 - " prefetch 192(%0)\n"
23873 - " prefetch 256(%0)\n"
23874 + "1: prefetch (%1)\n"
23875 + " prefetch 64(%1)\n"
23876 + " prefetch 128(%1)\n"
23877 + " prefetch 192(%1)\n"
23878 + " prefetch 256(%1)\n"
23879 "2: \n"
23880 ".section .fixup, \"ax\"\n"
23881 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23882 + "3: \n"
23883 +
23884 +#ifdef CONFIG_PAX_KERNEXEC
23885 + " movl %%cr0, %0\n"
23886 + " movl %0, %%eax\n"
23887 + " andl $0xFFFEFFFF, %%eax\n"
23888 + " movl %%eax, %%cr0\n"
23889 +#endif
23890 +
23891 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23892 +
23893 +#ifdef CONFIG_PAX_KERNEXEC
23894 + " movl %0, %%cr0\n"
23895 +#endif
23896 +
23897 " jmp 2b\n"
23898 ".previous\n"
23899 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
23900 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
23901
23902 for (i = 0; i < (4096-320)/64; i++) {
23903 __asm__ __volatile__ (
23904 - "1: prefetch 320(%0)\n"
23905 - "2: movq (%0), %%mm0\n"
23906 - " movntq %%mm0, (%1)\n"
23907 - " movq 8(%0), %%mm1\n"
23908 - " movntq %%mm1, 8(%1)\n"
23909 - " movq 16(%0), %%mm2\n"
23910 - " movntq %%mm2, 16(%1)\n"
23911 - " movq 24(%0), %%mm3\n"
23912 - " movntq %%mm3, 24(%1)\n"
23913 - " movq 32(%0), %%mm4\n"
23914 - " movntq %%mm4, 32(%1)\n"
23915 - " movq 40(%0), %%mm5\n"
23916 - " movntq %%mm5, 40(%1)\n"
23917 - " movq 48(%0), %%mm6\n"
23918 - " movntq %%mm6, 48(%1)\n"
23919 - " movq 56(%0), %%mm7\n"
23920 - " movntq %%mm7, 56(%1)\n"
23921 + "1: prefetch 320(%1)\n"
23922 + "2: movq (%1), %%mm0\n"
23923 + " movntq %%mm0, (%2)\n"
23924 + " movq 8(%1), %%mm1\n"
23925 + " movntq %%mm1, 8(%2)\n"
23926 + " movq 16(%1), %%mm2\n"
23927 + " movntq %%mm2, 16(%2)\n"
23928 + " movq 24(%1), %%mm3\n"
23929 + " movntq %%mm3, 24(%2)\n"
23930 + " movq 32(%1), %%mm4\n"
23931 + " movntq %%mm4, 32(%2)\n"
23932 + " movq 40(%1), %%mm5\n"
23933 + " movntq %%mm5, 40(%2)\n"
23934 + " movq 48(%1), %%mm6\n"
23935 + " movntq %%mm6, 48(%2)\n"
23936 + " movq 56(%1), %%mm7\n"
23937 + " movntq %%mm7, 56(%2)\n"
23938 ".section .fixup, \"ax\"\n"
23939 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23940 + "3:\n"
23941 +
23942 +#ifdef CONFIG_PAX_KERNEXEC
23943 + " movl %%cr0, %0\n"
23944 + " movl %0, %%eax\n"
23945 + " andl $0xFFFEFFFF, %%eax\n"
23946 + " movl %%eax, %%cr0\n"
23947 +#endif
23948 +
23949 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23950 +
23951 +#ifdef CONFIG_PAX_KERNEXEC
23952 + " movl %0, %%cr0\n"
23953 +#endif
23954 +
23955 " jmp 2b\n"
23956 ".previous\n"
23957 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
23958 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
23959
23960 from += 64;
23961 to += 64;
23962 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
23963 static void fast_copy_page(void *to, void *from)
23964 {
23965 int i;
23966 + unsigned long cr0;
23967
23968 kernel_fpu_begin();
23969
23970 __asm__ __volatile__ (
23971 - "1: prefetch (%0)\n"
23972 - " prefetch 64(%0)\n"
23973 - " prefetch 128(%0)\n"
23974 - " prefetch 192(%0)\n"
23975 - " prefetch 256(%0)\n"
23976 + "1: prefetch (%1)\n"
23977 + " prefetch 64(%1)\n"
23978 + " prefetch 128(%1)\n"
23979 + " prefetch 192(%1)\n"
23980 + " prefetch 256(%1)\n"
23981 "2: \n"
23982 ".section .fixup, \"ax\"\n"
23983 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23984 + "3: \n"
23985 +
23986 +#ifdef CONFIG_PAX_KERNEXEC
23987 + " movl %%cr0, %0\n"
23988 + " movl %0, %%eax\n"
23989 + " andl $0xFFFEFFFF, %%eax\n"
23990 + " movl %%eax, %%cr0\n"
23991 +#endif
23992 +
23993 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23994 +
23995 +#ifdef CONFIG_PAX_KERNEXEC
23996 + " movl %0, %%cr0\n"
23997 +#endif
23998 +
23999 " jmp 2b\n"
24000 ".previous\n"
24001 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
24002 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
24003
24004 for (i = 0; i < 4096/64; i++) {
24005 __asm__ __volatile__ (
24006 - "1: prefetch 320(%0)\n"
24007 - "2: movq (%0), %%mm0\n"
24008 - " movq 8(%0), %%mm1\n"
24009 - " movq 16(%0), %%mm2\n"
24010 - " movq 24(%0), %%mm3\n"
24011 - " movq %%mm0, (%1)\n"
24012 - " movq %%mm1, 8(%1)\n"
24013 - " movq %%mm2, 16(%1)\n"
24014 - " movq %%mm3, 24(%1)\n"
24015 - " movq 32(%0), %%mm0\n"
24016 - " movq 40(%0), %%mm1\n"
24017 - " movq 48(%0), %%mm2\n"
24018 - " movq 56(%0), %%mm3\n"
24019 - " movq %%mm0, 32(%1)\n"
24020 - " movq %%mm1, 40(%1)\n"
24021 - " movq %%mm2, 48(%1)\n"
24022 - " movq %%mm3, 56(%1)\n"
24023 + "1: prefetch 320(%1)\n"
24024 + "2: movq (%1), %%mm0\n"
24025 + " movq 8(%1), %%mm1\n"
24026 + " movq 16(%1), %%mm2\n"
24027 + " movq 24(%1), %%mm3\n"
24028 + " movq %%mm0, (%2)\n"
24029 + " movq %%mm1, 8(%2)\n"
24030 + " movq %%mm2, 16(%2)\n"
24031 + " movq %%mm3, 24(%2)\n"
24032 + " movq 32(%1), %%mm0\n"
24033 + " movq 40(%1), %%mm1\n"
24034 + " movq 48(%1), %%mm2\n"
24035 + " movq 56(%1), %%mm3\n"
24036 + " movq %%mm0, 32(%2)\n"
24037 + " movq %%mm1, 40(%2)\n"
24038 + " movq %%mm2, 48(%2)\n"
24039 + " movq %%mm3, 56(%2)\n"
24040 ".section .fixup, \"ax\"\n"
24041 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
24042 + "3:\n"
24043 +
24044 +#ifdef CONFIG_PAX_KERNEXEC
24045 + " movl %%cr0, %0\n"
24046 + " movl %0, %%eax\n"
24047 + " andl $0xFFFEFFFF, %%eax\n"
24048 + " movl %%eax, %%cr0\n"
24049 +#endif
24050 +
24051 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
24052 +
24053 +#ifdef CONFIG_PAX_KERNEXEC
24054 + " movl %0, %%cr0\n"
24055 +#endif
24056 +
24057 " jmp 2b\n"
24058 ".previous\n"
24059 _ASM_EXTABLE(1b, 3b)
24060 - : : "r" (from), "r" (to) : "memory");
24061 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
24062
24063 from += 64;
24064 to += 64;
24065 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
24066 index f6d13ee..aca5f0b 100644
24067 --- a/arch/x86/lib/msr-reg.S
24068 +++ b/arch/x86/lib/msr-reg.S
24069 @@ -3,6 +3,7 @@
24070 #include <asm/dwarf2.h>
24071 #include <asm/asm.h>
24072 #include <asm/msr.h>
24073 +#include <asm/alternative-asm.h>
24074
24075 #ifdef CONFIG_X86_64
24076 /*
24077 @@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
24078 CFI_STARTPROC
24079 pushq_cfi %rbx
24080 pushq_cfi %rbp
24081 - movq %rdi, %r10 /* Save pointer */
24082 + movq %rdi, %r9 /* Save pointer */
24083 xorl %r11d, %r11d /* Return value */
24084 movl (%rdi), %eax
24085 movl 4(%rdi), %ecx
24086 @@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
24087 movl 28(%rdi), %edi
24088 CFI_REMEMBER_STATE
24089 1: \op
24090 -2: movl %eax, (%r10)
24091 +2: movl %eax, (%r9)
24092 movl %r11d, %eax /* Return value */
24093 - movl %ecx, 4(%r10)
24094 - movl %edx, 8(%r10)
24095 - movl %ebx, 12(%r10)
24096 - movl %ebp, 20(%r10)
24097 - movl %esi, 24(%r10)
24098 - movl %edi, 28(%r10)
24099 + movl %ecx, 4(%r9)
24100 + movl %edx, 8(%r9)
24101 + movl %ebx, 12(%r9)
24102 + movl %ebp, 20(%r9)
24103 + movl %esi, 24(%r9)
24104 + movl %edi, 28(%r9)
24105 popq_cfi %rbp
24106 popq_cfi %rbx
24107 + pax_force_retaddr
24108 ret
24109 3:
24110 CFI_RESTORE_STATE
24111 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
24112 index fc6ba17..04471c5 100644
24113 --- a/arch/x86/lib/putuser.S
24114 +++ b/arch/x86/lib/putuser.S
24115 @@ -16,7 +16,9 @@
24116 #include <asm/errno.h>
24117 #include <asm/asm.h>
24118 #include <asm/smap.h>
24119 -
24120 +#include <asm/segment.h>
24121 +#include <asm/pgtable.h>
24122 +#include <asm/alternative-asm.h>
24123
24124 /*
24125 * __put_user_X
24126 @@ -30,57 +32,125 @@
24127 * as they get called from within inline assembly.
24128 */
24129
24130 -#define ENTER CFI_STARTPROC ; \
24131 - GET_THREAD_INFO(%_ASM_BX)
24132 -#define EXIT ASM_CLAC ; \
24133 - ret ; \
24134 +#define ENTER CFI_STARTPROC
24135 +#define EXIT ASM_CLAC ; \
24136 + pax_force_retaddr ; \
24137 + ret ; \
24138 CFI_ENDPROC
24139
24140 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24141 +#define _DEST %_ASM_CX,%_ASM_BX
24142 +#else
24143 +#define _DEST %_ASM_CX
24144 +#endif
24145 +
24146 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
24147 +#define __copyuser_seg gs;
24148 +#else
24149 +#define __copyuser_seg
24150 +#endif
24151 +
24152 .text
24153 ENTRY(__put_user_1)
24154 ENTER
24155 +
24156 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24157 + GET_THREAD_INFO(%_ASM_BX)
24158 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
24159 jae bad_put_user
24160 ASM_STAC
24161 -1: movb %al,(%_ASM_CX)
24162 +
24163 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24164 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
24165 + cmp %_ASM_BX,%_ASM_CX
24166 + jb 1234f
24167 + xor %ebx,%ebx
24168 +1234:
24169 +#endif
24170 +
24171 +#endif
24172 +
24173 +1: __copyuser_seg movb %al,(_DEST)
24174 xor %eax,%eax
24175 EXIT
24176 ENDPROC(__put_user_1)
24177
24178 ENTRY(__put_user_2)
24179 ENTER
24180 +
24181 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24182 + GET_THREAD_INFO(%_ASM_BX)
24183 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
24184 sub $1,%_ASM_BX
24185 cmp %_ASM_BX,%_ASM_CX
24186 jae bad_put_user
24187 ASM_STAC
24188 -2: movw %ax,(%_ASM_CX)
24189 +
24190 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24191 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
24192 + cmp %_ASM_BX,%_ASM_CX
24193 + jb 1234f
24194 + xor %ebx,%ebx
24195 +1234:
24196 +#endif
24197 +
24198 +#endif
24199 +
24200 +2: __copyuser_seg movw %ax,(_DEST)
24201 xor %eax,%eax
24202 EXIT
24203 ENDPROC(__put_user_2)
24204
24205 ENTRY(__put_user_4)
24206 ENTER
24207 +
24208 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24209 + GET_THREAD_INFO(%_ASM_BX)
24210 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
24211 sub $3,%_ASM_BX
24212 cmp %_ASM_BX,%_ASM_CX
24213 jae bad_put_user
24214 ASM_STAC
24215 -3: movl %eax,(%_ASM_CX)
24216 +
24217 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24218 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
24219 + cmp %_ASM_BX,%_ASM_CX
24220 + jb 1234f
24221 + xor %ebx,%ebx
24222 +1234:
24223 +#endif
24224 +
24225 +#endif
24226 +
24227 +3: __copyuser_seg movl %eax,(_DEST)
24228 xor %eax,%eax
24229 EXIT
24230 ENDPROC(__put_user_4)
24231
24232 ENTRY(__put_user_8)
24233 ENTER
24234 +
24235 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24236 + GET_THREAD_INFO(%_ASM_BX)
24237 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
24238 sub $7,%_ASM_BX
24239 cmp %_ASM_BX,%_ASM_CX
24240 jae bad_put_user
24241 ASM_STAC
24242 -4: mov %_ASM_AX,(%_ASM_CX)
24243 +
24244 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24245 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
24246 + cmp %_ASM_BX,%_ASM_CX
24247 + jb 1234f
24248 + xor %ebx,%ebx
24249 +1234:
24250 +#endif
24251 +
24252 +#endif
24253 +
24254 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
24255 #ifdef CONFIG_X86_32
24256 -5: movl %edx,4(%_ASM_CX)
24257 +5: __copyuser_seg movl %edx,4(_DEST)
24258 #endif
24259 xor %eax,%eax
24260 EXIT
24261 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
24262 index 1cad221..de671ee 100644
24263 --- a/arch/x86/lib/rwlock.S
24264 +++ b/arch/x86/lib/rwlock.S
24265 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
24266 FRAME
24267 0: LOCK_PREFIX
24268 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
24269 +
24270 +#ifdef CONFIG_PAX_REFCOUNT
24271 + jno 1234f
24272 + LOCK_PREFIX
24273 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
24274 + int $4
24275 +1234:
24276 + _ASM_EXTABLE(1234b, 1234b)
24277 +#endif
24278 +
24279 1: rep; nop
24280 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
24281 jne 1b
24282 LOCK_PREFIX
24283 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
24284 +
24285 +#ifdef CONFIG_PAX_REFCOUNT
24286 + jno 1234f
24287 + LOCK_PREFIX
24288 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
24289 + int $4
24290 +1234:
24291 + _ASM_EXTABLE(1234b, 1234b)
24292 +#endif
24293 +
24294 jnz 0b
24295 ENDFRAME
24296 + pax_force_retaddr
24297 ret
24298 CFI_ENDPROC
24299 END(__write_lock_failed)
24300 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
24301 FRAME
24302 0: LOCK_PREFIX
24303 READ_LOCK_SIZE(inc) (%__lock_ptr)
24304 +
24305 +#ifdef CONFIG_PAX_REFCOUNT
24306 + jno 1234f
24307 + LOCK_PREFIX
24308 + READ_LOCK_SIZE(dec) (%__lock_ptr)
24309 + int $4
24310 +1234:
24311 + _ASM_EXTABLE(1234b, 1234b)
24312 +#endif
24313 +
24314 1: rep; nop
24315 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
24316 js 1b
24317 LOCK_PREFIX
24318 READ_LOCK_SIZE(dec) (%__lock_ptr)
24319 +
24320 +#ifdef CONFIG_PAX_REFCOUNT
24321 + jno 1234f
24322 + LOCK_PREFIX
24323 + READ_LOCK_SIZE(inc) (%__lock_ptr)
24324 + int $4
24325 +1234:
24326 + _ASM_EXTABLE(1234b, 1234b)
24327 +#endif
24328 +
24329 js 0b
24330 ENDFRAME
24331 + pax_force_retaddr
24332 ret
24333 CFI_ENDPROC
24334 END(__read_lock_failed)
24335 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
24336 index 5dff5f0..cadebf4 100644
24337 --- a/arch/x86/lib/rwsem.S
24338 +++ b/arch/x86/lib/rwsem.S
24339 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
24340 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
24341 CFI_RESTORE __ASM_REG(dx)
24342 restore_common_regs
24343 + pax_force_retaddr
24344 ret
24345 CFI_ENDPROC
24346 ENDPROC(call_rwsem_down_read_failed)
24347 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
24348 movq %rax,%rdi
24349 call rwsem_down_write_failed
24350 restore_common_regs
24351 + pax_force_retaddr
24352 ret
24353 CFI_ENDPROC
24354 ENDPROC(call_rwsem_down_write_failed)
24355 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
24356 movq %rax,%rdi
24357 call rwsem_wake
24358 restore_common_regs
24359 -1: ret
24360 +1: pax_force_retaddr
24361 + ret
24362 CFI_ENDPROC
24363 ENDPROC(call_rwsem_wake)
24364
24365 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
24366 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
24367 CFI_RESTORE __ASM_REG(dx)
24368 restore_common_regs
24369 + pax_force_retaddr
24370 ret
24371 CFI_ENDPROC
24372 ENDPROC(call_rwsem_downgrade_wake)
24373 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
24374 index a63efd6..ccecad8 100644
24375 --- a/arch/x86/lib/thunk_64.S
24376 +++ b/arch/x86/lib/thunk_64.S
24377 @@ -8,6 +8,7 @@
24378 #include <linux/linkage.h>
24379 #include <asm/dwarf2.h>
24380 #include <asm/calling.h>
24381 +#include <asm/alternative-asm.h>
24382
24383 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
24384 .macro THUNK name, func, put_ret_addr_in_rdi=0
24385 @@ -41,5 +42,6 @@
24386 SAVE_ARGS
24387 restore:
24388 RESTORE_ARGS
24389 + pax_force_retaddr
24390 ret
24391 CFI_ENDPROC
24392 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
24393 index 98f6d6b6..d27f045 100644
24394 --- a/arch/x86/lib/usercopy_32.c
24395 +++ b/arch/x86/lib/usercopy_32.c
24396 @@ -42,11 +42,13 @@ do { \
24397 int __d0; \
24398 might_fault(); \
24399 __asm__ __volatile__( \
24400 + __COPYUSER_SET_ES \
24401 ASM_STAC "\n" \
24402 "0: rep; stosl\n" \
24403 " movl %2,%0\n" \
24404 "1: rep; stosb\n" \
24405 "2: " ASM_CLAC "\n" \
24406 + __COPYUSER_RESTORE_ES \
24407 ".section .fixup,\"ax\"\n" \
24408 "3: lea 0(%2,%0,4),%0\n" \
24409 " jmp 2b\n" \
24410 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
24411
24412 #ifdef CONFIG_X86_INTEL_USERCOPY
24413 static unsigned long
24414 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
24415 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
24416 {
24417 int d0, d1;
24418 __asm__ __volatile__(
24419 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
24420 " .align 2,0x90\n"
24421 "3: movl 0(%4), %%eax\n"
24422 "4: movl 4(%4), %%edx\n"
24423 - "5: movl %%eax, 0(%3)\n"
24424 - "6: movl %%edx, 4(%3)\n"
24425 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
24426 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
24427 "7: movl 8(%4), %%eax\n"
24428 "8: movl 12(%4),%%edx\n"
24429 - "9: movl %%eax, 8(%3)\n"
24430 - "10: movl %%edx, 12(%3)\n"
24431 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
24432 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
24433 "11: movl 16(%4), %%eax\n"
24434 "12: movl 20(%4), %%edx\n"
24435 - "13: movl %%eax, 16(%3)\n"
24436 - "14: movl %%edx, 20(%3)\n"
24437 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
24438 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
24439 "15: movl 24(%4), %%eax\n"
24440 "16: movl 28(%4), %%edx\n"
24441 - "17: movl %%eax, 24(%3)\n"
24442 - "18: movl %%edx, 28(%3)\n"
24443 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
24444 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
24445 "19: movl 32(%4), %%eax\n"
24446 "20: movl 36(%4), %%edx\n"
24447 - "21: movl %%eax, 32(%3)\n"
24448 - "22: movl %%edx, 36(%3)\n"
24449 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
24450 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
24451 "23: movl 40(%4), %%eax\n"
24452 "24: movl 44(%4), %%edx\n"
24453 - "25: movl %%eax, 40(%3)\n"
24454 - "26: movl %%edx, 44(%3)\n"
24455 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
24456 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
24457 "27: movl 48(%4), %%eax\n"
24458 "28: movl 52(%4), %%edx\n"
24459 - "29: movl %%eax, 48(%3)\n"
24460 - "30: movl %%edx, 52(%3)\n"
24461 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
24462 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
24463 "31: movl 56(%4), %%eax\n"
24464 "32: movl 60(%4), %%edx\n"
24465 - "33: movl %%eax, 56(%3)\n"
24466 - "34: movl %%edx, 60(%3)\n"
24467 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
24468 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
24469 " addl $-64, %0\n"
24470 " addl $64, %4\n"
24471 " addl $64, %3\n"
24472 @@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
24473 " shrl $2, %0\n"
24474 " andl $3, %%eax\n"
24475 " cld\n"
24476 + __COPYUSER_SET_ES
24477 "99: rep; movsl\n"
24478 "36: movl %%eax, %0\n"
24479 "37: rep; movsb\n"
24480 "100:\n"
24481 + __COPYUSER_RESTORE_ES
24482 ".section .fixup,\"ax\"\n"
24483 "101: lea 0(%%eax,%0,4),%0\n"
24484 " jmp 100b\n"
24485 @@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
24486 }
24487
24488 static unsigned long
24489 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
24490 +{
24491 + int d0, d1;
24492 + __asm__ __volatile__(
24493 + " .align 2,0x90\n"
24494 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
24495 + " cmpl $67, %0\n"
24496 + " jbe 3f\n"
24497 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
24498 + " .align 2,0x90\n"
24499 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
24500 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
24501 + "5: movl %%eax, 0(%3)\n"
24502 + "6: movl %%edx, 4(%3)\n"
24503 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
24504 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
24505 + "9: movl %%eax, 8(%3)\n"
24506 + "10: movl %%edx, 12(%3)\n"
24507 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
24508 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
24509 + "13: movl %%eax, 16(%3)\n"
24510 + "14: movl %%edx, 20(%3)\n"
24511 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
24512 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
24513 + "17: movl %%eax, 24(%3)\n"
24514 + "18: movl %%edx, 28(%3)\n"
24515 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
24516 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
24517 + "21: movl %%eax, 32(%3)\n"
24518 + "22: movl %%edx, 36(%3)\n"
24519 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
24520 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
24521 + "25: movl %%eax, 40(%3)\n"
24522 + "26: movl %%edx, 44(%3)\n"
24523 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
24524 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
24525 + "29: movl %%eax, 48(%3)\n"
24526 + "30: movl %%edx, 52(%3)\n"
24527 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
24528 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
24529 + "33: movl %%eax, 56(%3)\n"
24530 + "34: movl %%edx, 60(%3)\n"
24531 + " addl $-64, %0\n"
24532 + " addl $64, %4\n"
24533 + " addl $64, %3\n"
24534 + " cmpl $63, %0\n"
24535 + " ja 1b\n"
24536 + "35: movl %0, %%eax\n"
24537 + " shrl $2, %0\n"
24538 + " andl $3, %%eax\n"
24539 + " cld\n"
24540 + "99: rep; "__copyuser_seg" movsl\n"
24541 + "36: movl %%eax, %0\n"
24542 + "37: rep; "__copyuser_seg" movsb\n"
24543 + "100:\n"
24544 + ".section .fixup,\"ax\"\n"
24545 + "101: lea 0(%%eax,%0,4),%0\n"
24546 + " jmp 100b\n"
24547 + ".previous\n"
24548 + _ASM_EXTABLE(1b,100b)
24549 + _ASM_EXTABLE(2b,100b)
24550 + _ASM_EXTABLE(3b,100b)
24551 + _ASM_EXTABLE(4b,100b)
24552 + _ASM_EXTABLE(5b,100b)
24553 + _ASM_EXTABLE(6b,100b)
24554 + _ASM_EXTABLE(7b,100b)
24555 + _ASM_EXTABLE(8b,100b)
24556 + _ASM_EXTABLE(9b,100b)
24557 + _ASM_EXTABLE(10b,100b)
24558 + _ASM_EXTABLE(11b,100b)
24559 + _ASM_EXTABLE(12b,100b)
24560 + _ASM_EXTABLE(13b,100b)
24561 + _ASM_EXTABLE(14b,100b)
24562 + _ASM_EXTABLE(15b,100b)
24563 + _ASM_EXTABLE(16b,100b)
24564 + _ASM_EXTABLE(17b,100b)
24565 + _ASM_EXTABLE(18b,100b)
24566 + _ASM_EXTABLE(19b,100b)
24567 + _ASM_EXTABLE(20b,100b)
24568 + _ASM_EXTABLE(21b,100b)
24569 + _ASM_EXTABLE(22b,100b)
24570 + _ASM_EXTABLE(23b,100b)
24571 + _ASM_EXTABLE(24b,100b)
24572 + _ASM_EXTABLE(25b,100b)
24573 + _ASM_EXTABLE(26b,100b)
24574 + _ASM_EXTABLE(27b,100b)
24575 + _ASM_EXTABLE(28b,100b)
24576 + _ASM_EXTABLE(29b,100b)
24577 + _ASM_EXTABLE(30b,100b)
24578 + _ASM_EXTABLE(31b,100b)
24579 + _ASM_EXTABLE(32b,100b)
24580 + _ASM_EXTABLE(33b,100b)
24581 + _ASM_EXTABLE(34b,100b)
24582 + _ASM_EXTABLE(35b,100b)
24583 + _ASM_EXTABLE(36b,100b)
24584 + _ASM_EXTABLE(37b,100b)
24585 + _ASM_EXTABLE(99b,101b)
24586 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
24587 + : "1"(to), "2"(from), "0"(size)
24588 + : "eax", "edx", "memory");
24589 + return size;
24590 +}
24591 +
24592 +static unsigned long __size_overflow(3)
24593 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
24594 {
24595 int d0, d1;
24596 __asm__ __volatile__(
24597 " .align 2,0x90\n"
24598 - "0: movl 32(%4), %%eax\n"
24599 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
24600 " cmpl $67, %0\n"
24601 " jbe 2f\n"
24602 - "1: movl 64(%4), %%eax\n"
24603 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
24604 " .align 2,0x90\n"
24605 - "2: movl 0(%4), %%eax\n"
24606 - "21: movl 4(%4), %%edx\n"
24607 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
24608 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
24609 " movl %%eax, 0(%3)\n"
24610 " movl %%edx, 4(%3)\n"
24611 - "3: movl 8(%4), %%eax\n"
24612 - "31: movl 12(%4),%%edx\n"
24613 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
24614 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
24615 " movl %%eax, 8(%3)\n"
24616 " movl %%edx, 12(%3)\n"
24617 - "4: movl 16(%4), %%eax\n"
24618 - "41: movl 20(%4), %%edx\n"
24619 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
24620 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
24621 " movl %%eax, 16(%3)\n"
24622 " movl %%edx, 20(%3)\n"
24623 - "10: movl 24(%4), %%eax\n"
24624 - "51: movl 28(%4), %%edx\n"
24625 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
24626 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
24627 " movl %%eax, 24(%3)\n"
24628 " movl %%edx, 28(%3)\n"
24629 - "11: movl 32(%4), %%eax\n"
24630 - "61: movl 36(%4), %%edx\n"
24631 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
24632 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
24633 " movl %%eax, 32(%3)\n"
24634 " movl %%edx, 36(%3)\n"
24635 - "12: movl 40(%4), %%eax\n"
24636 - "71: movl 44(%4), %%edx\n"
24637 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
24638 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
24639 " movl %%eax, 40(%3)\n"
24640 " movl %%edx, 44(%3)\n"
24641 - "13: movl 48(%4), %%eax\n"
24642 - "81: movl 52(%4), %%edx\n"
24643 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
24644 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
24645 " movl %%eax, 48(%3)\n"
24646 " movl %%edx, 52(%3)\n"
24647 - "14: movl 56(%4), %%eax\n"
24648 - "91: movl 60(%4), %%edx\n"
24649 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
24650 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
24651 " movl %%eax, 56(%3)\n"
24652 " movl %%edx, 60(%3)\n"
24653 " addl $-64, %0\n"
24654 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
24655 " shrl $2, %0\n"
24656 " andl $3, %%eax\n"
24657 " cld\n"
24658 - "6: rep; movsl\n"
24659 + "6: rep; "__copyuser_seg" movsl\n"
24660 " movl %%eax,%0\n"
24661 - "7: rep; movsb\n"
24662 + "7: rep; "__copyuser_seg" movsb\n"
24663 "8:\n"
24664 ".section .fixup,\"ax\"\n"
24665 "9: lea 0(%%eax,%0,4),%0\n"
24666 @@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
24667 * hyoshiok@miraclelinux.com
24668 */
24669
24670 -static unsigned long __copy_user_zeroing_intel_nocache(void *to,
24671 +static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
24672 const void __user *from, unsigned long size)
24673 {
24674 int d0, d1;
24675
24676 __asm__ __volatile__(
24677 " .align 2,0x90\n"
24678 - "0: movl 32(%4), %%eax\n"
24679 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
24680 " cmpl $67, %0\n"
24681 " jbe 2f\n"
24682 - "1: movl 64(%4), %%eax\n"
24683 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
24684 " .align 2,0x90\n"
24685 - "2: movl 0(%4), %%eax\n"
24686 - "21: movl 4(%4), %%edx\n"
24687 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
24688 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
24689 " movnti %%eax, 0(%3)\n"
24690 " movnti %%edx, 4(%3)\n"
24691 - "3: movl 8(%4), %%eax\n"
24692 - "31: movl 12(%4),%%edx\n"
24693 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
24694 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
24695 " movnti %%eax, 8(%3)\n"
24696 " movnti %%edx, 12(%3)\n"
24697 - "4: movl 16(%4), %%eax\n"
24698 - "41: movl 20(%4), %%edx\n"
24699 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
24700 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
24701 " movnti %%eax, 16(%3)\n"
24702 " movnti %%edx, 20(%3)\n"
24703 - "10: movl 24(%4), %%eax\n"
24704 - "51: movl 28(%4), %%edx\n"
24705 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
24706 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
24707 " movnti %%eax, 24(%3)\n"
24708 " movnti %%edx, 28(%3)\n"
24709 - "11: movl 32(%4), %%eax\n"
24710 - "61: movl 36(%4), %%edx\n"
24711 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
24712 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
24713 " movnti %%eax, 32(%3)\n"
24714 " movnti %%edx, 36(%3)\n"
24715 - "12: movl 40(%4), %%eax\n"
24716 - "71: movl 44(%4), %%edx\n"
24717 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
24718 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
24719 " movnti %%eax, 40(%3)\n"
24720 " movnti %%edx, 44(%3)\n"
24721 - "13: movl 48(%4), %%eax\n"
24722 - "81: movl 52(%4), %%edx\n"
24723 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
24724 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
24725 " movnti %%eax, 48(%3)\n"
24726 " movnti %%edx, 52(%3)\n"
24727 - "14: movl 56(%4), %%eax\n"
24728 - "91: movl 60(%4), %%edx\n"
24729 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
24730 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
24731 " movnti %%eax, 56(%3)\n"
24732 " movnti %%edx, 60(%3)\n"
24733 " addl $-64, %0\n"
24734 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
24735 " shrl $2, %0\n"
24736 " andl $3, %%eax\n"
24737 " cld\n"
24738 - "6: rep; movsl\n"
24739 + "6: rep; "__copyuser_seg" movsl\n"
24740 " movl %%eax,%0\n"
24741 - "7: rep; movsb\n"
24742 + "7: rep; "__copyuser_seg" movsb\n"
24743 "8:\n"
24744 ".section .fixup,\"ax\"\n"
24745 "9: lea 0(%%eax,%0,4),%0\n"
24746 @@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
24747 return size;
24748 }
24749
24750 -static unsigned long __copy_user_intel_nocache(void *to,
24751 +static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
24752 const void __user *from, unsigned long size)
24753 {
24754 int d0, d1;
24755
24756 __asm__ __volatile__(
24757 " .align 2,0x90\n"
24758 - "0: movl 32(%4), %%eax\n"
24759 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
24760 " cmpl $67, %0\n"
24761 " jbe 2f\n"
24762 - "1: movl 64(%4), %%eax\n"
24763 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
24764 " .align 2,0x90\n"
24765 - "2: movl 0(%4), %%eax\n"
24766 - "21: movl 4(%4), %%edx\n"
24767 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
24768 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
24769 " movnti %%eax, 0(%3)\n"
24770 " movnti %%edx, 4(%3)\n"
24771 - "3: movl 8(%4), %%eax\n"
24772 - "31: movl 12(%4),%%edx\n"
24773 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
24774 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
24775 " movnti %%eax, 8(%3)\n"
24776 " movnti %%edx, 12(%3)\n"
24777 - "4: movl 16(%4), %%eax\n"
24778 - "41: movl 20(%4), %%edx\n"
24779 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
24780 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
24781 " movnti %%eax, 16(%3)\n"
24782 " movnti %%edx, 20(%3)\n"
24783 - "10: movl 24(%4), %%eax\n"
24784 - "51: movl 28(%4), %%edx\n"
24785 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
24786 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
24787 " movnti %%eax, 24(%3)\n"
24788 " movnti %%edx, 28(%3)\n"
24789 - "11: movl 32(%4), %%eax\n"
24790 - "61: movl 36(%4), %%edx\n"
24791 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
24792 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
24793 " movnti %%eax, 32(%3)\n"
24794 " movnti %%edx, 36(%3)\n"
24795 - "12: movl 40(%4), %%eax\n"
24796 - "71: movl 44(%4), %%edx\n"
24797 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
24798 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
24799 " movnti %%eax, 40(%3)\n"
24800 " movnti %%edx, 44(%3)\n"
24801 - "13: movl 48(%4), %%eax\n"
24802 - "81: movl 52(%4), %%edx\n"
24803 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
24804 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
24805 " movnti %%eax, 48(%3)\n"
24806 " movnti %%edx, 52(%3)\n"
24807 - "14: movl 56(%4), %%eax\n"
24808 - "91: movl 60(%4), %%edx\n"
24809 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
24810 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
24811 " movnti %%eax, 56(%3)\n"
24812 " movnti %%edx, 60(%3)\n"
24813 " addl $-64, %0\n"
24814 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
24815 " shrl $2, %0\n"
24816 " andl $3, %%eax\n"
24817 " cld\n"
24818 - "6: rep; movsl\n"
24819 + "6: rep; "__copyuser_seg" movsl\n"
24820 " movl %%eax,%0\n"
24821 - "7: rep; movsb\n"
24822 + "7: rep; "__copyuser_seg" movsb\n"
24823 "8:\n"
24824 ".section .fixup,\"ax\"\n"
24825 "9: lea 0(%%eax,%0,4),%0\n"
24826 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
24827 */
24828 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
24829 unsigned long size);
24830 -unsigned long __copy_user_intel(void __user *to, const void *from,
24831 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
24832 + unsigned long size);
24833 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
24834 unsigned long size);
24835 unsigned long __copy_user_zeroing_intel_nocache(void *to,
24836 const void __user *from, unsigned long size);
24837 #endif /* CONFIG_X86_INTEL_USERCOPY */
24838
24839 /* Generic arbitrary sized copy. */
24840 -#define __copy_user(to, from, size) \
24841 +#define __copy_user(to, from, size, prefix, set, restore) \
24842 do { \
24843 int __d0, __d1, __d2; \
24844 __asm__ __volatile__( \
24845 + set \
24846 " cmp $7,%0\n" \
24847 " jbe 1f\n" \
24848 " movl %1,%0\n" \
24849 " negl %0\n" \
24850 " andl $7,%0\n" \
24851 " subl %0,%3\n" \
24852 - "4: rep; movsb\n" \
24853 + "4: rep; "prefix"movsb\n" \
24854 " movl %3,%0\n" \
24855 " shrl $2,%0\n" \
24856 " andl $3,%3\n" \
24857 " .align 2,0x90\n" \
24858 - "0: rep; movsl\n" \
24859 + "0: rep; "prefix"movsl\n" \
24860 " movl %3,%0\n" \
24861 - "1: rep; movsb\n" \
24862 + "1: rep; "prefix"movsb\n" \
24863 "2:\n" \
24864 + restore \
24865 ".section .fixup,\"ax\"\n" \
24866 "5: addl %3,%0\n" \
24867 " jmp 2b\n" \
24868 @@ -538,14 +650,14 @@ do { \
24869 " negl %0\n" \
24870 " andl $7,%0\n" \
24871 " subl %0,%3\n" \
24872 - "4: rep; movsb\n" \
24873 + "4: rep; "__copyuser_seg"movsb\n" \
24874 " movl %3,%0\n" \
24875 " shrl $2,%0\n" \
24876 " andl $3,%3\n" \
24877 " .align 2,0x90\n" \
24878 - "0: rep; movsl\n" \
24879 + "0: rep; "__copyuser_seg"movsl\n" \
24880 " movl %3,%0\n" \
24881 - "1: rep; movsb\n" \
24882 + "1: rep; "__copyuser_seg"movsb\n" \
24883 "2:\n" \
24884 ".section .fixup,\"ax\"\n" \
24885 "5: addl %3,%0\n" \
24886 @@ -629,9 +741,9 @@ survive:
24887 #endif
24888 stac();
24889 if (movsl_is_ok(to, from, n))
24890 - __copy_user(to, from, n);
24891 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
24892 else
24893 - n = __copy_user_intel(to, from, n);
24894 + n = __generic_copy_to_user_intel(to, from, n);
24895 clac();
24896 return n;
24897 }
24898 @@ -655,10 +767,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
24899 {
24900 stac();
24901 if (movsl_is_ok(to, from, n))
24902 - __copy_user(to, from, n);
24903 + __copy_user(to, from, n, __copyuser_seg, "", "");
24904 else
24905 - n = __copy_user_intel((void __user *)to,
24906 - (const void *)from, n);
24907 + n = __generic_copy_from_user_intel(to, from, n);
24908 clac();
24909 return n;
24910 }
24911 @@ -689,66 +800,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
24912 if (n > 64 && cpu_has_xmm2)
24913 n = __copy_user_intel_nocache(to, from, n);
24914 else
24915 - __copy_user(to, from, n);
24916 + __copy_user(to, from, n, __copyuser_seg, "", "");
24917 #else
24918 - __copy_user(to, from, n);
24919 + __copy_user(to, from, n, __copyuser_seg, "", "");
24920 #endif
24921 clac();
24922 return n;
24923 }
24924 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
24925
24926 -/**
24927 - * copy_to_user: - Copy a block of data into user space.
24928 - * @to: Destination address, in user space.
24929 - * @from: Source address, in kernel space.
24930 - * @n: Number of bytes to copy.
24931 - *
24932 - * Context: User context only. This function may sleep.
24933 - *
24934 - * Copy data from kernel space to user space.
24935 - *
24936 - * Returns number of bytes that could not be copied.
24937 - * On success, this will be zero.
24938 - */
24939 -unsigned long
24940 -copy_to_user(void __user *to, const void *from, unsigned long n)
24941 -{
24942 - if (access_ok(VERIFY_WRITE, to, n))
24943 - n = __copy_to_user(to, from, n);
24944 - return n;
24945 -}
24946 -EXPORT_SYMBOL(copy_to_user);
24947 -
24948 -/**
24949 - * copy_from_user: - Copy a block of data from user space.
24950 - * @to: Destination address, in kernel space.
24951 - * @from: Source address, in user space.
24952 - * @n: Number of bytes to copy.
24953 - *
24954 - * Context: User context only. This function may sleep.
24955 - *
24956 - * Copy data from user space to kernel space.
24957 - *
24958 - * Returns number of bytes that could not be copied.
24959 - * On success, this will be zero.
24960 - *
24961 - * If some data could not be copied, this function will pad the copied
24962 - * data to the requested size using zero bytes.
24963 - */
24964 -unsigned long
24965 -_copy_from_user(void *to, const void __user *from, unsigned long n)
24966 -{
24967 - if (access_ok(VERIFY_READ, from, n))
24968 - n = __copy_from_user(to, from, n);
24969 - else
24970 - memset(to, 0, n);
24971 - return n;
24972 -}
24973 -EXPORT_SYMBOL(_copy_from_user);
24974 -
24975 void copy_from_user_overflow(void)
24976 {
24977 WARN(1, "Buffer overflow detected!\n");
24978 }
24979 EXPORT_SYMBOL(copy_from_user_overflow);
24980 +
24981 +void copy_to_user_overflow(void)
24982 +{
24983 + WARN(1, "Buffer overflow detected!\n");
24984 +}
24985 +EXPORT_SYMBOL(copy_to_user_overflow);
24986 +
24987 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24988 +void __set_fs(mm_segment_t x)
24989 +{
24990 + switch (x.seg) {
24991 + case 0:
24992 + loadsegment(gs, 0);
24993 + break;
24994 + case TASK_SIZE_MAX:
24995 + loadsegment(gs, __USER_DS);
24996 + break;
24997 + case -1UL:
24998 + loadsegment(gs, __KERNEL_DS);
24999 + break;
25000 + default:
25001 + BUG();
25002 + }
25003 + return;
25004 +}
25005 +EXPORT_SYMBOL(__set_fs);
25006 +
25007 +void set_fs(mm_segment_t x)
25008 +{
25009 + current_thread_info()->addr_limit = x;
25010 + __set_fs(x);
25011 +}
25012 +EXPORT_SYMBOL(set_fs);
25013 +#endif
25014 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
25015 index 05928aa..b33dea1 100644
25016 --- a/arch/x86/lib/usercopy_64.c
25017 +++ b/arch/x86/lib/usercopy_64.c
25018 @@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
25019 _ASM_EXTABLE(0b,3b)
25020 _ASM_EXTABLE(1b,2b)
25021 : [size8] "=&c"(size), [dst] "=&D" (__d0)
25022 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
25023 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
25024 [zero] "r" (0UL), [eight] "r" (8UL));
25025 clac();
25026 return size;
25027 @@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
25028 }
25029 EXPORT_SYMBOL(clear_user);
25030
25031 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
25032 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
25033 {
25034 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
25035 - return copy_user_generic((__force void *)to, (__force void *)from, len);
25036 - }
25037 - return len;
25038 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
25039 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
25040 + return len;
25041 }
25042 EXPORT_SYMBOL(copy_in_user);
25043
25044 @@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
25045 * it is not necessary to optimize tail handling.
25046 */
25047 unsigned long
25048 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
25049 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
25050 {
25051 char c;
25052 unsigned zero_len;
25053 @@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
25054 clac();
25055 return len;
25056 }
25057 +
25058 +void copy_from_user_overflow(void)
25059 +{
25060 + WARN(1, "Buffer overflow detected!\n");
25061 +}
25062 +EXPORT_SYMBOL(copy_from_user_overflow);
25063 +
25064 +void copy_to_user_overflow(void)
25065 +{
25066 + WARN(1, "Buffer overflow detected!\n");
25067 +}
25068 +EXPORT_SYMBOL(copy_to_user_overflow);
25069 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
25070 index 903ec1e..c4166b2 100644
25071 --- a/arch/x86/mm/extable.c
25072 +++ b/arch/x86/mm/extable.c
25073 @@ -6,12 +6,24 @@
25074 static inline unsigned long
25075 ex_insn_addr(const struct exception_table_entry *x)
25076 {
25077 - return (unsigned long)&x->insn + x->insn;
25078 + unsigned long reloc = 0;
25079 +
25080 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25081 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25082 +#endif
25083 +
25084 + return (unsigned long)&x->insn + x->insn + reloc;
25085 }
25086 static inline unsigned long
25087 ex_fixup_addr(const struct exception_table_entry *x)
25088 {
25089 - return (unsigned long)&x->fixup + x->fixup;
25090 + unsigned long reloc = 0;
25091 +
25092 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25093 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25094 +#endif
25095 +
25096 + return (unsigned long)&x->fixup + x->fixup + reloc;
25097 }
25098
25099 int fixup_exception(struct pt_regs *regs)
25100 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
25101 unsigned long new_ip;
25102
25103 #ifdef CONFIG_PNPBIOS
25104 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
25105 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
25106 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
25107 extern u32 pnp_bios_is_utter_crap;
25108 pnp_bios_is_utter_crap = 1;
25109 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
25110 i += 4;
25111 p->fixup -= i;
25112 i += 4;
25113 +
25114 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25115 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
25116 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25117 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25118 +#endif
25119 +
25120 }
25121 }
25122
25123 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
25124 index 8e13ecb..60bf506 100644
25125 --- a/arch/x86/mm/fault.c
25126 +++ b/arch/x86/mm/fault.c
25127 @@ -13,12 +13,19 @@
25128 #include <linux/perf_event.h> /* perf_sw_event */
25129 #include <linux/hugetlb.h> /* hstate_index_to_shift */
25130 #include <linux/prefetch.h> /* prefetchw */
25131 +#include <linux/unistd.h>
25132 +#include <linux/compiler.h>
25133
25134 #include <asm/traps.h> /* dotraplinkage, ... */
25135 #include <asm/pgalloc.h> /* pgd_*(), ... */
25136 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
25137 #include <asm/fixmap.h> /* VSYSCALL_START */
25138 #include <asm/rcu.h> /* exception_enter(), ... */
25139 +#include <asm/tlbflush.h>
25140 +
25141 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25142 +#include <asm/stacktrace.h>
25143 +#endif
25144
25145 /*
25146 * Page fault error code bits:
25147 @@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
25148 int ret = 0;
25149
25150 /* kprobe_running() needs smp_processor_id() */
25151 - if (kprobes_built_in() && !user_mode_vm(regs)) {
25152 + if (kprobes_built_in() && !user_mode(regs)) {
25153 preempt_disable();
25154 if (kprobe_running() && kprobe_fault_handler(regs, 14))
25155 ret = 1;
25156 @@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
25157 return !instr_lo || (instr_lo>>1) == 1;
25158 case 0x00:
25159 /* Prefetch instruction is 0x0F0D or 0x0F18 */
25160 - if (probe_kernel_address(instr, opcode))
25161 + if (user_mode(regs)) {
25162 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
25163 + return 0;
25164 + } else if (probe_kernel_address(instr, opcode))
25165 return 0;
25166
25167 *prefetch = (instr_lo == 0xF) &&
25168 @@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
25169 while (instr < max_instr) {
25170 unsigned char opcode;
25171
25172 - if (probe_kernel_address(instr, opcode))
25173 + if (user_mode(regs)) {
25174 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
25175 + break;
25176 + } else if (probe_kernel_address(instr, opcode))
25177 break;
25178
25179 instr++;
25180 @@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
25181 force_sig_info(si_signo, &info, tsk);
25182 }
25183
25184 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25185 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
25186 +#endif
25187 +
25188 +#ifdef CONFIG_PAX_EMUTRAMP
25189 +static int pax_handle_fetch_fault(struct pt_regs *regs);
25190 +#endif
25191 +
25192 +#ifdef CONFIG_PAX_PAGEEXEC
25193 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
25194 +{
25195 + pgd_t *pgd;
25196 + pud_t *pud;
25197 + pmd_t *pmd;
25198 +
25199 + pgd = pgd_offset(mm, address);
25200 + if (!pgd_present(*pgd))
25201 + return NULL;
25202 + pud = pud_offset(pgd, address);
25203 + if (!pud_present(*pud))
25204 + return NULL;
25205 + pmd = pmd_offset(pud, address);
25206 + if (!pmd_present(*pmd))
25207 + return NULL;
25208 + return pmd;
25209 +}
25210 +#endif
25211 +
25212 DEFINE_SPINLOCK(pgd_lock);
25213 LIST_HEAD(pgd_list);
25214
25215 @@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
25216 for (address = VMALLOC_START & PMD_MASK;
25217 address >= TASK_SIZE && address < FIXADDR_TOP;
25218 address += PMD_SIZE) {
25219 +
25220 +#ifdef CONFIG_PAX_PER_CPU_PGD
25221 + unsigned long cpu;
25222 +#else
25223 struct page *page;
25224 +#endif
25225
25226 spin_lock(&pgd_lock);
25227 +
25228 +#ifdef CONFIG_PAX_PER_CPU_PGD
25229 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25230 + pgd_t *pgd = get_cpu_pgd(cpu);
25231 + pmd_t *ret;
25232 +#else
25233 list_for_each_entry(page, &pgd_list, lru) {
25234 + pgd_t *pgd = page_address(page);
25235 spinlock_t *pgt_lock;
25236 pmd_t *ret;
25237
25238 @@ -243,8 +296,13 @@ void vmalloc_sync_all(void)
25239 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25240
25241 spin_lock(pgt_lock);
25242 - ret = vmalloc_sync_one(page_address(page), address);
25243 +#endif
25244 +
25245 + ret = vmalloc_sync_one(pgd, address);
25246 +
25247 +#ifndef CONFIG_PAX_PER_CPU_PGD
25248 spin_unlock(pgt_lock);
25249 +#endif
25250
25251 if (!ret)
25252 break;
25253 @@ -278,6 +336,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
25254 * an interrupt in the middle of a task switch..
25255 */
25256 pgd_paddr = read_cr3();
25257 +
25258 +#ifdef CONFIG_PAX_PER_CPU_PGD
25259 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
25260 +#endif
25261 +
25262 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
25263 if (!pmd_k)
25264 return -1;
25265 @@ -373,7 +436,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
25266 * happen within a race in page table update. In the later
25267 * case just flush:
25268 */
25269 +
25270 +#ifdef CONFIG_PAX_PER_CPU_PGD
25271 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
25272 + pgd = pgd_offset_cpu(smp_processor_id(), address);
25273 +#else
25274 pgd = pgd_offset(current->active_mm, address);
25275 +#endif
25276 +
25277 pgd_ref = pgd_offset_k(address);
25278 if (pgd_none(*pgd_ref))
25279 return -1;
25280 @@ -541,7 +611,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
25281 static int is_errata100(struct pt_regs *regs, unsigned long address)
25282 {
25283 #ifdef CONFIG_X86_64
25284 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
25285 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
25286 return 1;
25287 #endif
25288 return 0;
25289 @@ -568,7 +638,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
25290 }
25291
25292 static const char nx_warning[] = KERN_CRIT
25293 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
25294 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
25295
25296 static void
25297 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
25298 @@ -577,15 +647,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
25299 if (!oops_may_print())
25300 return;
25301
25302 - if (error_code & PF_INSTR) {
25303 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
25304 unsigned int level;
25305
25306 pte_t *pte = lookup_address(address, &level);
25307
25308 if (pte && pte_present(*pte) && !pte_exec(*pte))
25309 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
25310 + printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
25311 }
25312
25313 +#ifdef CONFIG_PAX_KERNEXEC
25314 + if (init_mm.start_code <= address && address < init_mm.end_code) {
25315 + if (current->signal->curr_ip)
25316 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
25317 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
25318 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
25319 + else
25320 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
25321 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
25322 + }
25323 +#endif
25324 +
25325 printk(KERN_ALERT "BUG: unable to handle kernel ");
25326 if (address < PAGE_SIZE)
25327 printk(KERN_CONT "NULL pointer dereference");
25328 @@ -749,12 +831,30 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
25329 }
25330 #endif
25331
25332 - if (unlikely(show_unhandled_signals))
25333 - show_signal_msg(regs, error_code, address, tsk);
25334 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25335 + if (pax_is_fetch_fault(regs, error_code, address)) {
25336 +
25337 +#ifdef CONFIG_PAX_EMUTRAMP
25338 + switch (pax_handle_fetch_fault(regs)) {
25339 + case 2:
25340 + return;
25341 + }
25342 +#endif
25343 +
25344 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
25345 + do_group_exit(SIGKILL);
25346 + }
25347 +#endif
25348
25349 /* Kernel addresses are always protection faults: */
25350 + if (address >= TASK_SIZE)
25351 + error_code |= PF_PROT;
25352 +
25353 + if (show_unhandled_signals)
25354 + show_signal_msg(regs, error_code, address, tsk);
25355 +
25356 tsk->thread.cr2 = address;
25357 - tsk->thread.error_code = error_code | (address >= TASK_SIZE);
25358 + tsk->thread.error_code = error_code;
25359 tsk->thread.trap_nr = X86_TRAP_PF;
25360
25361 force_sig_info_fault(SIGSEGV, si_code, address, tsk, 0);
25362 @@ -845,7 +945,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
25363 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
25364 printk(KERN_ERR
25365 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
25366 - tsk->comm, tsk->pid, address);
25367 + tsk->comm, task_pid_nr(tsk), address);
25368 code = BUS_MCEERR_AR;
25369 }
25370 #endif
25371 @@ -901,6 +1001,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
25372 return 1;
25373 }
25374
25375 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
25376 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
25377 +{
25378 + pte_t *pte;
25379 + pmd_t *pmd;
25380 + spinlock_t *ptl;
25381 + unsigned char pte_mask;
25382 +
25383 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
25384 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
25385 + return 0;
25386 +
25387 + /* PaX: it's our fault, let's handle it if we can */
25388 +
25389 + /* PaX: take a look at read faults before acquiring any locks */
25390 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
25391 + /* instruction fetch attempt from a protected page in user mode */
25392 + up_read(&mm->mmap_sem);
25393 +
25394 +#ifdef CONFIG_PAX_EMUTRAMP
25395 + switch (pax_handle_fetch_fault(regs)) {
25396 + case 2:
25397 + return 1;
25398 + }
25399 +#endif
25400 +
25401 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
25402 + do_group_exit(SIGKILL);
25403 + }
25404 +
25405 + pmd = pax_get_pmd(mm, address);
25406 + if (unlikely(!pmd))
25407 + return 0;
25408 +
25409 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
25410 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
25411 + pte_unmap_unlock(pte, ptl);
25412 + return 0;
25413 + }
25414 +
25415 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
25416 + /* write attempt to a protected page in user mode */
25417 + pte_unmap_unlock(pte, ptl);
25418 + return 0;
25419 + }
25420 +
25421 +#ifdef CONFIG_SMP
25422 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
25423 +#else
25424 + if (likely(address > get_limit(regs->cs)))
25425 +#endif
25426 + {
25427 + set_pte(pte, pte_mkread(*pte));
25428 + __flush_tlb_one(address);
25429 + pte_unmap_unlock(pte, ptl);
25430 + up_read(&mm->mmap_sem);
25431 + return 1;
25432 + }
25433 +
25434 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
25435 +
25436 + /*
25437 + * PaX: fill DTLB with user rights and retry
25438 + */
25439 + __asm__ __volatile__ (
25440 + "orb %2,(%1)\n"
25441 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
25442 +/*
25443 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
25444 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
25445 + * page fault when examined during a TLB load attempt. this is true not only
25446 + * for PTEs holding a non-present entry but also present entries that will
25447 + * raise a page fault (such as those set up by PaX, or the copy-on-write
25448 + * mechanism). in effect it means that we do *not* need to flush the TLBs
25449 + * for our target pages since their PTEs are simply not in the TLBs at all.
25450 +
25451 + * the best thing in omitting it is that we gain around 15-20% speed in the
25452 + * fast path of the page fault handler and can get rid of tracing since we
25453 + * can no longer flush unintended entries.
25454 + */
25455 + "invlpg (%0)\n"
25456 +#endif
25457 + __copyuser_seg"testb $0,(%0)\n"
25458 + "xorb %3,(%1)\n"
25459 + :
25460 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
25461 + : "memory", "cc");
25462 + pte_unmap_unlock(pte, ptl);
25463 + up_read(&mm->mmap_sem);
25464 + return 1;
25465 +}
25466 +#endif
25467 +
25468 /*
25469 * Handle a spurious fault caused by a stale TLB entry.
25470 *
25471 @@ -973,6 +1166,9 @@ int show_unhandled_signals = 1;
25472 static inline int
25473 access_error(unsigned long error_code, struct vm_area_struct *vma)
25474 {
25475 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
25476 + return 1;
25477 +
25478 if (error_code & PF_WRITE) {
25479 /* write, present and write, not present: */
25480 if (unlikely(!(vma->vm_flags & VM_WRITE)))
25481 @@ -1001,7 +1197,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
25482 if (error_code & PF_USER)
25483 return false;
25484
25485 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
25486 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
25487 return false;
25488
25489 return true;
25490 @@ -1017,18 +1213,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
25491 {
25492 struct vm_area_struct *vma;
25493 struct task_struct *tsk;
25494 - unsigned long address;
25495 struct mm_struct *mm;
25496 int fault;
25497 int write = error_code & PF_WRITE;
25498 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
25499 (write ? FAULT_FLAG_WRITE : 0);
25500
25501 - tsk = current;
25502 - mm = tsk->mm;
25503 -
25504 /* Get the faulting address: */
25505 - address = read_cr2();
25506 + unsigned long address = read_cr2();
25507 +
25508 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25509 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
25510 + if (!search_exception_tables(regs->ip)) {
25511 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
25512 + bad_area_nosemaphore(regs, error_code, address);
25513 + return;
25514 + }
25515 + if (address < PAX_USER_SHADOW_BASE) {
25516 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
25517 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
25518 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
25519 + } else
25520 + address -= PAX_USER_SHADOW_BASE;
25521 + }
25522 +#endif
25523 +
25524 + tsk = current;
25525 + mm = tsk->mm;
25526
25527 /*
25528 * Detect and handle instructions that would cause a page fault for
25529 @@ -1089,7 +1300,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
25530 * User-mode registers count as a user access even for any
25531 * potential system fault or CPU buglet:
25532 */
25533 - if (user_mode_vm(regs)) {
25534 + if (user_mode(regs)) {
25535 local_irq_enable();
25536 error_code |= PF_USER;
25537 } else {
25538 @@ -1151,6 +1362,11 @@ retry:
25539 might_sleep();
25540 }
25541
25542 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
25543 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
25544 + return;
25545 +#endif
25546 +
25547 vma = find_vma(mm, address);
25548 if (unlikely(!vma)) {
25549 bad_area(regs, error_code, address);
25550 @@ -1162,18 +1378,24 @@ retry:
25551 bad_area(regs, error_code, address);
25552 return;
25553 }
25554 - if (error_code & PF_USER) {
25555 - /*
25556 - * Accessing the stack below %sp is always a bug.
25557 - * The large cushion allows instructions like enter
25558 - * and pusha to work. ("enter $65535, $31" pushes
25559 - * 32 pointers and then decrements %sp by 65535.)
25560 - */
25561 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
25562 - bad_area(regs, error_code, address);
25563 - return;
25564 - }
25565 + /*
25566 + * Accessing the stack below %sp is always a bug.
25567 + * The large cushion allows instructions like enter
25568 + * and pusha to work. ("enter $65535, $31" pushes
25569 + * 32 pointers and then decrements %sp by 65535.)
25570 + */
25571 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
25572 + bad_area(regs, error_code, address);
25573 + return;
25574 }
25575 +
25576 +#ifdef CONFIG_PAX_SEGMEXEC
25577 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
25578 + bad_area(regs, error_code, address);
25579 + return;
25580 + }
25581 +#endif
25582 +
25583 if (unlikely(expand_stack(vma, address))) {
25584 bad_area(regs, error_code, address);
25585 return;
25586 @@ -1237,3 +1459,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
25587 __do_page_fault(regs, error_code);
25588 exception_exit(regs);
25589 }
25590 +
25591 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25592 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
25593 +{
25594 + struct mm_struct *mm = current->mm;
25595 + unsigned long ip = regs->ip;
25596 +
25597 + if (v8086_mode(regs))
25598 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
25599 +
25600 +#ifdef CONFIG_PAX_PAGEEXEC
25601 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
25602 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
25603 + return true;
25604 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
25605 + return true;
25606 + return false;
25607 + }
25608 +#endif
25609 +
25610 +#ifdef CONFIG_PAX_SEGMEXEC
25611 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
25612 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
25613 + return true;
25614 + return false;
25615 + }
25616 +#endif
25617 +
25618 + return false;
25619 +}
25620 +#endif
25621 +
25622 +#ifdef CONFIG_PAX_EMUTRAMP
25623 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
25624 +{
25625 + int err;
25626 +
25627 + do { /* PaX: libffi trampoline emulation */
25628 + unsigned char mov, jmp;
25629 + unsigned int addr1, addr2;
25630 +
25631 +#ifdef CONFIG_X86_64
25632 + if ((regs->ip + 9) >> 32)
25633 + break;
25634 +#endif
25635 +
25636 + err = get_user(mov, (unsigned char __user *)regs->ip);
25637 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
25638 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
25639 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
25640 +
25641 + if (err)
25642 + break;
25643 +
25644 + if (mov == 0xB8 && jmp == 0xE9) {
25645 + regs->ax = addr1;
25646 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
25647 + return 2;
25648 + }
25649 + } while (0);
25650 +
25651 + do { /* PaX: gcc trampoline emulation #1 */
25652 + unsigned char mov1, mov2;
25653 + unsigned short jmp;
25654 + unsigned int addr1, addr2;
25655 +
25656 +#ifdef CONFIG_X86_64
25657 + if ((regs->ip + 11) >> 32)
25658 + break;
25659 +#endif
25660 +
25661 + err = get_user(mov1, (unsigned char __user *)regs->ip);
25662 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
25663 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
25664 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
25665 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
25666 +
25667 + if (err)
25668 + break;
25669 +
25670 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
25671 + regs->cx = addr1;
25672 + regs->ax = addr2;
25673 + regs->ip = addr2;
25674 + return 2;
25675 + }
25676 + } while (0);
25677 +
25678 + do { /* PaX: gcc trampoline emulation #2 */
25679 + unsigned char mov, jmp;
25680 + unsigned int addr1, addr2;
25681 +
25682 +#ifdef CONFIG_X86_64
25683 + if ((regs->ip + 9) >> 32)
25684 + break;
25685 +#endif
25686 +
25687 + err = get_user(mov, (unsigned char __user *)regs->ip);
25688 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
25689 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
25690 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
25691 +
25692 + if (err)
25693 + break;
25694 +
25695 + if (mov == 0xB9 && jmp == 0xE9) {
25696 + regs->cx = addr1;
25697 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
25698 + return 2;
25699 + }
25700 + } while (0);
25701 +
25702 + return 1; /* PaX in action */
25703 +}
25704 +
25705 +#ifdef CONFIG_X86_64
25706 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
25707 +{
25708 + int err;
25709 +
25710 + do { /* PaX: libffi trampoline emulation */
25711 + unsigned short mov1, mov2, jmp1;
25712 + unsigned char stcclc, jmp2;
25713 + unsigned long addr1, addr2;
25714 +
25715 + err = get_user(mov1, (unsigned short __user *)regs->ip);
25716 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
25717 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
25718 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
25719 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
25720 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
25721 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
25722 +
25723 + if (err)
25724 + break;
25725 +
25726 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
25727 + regs->r11 = addr1;
25728 + regs->r10 = addr2;
25729 + if (stcclc == 0xF8)
25730 + regs->flags &= ~X86_EFLAGS_CF;
25731 + else
25732 + regs->flags |= X86_EFLAGS_CF;
25733 + regs->ip = addr1;
25734 + return 2;
25735 + }
25736 + } while (0);
25737 +
25738 + do { /* PaX: gcc trampoline emulation #1 */
25739 + unsigned short mov1, mov2, jmp1;
25740 + unsigned char jmp2;
25741 + unsigned int addr1;
25742 + unsigned long addr2;
25743 +
25744 + err = get_user(mov1, (unsigned short __user *)regs->ip);
25745 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
25746 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
25747 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
25748 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
25749 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
25750 +
25751 + if (err)
25752 + break;
25753 +
25754 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
25755 + regs->r11 = addr1;
25756 + regs->r10 = addr2;
25757 + regs->ip = addr1;
25758 + return 2;
25759 + }
25760 + } while (0);
25761 +
25762 + do { /* PaX: gcc trampoline emulation #2 */
25763 + unsigned short mov1, mov2, jmp1;
25764 + unsigned char jmp2;
25765 + unsigned long addr1, addr2;
25766 +
25767 + err = get_user(mov1, (unsigned short __user *)regs->ip);
25768 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
25769 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
25770 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
25771 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
25772 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
25773 +
25774 + if (err)
25775 + break;
25776 +
25777 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
25778 + regs->r11 = addr1;
25779 + regs->r10 = addr2;
25780 + regs->ip = addr1;
25781 + return 2;
25782 + }
25783 + } while (0);
25784 +
25785 + return 1; /* PaX in action */
25786 +}
25787 +#endif
25788 +
25789 +/*
25790 + * PaX: decide what to do with offenders (regs->ip = fault address)
25791 + *
25792 + * returns 1 when task should be killed
25793 + * 2 when gcc trampoline was detected
25794 + */
25795 +static int pax_handle_fetch_fault(struct pt_regs *regs)
25796 +{
25797 + if (v8086_mode(regs))
25798 + return 1;
25799 +
25800 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
25801 + return 1;
25802 +
25803 +#ifdef CONFIG_X86_32
25804 + return pax_handle_fetch_fault_32(regs);
25805 +#else
25806 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
25807 + return pax_handle_fetch_fault_32(regs);
25808 + else
25809 + return pax_handle_fetch_fault_64(regs);
25810 +#endif
25811 +}
25812 +#endif
25813 +
25814 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25815 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
25816 +{
25817 + long i;
25818 +
25819 + printk(KERN_ERR "PAX: bytes at PC: ");
25820 + for (i = 0; i < 20; i++) {
25821 + unsigned char c;
25822 + if (get_user(c, (unsigned char __force_user *)pc+i))
25823 + printk(KERN_CONT "?? ");
25824 + else
25825 + printk(KERN_CONT "%02x ", c);
25826 + }
25827 + printk("\n");
25828 +
25829 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
25830 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
25831 + unsigned long c;
25832 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
25833 +#ifdef CONFIG_X86_32
25834 + printk(KERN_CONT "???????? ");
25835 +#else
25836 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
25837 + printk(KERN_CONT "???????? ???????? ");
25838 + else
25839 + printk(KERN_CONT "???????????????? ");
25840 +#endif
25841 + } else {
25842 +#ifdef CONFIG_X86_64
25843 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
25844 + printk(KERN_CONT "%08x ", (unsigned int)c);
25845 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
25846 + } else
25847 +#endif
25848 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
25849 + }
25850 + }
25851 + printk("\n");
25852 +}
25853 +#endif
25854 +
25855 +/**
25856 + * probe_kernel_write(): safely attempt to write to a location
25857 + * @dst: address to write to
25858 + * @src: pointer to the data that shall be written
25859 + * @size: size of the data chunk
25860 + *
25861 + * Safely write to address @dst from the buffer at @src. If a kernel fault
25862 + * happens, handle that and return -EFAULT.
25863 + */
25864 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
25865 +{
25866 + long ret;
25867 + mm_segment_t old_fs = get_fs();
25868 +
25869 + set_fs(KERNEL_DS);
25870 + pagefault_disable();
25871 + pax_open_kernel();
25872 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
25873 + pax_close_kernel();
25874 + pagefault_enable();
25875 + set_fs(old_fs);
25876 +
25877 + return ret ? -EFAULT : 0;
25878 +}
25879 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
25880 index dd74e46..7d26398 100644
25881 --- a/arch/x86/mm/gup.c
25882 +++ b/arch/x86/mm/gup.c
25883 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
25884 addr = start;
25885 len = (unsigned long) nr_pages << PAGE_SHIFT;
25886 end = start + len;
25887 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
25888 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
25889 (void __user *)start, len)))
25890 return 0;
25891
25892 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
25893 index 6f31ee5..8ee4164 100644
25894 --- a/arch/x86/mm/highmem_32.c
25895 +++ b/arch/x86/mm/highmem_32.c
25896 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
25897 idx = type + KM_TYPE_NR*smp_processor_id();
25898 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25899 BUG_ON(!pte_none(*(kmap_pte-idx)));
25900 +
25901 + pax_open_kernel();
25902 set_pte(kmap_pte-idx, mk_pte(page, prot));
25903 + pax_close_kernel();
25904 +
25905 arch_flush_lazy_mmu_mode();
25906
25907 return (void *)vaddr;
25908 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
25909 index 937bff5..dce75ff 100644
25910 --- a/arch/x86/mm/hugetlbpage.c
25911 +++ b/arch/x86/mm/hugetlbpage.c
25912 @@ -276,13 +276,21 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
25913 struct hstate *h = hstate_file(file);
25914 struct mm_struct *mm = current->mm;
25915 struct vm_area_struct *vma;
25916 - unsigned long start_addr;
25917 + unsigned long start_addr, pax_task_size = TASK_SIZE;
25918 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
25919 +
25920 +#ifdef CONFIG_PAX_SEGMEXEC
25921 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25922 + pax_task_size = SEGMEXEC_TASK_SIZE;
25923 +#endif
25924 +
25925 + pax_task_size -= PAGE_SIZE;
25926
25927 if (len > mm->cached_hole_size) {
25928 - start_addr = mm->free_area_cache;
25929 + start_addr = mm->free_area_cache;
25930 } else {
25931 - start_addr = TASK_UNMAPPED_BASE;
25932 - mm->cached_hole_size = 0;
25933 + start_addr = mm->mmap_base;
25934 + mm->cached_hole_size = 0;
25935 }
25936
25937 full_search:
25938 @@ -290,26 +298,27 @@ full_search:
25939
25940 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
25941 /* At this point: (!vma || addr < vma->vm_end). */
25942 - if (TASK_SIZE - len < addr) {
25943 + if (pax_task_size - len < addr) {
25944 /*
25945 * Start a new search - just in case we missed
25946 * some holes.
25947 */
25948 - if (start_addr != TASK_UNMAPPED_BASE) {
25949 - start_addr = TASK_UNMAPPED_BASE;
25950 + if (start_addr != mm->mmap_base) {
25951 + start_addr = mm->mmap_base;
25952 mm->cached_hole_size = 0;
25953 goto full_search;
25954 }
25955 return -ENOMEM;
25956 }
25957 - if (!vma || addr + len <= vma->vm_start) {
25958 - mm->free_area_cache = addr + len;
25959 - return addr;
25960 - }
25961 + if (check_heap_stack_gap(vma, addr, len, offset))
25962 + break;
25963 if (addr + mm->cached_hole_size < vma->vm_start)
25964 mm->cached_hole_size = vma->vm_start - addr;
25965 addr = ALIGN(vma->vm_end, huge_page_size(h));
25966 }
25967 +
25968 + mm->free_area_cache = addr + len;
25969 + return addr;
25970 }
25971
25972 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
25973 @@ -320,9 +329,9 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
25974 struct mm_struct *mm = current->mm;
25975 struct vm_area_struct *vma;
25976 unsigned long base = mm->mmap_base;
25977 - unsigned long addr = addr0;
25978 + unsigned long addr;
25979 unsigned long largest_hole = mm->cached_hole_size;
25980 - unsigned long start_addr;
25981 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
25982
25983 /* don't allow allocations above current base */
25984 if (mm->free_area_cache > base)
25985 @@ -332,16 +341,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
25986 largest_hole = 0;
25987 mm->free_area_cache = base;
25988 }
25989 -try_again:
25990 - start_addr = mm->free_area_cache;
25991
25992 /* make sure it can fit in the remaining address space */
25993 if (mm->free_area_cache < len)
25994 goto fail;
25995
25996 /* either no address requested or can't fit in requested address hole */
25997 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
25998 + addr = mm->free_area_cache - len;
25999 do {
26000 + addr &= huge_page_mask(h);
26001 /*
26002 * Lookup failure means no vma is above this address,
26003 * i.e. return with success:
26004 @@ -350,10 +358,10 @@ try_again:
26005 if (!vma)
26006 return addr;
26007
26008 - if (addr + len <= vma->vm_start) {
26009 + if (check_heap_stack_gap(vma, addr, len, offset)) {
26010 /* remember the address as a hint for next time */
26011 - mm->cached_hole_size = largest_hole;
26012 - return (mm->free_area_cache = addr);
26013 + mm->cached_hole_size = largest_hole;
26014 + return (mm->free_area_cache = addr);
26015 } else if (mm->free_area_cache == vma->vm_end) {
26016 /* pull free_area_cache down to the first hole */
26017 mm->free_area_cache = vma->vm_start;
26018 @@ -362,29 +370,34 @@ try_again:
26019
26020 /* remember the largest hole we saw so far */
26021 if (addr + largest_hole < vma->vm_start)
26022 - largest_hole = vma->vm_start - addr;
26023 + largest_hole = vma->vm_start - addr;
26024
26025 /* try just below the current vma->vm_start */
26026 - addr = (vma->vm_start - len) & huge_page_mask(h);
26027 - } while (len <= vma->vm_start);
26028 + addr = skip_heap_stack_gap(vma, len, offset);
26029 + } while (!IS_ERR_VALUE(addr));
26030
26031 fail:
26032 /*
26033 - * if hint left us with no space for the requested
26034 - * mapping then try again:
26035 - */
26036 - if (start_addr != base) {
26037 - mm->free_area_cache = base;
26038 - largest_hole = 0;
26039 - goto try_again;
26040 - }
26041 - /*
26042 * A failed mmap() very likely causes application failure,
26043 * so fall back to the bottom-up function here. This scenario
26044 * can happen with large stack limits and large mmap()
26045 * allocations.
26046 */
26047 - mm->free_area_cache = TASK_UNMAPPED_BASE;
26048 +
26049 +#ifdef CONFIG_PAX_SEGMEXEC
26050 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26051 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
26052 + else
26053 +#endif
26054 +
26055 + mm->mmap_base = TASK_UNMAPPED_BASE;
26056 +
26057 +#ifdef CONFIG_PAX_RANDMMAP
26058 + if (mm->pax_flags & MF_PAX_RANDMMAP)
26059 + mm->mmap_base += mm->delta_mmap;
26060 +#endif
26061 +
26062 + mm->free_area_cache = mm->mmap_base;
26063 mm->cached_hole_size = ~0UL;
26064 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
26065 len, pgoff, flags);
26066 @@ -392,6 +405,7 @@ fail:
26067 /*
26068 * Restore the topdown base:
26069 */
26070 + mm->mmap_base = base;
26071 mm->free_area_cache = base;
26072 mm->cached_hole_size = ~0UL;
26073
26074 @@ -405,10 +419,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
26075 struct hstate *h = hstate_file(file);
26076 struct mm_struct *mm = current->mm;
26077 struct vm_area_struct *vma;
26078 + unsigned long pax_task_size = TASK_SIZE;
26079 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
26080
26081 if (len & ~huge_page_mask(h))
26082 return -EINVAL;
26083 - if (len > TASK_SIZE)
26084 +
26085 +#ifdef CONFIG_PAX_SEGMEXEC
26086 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26087 + pax_task_size = SEGMEXEC_TASK_SIZE;
26088 +#endif
26089 +
26090 + pax_task_size -= PAGE_SIZE;
26091 +
26092 + if (len > pax_task_size)
26093 return -ENOMEM;
26094
26095 if (flags & MAP_FIXED) {
26096 @@ -417,11 +441,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
26097 return addr;
26098 }
26099
26100 +#ifdef CONFIG_PAX_RANDMMAP
26101 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26102 +#endif
26103 +
26104 if (addr) {
26105 addr = ALIGN(addr, huge_page_size(h));
26106 vma = find_vma(mm, addr);
26107 - if (TASK_SIZE - len >= addr &&
26108 - (!vma || addr + len <= vma->vm_start))
26109 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
26110 return addr;
26111 }
26112 if (mm->get_unmapped_area == arch_get_unmapped_area)
26113 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
26114 index d7aea41..0fc945b 100644
26115 --- a/arch/x86/mm/init.c
26116 +++ b/arch/x86/mm/init.c
26117 @@ -4,6 +4,7 @@
26118 #include <linux/swap.h>
26119 #include <linux/memblock.h>
26120 #include <linux/bootmem.h> /* for max_low_pfn */
26121 +#include <linux/tboot.h>
26122
26123 #include <asm/cacheflush.h>
26124 #include <asm/e820.h>
26125 @@ -16,6 +17,8 @@
26126 #include <asm/tlb.h>
26127 #include <asm/proto.h>
26128 #include <asm/dma.h> /* for MAX_DMA_PFN */
26129 +#include <asm/desc.h>
26130 +#include <asm/bios_ebda.h>
26131
26132 unsigned long __initdata pgt_buf_start;
26133 unsigned long __meminitdata pgt_buf_end;
26134 @@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
26135 {
26136 int i;
26137 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
26138 - unsigned long start = 0, good_end;
26139 + unsigned long start = 0x100000, good_end;
26140 phys_addr_t base;
26141
26142 for (i = 0; i < nr_range; i++) {
26143 @@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
26144 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
26145 * mmio resources as well as potential bios/acpi data regions.
26146 */
26147 +
26148 +#ifdef CONFIG_GRKERNSEC_KMEM
26149 +static unsigned int ebda_start __read_only;
26150 +static unsigned int ebda_end __read_only;
26151 +#endif
26152 +
26153 int devmem_is_allowed(unsigned long pagenr)
26154 {
26155 - if (pagenr < 256)
26156 +#ifdef CONFIG_GRKERNSEC_KMEM
26157 + /* allow BDA */
26158 + if (!pagenr)
26159 return 1;
26160 + /* allow EBDA */
26161 + if (pagenr >= ebda_start && pagenr < ebda_end)
26162 + return 1;
26163 + /* if tboot is in use, allow access to its hardcoded serial log range */
26164 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
26165 + return 1;
26166 +#else
26167 + if (!pagenr)
26168 + return 1;
26169 +#ifdef CONFIG_VM86
26170 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
26171 + return 1;
26172 +#endif
26173 +#endif
26174 +
26175 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
26176 + return 1;
26177 +#ifdef CONFIG_GRKERNSEC_KMEM
26178 + /* throw out everything else below 1MB */
26179 + if (pagenr <= 256)
26180 + return 0;
26181 +#endif
26182 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
26183 return 0;
26184 if (!page_is_ram(pagenr))
26185 @@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
26186 #endif
26187 }
26188
26189 +#ifdef CONFIG_GRKERNSEC_KMEM
26190 +static inline void gr_init_ebda(void)
26191 +{
26192 + unsigned int ebda_addr;
26193 + unsigned int ebda_size = 0;
26194 +
26195 + ebda_addr = get_bios_ebda();
26196 + if (ebda_addr) {
26197 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
26198 + ebda_size <<= 10;
26199 + }
26200 + if (ebda_addr && ebda_size) {
26201 + ebda_start = ebda_addr >> PAGE_SHIFT;
26202 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
26203 + } else {
26204 + ebda_start = 0x9f000 >> PAGE_SHIFT;
26205 + ebda_end = 0xa0000 >> PAGE_SHIFT;
26206 + }
26207 +}
26208 +#else
26209 +static inline void gr_init_ebda(void) { }
26210 +#endif
26211 +
26212 void free_initmem(void)
26213 {
26214 +#ifdef CONFIG_PAX_KERNEXEC
26215 +#ifdef CONFIG_X86_32
26216 + /* PaX: limit KERNEL_CS to actual size */
26217 + unsigned long addr, limit;
26218 + struct desc_struct d;
26219 + int cpu;
26220 +#else
26221 + pgd_t *pgd;
26222 + pud_t *pud;
26223 + pmd_t *pmd;
26224 + unsigned long addr, end;
26225 +#endif
26226 +#endif
26227 +
26228 + gr_init_ebda();
26229 +
26230 +#ifdef CONFIG_PAX_KERNEXEC
26231 +#ifdef CONFIG_X86_32
26232 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
26233 + limit = (limit - 1UL) >> PAGE_SHIFT;
26234 +
26235 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
26236 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26237 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
26238 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
26239 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
26240 + }
26241 +
26242 + /* PaX: make KERNEL_CS read-only */
26243 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
26244 + if (!paravirt_enabled())
26245 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
26246 +/*
26247 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
26248 + pgd = pgd_offset_k(addr);
26249 + pud = pud_offset(pgd, addr);
26250 + pmd = pmd_offset(pud, addr);
26251 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
26252 + }
26253 +*/
26254 +#ifdef CONFIG_X86_PAE
26255 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
26256 +/*
26257 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
26258 + pgd = pgd_offset_k(addr);
26259 + pud = pud_offset(pgd, addr);
26260 + pmd = pmd_offset(pud, addr);
26261 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
26262 + }
26263 +*/
26264 +#endif
26265 +
26266 +#ifdef CONFIG_MODULES
26267 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
26268 +#endif
26269 +
26270 +#else
26271 + /* PaX: make kernel code/rodata read-only, rest non-executable */
26272 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
26273 + pgd = pgd_offset_k(addr);
26274 + pud = pud_offset(pgd, addr);
26275 + pmd = pmd_offset(pud, addr);
26276 + if (!pmd_present(*pmd))
26277 + continue;
26278 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
26279 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
26280 + else
26281 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
26282 + }
26283 +
26284 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
26285 + end = addr + KERNEL_IMAGE_SIZE;
26286 + for (; addr < end; addr += PMD_SIZE) {
26287 + pgd = pgd_offset_k(addr);
26288 + pud = pud_offset(pgd, addr);
26289 + pmd = pmd_offset(pud, addr);
26290 + if (!pmd_present(*pmd))
26291 + continue;
26292 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
26293 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
26294 + }
26295 +#endif
26296 +
26297 + flush_tlb_all();
26298 +#endif
26299 +
26300 free_init_pages("unused kernel memory",
26301 (unsigned long)(&__init_begin),
26302 (unsigned long)(&__init_end));
26303 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
26304 index 11a5800..4bd9977 100644
26305 --- a/arch/x86/mm/init_32.c
26306 +++ b/arch/x86/mm/init_32.c
26307 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
26308 }
26309
26310 /*
26311 - * Creates a middle page table and puts a pointer to it in the
26312 - * given global directory entry. This only returns the gd entry
26313 - * in non-PAE compilation mode, since the middle layer is folded.
26314 - */
26315 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
26316 -{
26317 - pud_t *pud;
26318 - pmd_t *pmd_table;
26319 -
26320 -#ifdef CONFIG_X86_PAE
26321 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
26322 - if (after_bootmem)
26323 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
26324 - else
26325 - pmd_table = (pmd_t *)alloc_low_page();
26326 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
26327 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
26328 - pud = pud_offset(pgd, 0);
26329 - BUG_ON(pmd_table != pmd_offset(pud, 0));
26330 -
26331 - return pmd_table;
26332 - }
26333 -#endif
26334 - pud = pud_offset(pgd, 0);
26335 - pmd_table = pmd_offset(pud, 0);
26336 -
26337 - return pmd_table;
26338 -}
26339 -
26340 -/*
26341 * Create a page table and place a pointer to it in a middle page
26342 * directory entry:
26343 */
26344 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
26345 page_table = (pte_t *)alloc_low_page();
26346
26347 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
26348 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26349 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
26350 +#else
26351 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
26352 +#endif
26353 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
26354 }
26355
26356 return pte_offset_kernel(pmd, 0);
26357 }
26358
26359 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
26360 +{
26361 + pud_t *pud;
26362 + pmd_t *pmd_table;
26363 +
26364 + pud = pud_offset(pgd, 0);
26365 + pmd_table = pmd_offset(pud, 0);
26366 +
26367 + return pmd_table;
26368 +}
26369 +
26370 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
26371 {
26372 int pgd_idx = pgd_index(vaddr);
26373 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
26374 int pgd_idx, pmd_idx;
26375 unsigned long vaddr;
26376 pgd_t *pgd;
26377 + pud_t *pud;
26378 pmd_t *pmd;
26379 pte_t *pte = NULL;
26380
26381 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
26382 pgd = pgd_base + pgd_idx;
26383
26384 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
26385 - pmd = one_md_table_init(pgd);
26386 - pmd = pmd + pmd_index(vaddr);
26387 + pud = pud_offset(pgd, vaddr);
26388 + pmd = pmd_offset(pud, vaddr);
26389 +
26390 +#ifdef CONFIG_X86_PAE
26391 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
26392 +#endif
26393 +
26394 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
26395 pmd++, pmd_idx++) {
26396 pte = page_table_kmap_check(one_page_table_init(pmd),
26397 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
26398 }
26399 }
26400
26401 -static inline int is_kernel_text(unsigned long addr)
26402 +static inline int is_kernel_text(unsigned long start, unsigned long end)
26403 {
26404 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
26405 - return 1;
26406 - return 0;
26407 + if ((start > ktla_ktva((unsigned long)_etext) ||
26408 + end <= ktla_ktva((unsigned long)_stext)) &&
26409 + (start > ktla_ktva((unsigned long)_einittext) ||
26410 + end <= ktla_ktva((unsigned long)_sinittext)) &&
26411 +
26412 +#ifdef CONFIG_ACPI_SLEEP
26413 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
26414 +#endif
26415 +
26416 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
26417 + return 0;
26418 + return 1;
26419 }
26420
26421 /*
26422 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
26423 unsigned long last_map_addr = end;
26424 unsigned long start_pfn, end_pfn;
26425 pgd_t *pgd_base = swapper_pg_dir;
26426 - int pgd_idx, pmd_idx, pte_ofs;
26427 + unsigned int pgd_idx, pmd_idx, pte_ofs;
26428 unsigned long pfn;
26429 pgd_t *pgd;
26430 + pud_t *pud;
26431 pmd_t *pmd;
26432 pte_t *pte;
26433 unsigned pages_2m, pages_4k;
26434 @@ -280,8 +281,13 @@ repeat:
26435 pfn = start_pfn;
26436 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
26437 pgd = pgd_base + pgd_idx;
26438 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
26439 - pmd = one_md_table_init(pgd);
26440 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
26441 + pud = pud_offset(pgd, 0);
26442 + pmd = pmd_offset(pud, 0);
26443 +
26444 +#ifdef CONFIG_X86_PAE
26445 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
26446 +#endif
26447
26448 if (pfn >= end_pfn)
26449 continue;
26450 @@ -293,14 +299,13 @@ repeat:
26451 #endif
26452 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
26453 pmd++, pmd_idx++) {
26454 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
26455 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
26456
26457 /*
26458 * Map with big pages if possible, otherwise
26459 * create normal page tables:
26460 */
26461 if (use_pse) {
26462 - unsigned int addr2;
26463 pgprot_t prot = PAGE_KERNEL_LARGE;
26464 /*
26465 * first pass will use the same initial
26466 @@ -310,11 +315,7 @@ repeat:
26467 __pgprot(PTE_IDENT_ATTR |
26468 _PAGE_PSE);
26469
26470 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
26471 - PAGE_OFFSET + PAGE_SIZE-1;
26472 -
26473 - if (is_kernel_text(addr) ||
26474 - is_kernel_text(addr2))
26475 + if (is_kernel_text(address, address + PMD_SIZE))
26476 prot = PAGE_KERNEL_LARGE_EXEC;
26477
26478 pages_2m++;
26479 @@ -331,7 +332,7 @@ repeat:
26480 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
26481 pte += pte_ofs;
26482 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
26483 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
26484 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
26485 pgprot_t prot = PAGE_KERNEL;
26486 /*
26487 * first pass will use the same initial
26488 @@ -339,7 +340,7 @@ repeat:
26489 */
26490 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
26491
26492 - if (is_kernel_text(addr))
26493 + if (is_kernel_text(address, address + PAGE_SIZE))
26494 prot = PAGE_KERNEL_EXEC;
26495
26496 pages_4k++;
26497 @@ -465,7 +466,7 @@ void __init native_pagetable_init(void)
26498
26499 pud = pud_offset(pgd, va);
26500 pmd = pmd_offset(pud, va);
26501 - if (!pmd_present(*pmd))
26502 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
26503 break;
26504
26505 pte = pte_offset_kernel(pmd, va);
26506 @@ -514,12 +515,10 @@ void __init early_ioremap_page_table_range_init(void)
26507
26508 static void __init pagetable_init(void)
26509 {
26510 - pgd_t *pgd_base = swapper_pg_dir;
26511 -
26512 - permanent_kmaps_init(pgd_base);
26513 + permanent_kmaps_init(swapper_pg_dir);
26514 }
26515
26516 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
26517 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
26518 EXPORT_SYMBOL_GPL(__supported_pte_mask);
26519
26520 /* user-defined highmem size */
26521 @@ -731,6 +730,12 @@ void __init mem_init(void)
26522
26523 pci_iommu_alloc();
26524
26525 +#ifdef CONFIG_PAX_PER_CPU_PGD
26526 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
26527 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26528 + KERNEL_PGD_PTRS);
26529 +#endif
26530 +
26531 #ifdef CONFIG_FLATMEM
26532 BUG_ON(!mem_map);
26533 #endif
26534 @@ -757,7 +762,7 @@ void __init mem_init(void)
26535 reservedpages++;
26536
26537 codesize = (unsigned long) &_etext - (unsigned long) &_text;
26538 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
26539 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
26540 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
26541
26542 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
26543 @@ -798,10 +803,10 @@ void __init mem_init(void)
26544 ((unsigned long)&__init_end -
26545 (unsigned long)&__init_begin) >> 10,
26546
26547 - (unsigned long)&_etext, (unsigned long)&_edata,
26548 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
26549 + (unsigned long)&_sdata, (unsigned long)&_edata,
26550 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
26551
26552 - (unsigned long)&_text, (unsigned long)&_etext,
26553 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
26554 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
26555
26556 /*
26557 @@ -879,6 +884,7 @@ void set_kernel_text_rw(void)
26558 if (!kernel_set_to_readonly)
26559 return;
26560
26561 + start = ktla_ktva(start);
26562 pr_debug("Set kernel text: %lx - %lx for read write\n",
26563 start, start+size);
26564
26565 @@ -893,6 +899,7 @@ void set_kernel_text_ro(void)
26566 if (!kernel_set_to_readonly)
26567 return;
26568
26569 + start = ktla_ktva(start);
26570 pr_debug("Set kernel text: %lx - %lx for read only\n",
26571 start, start+size);
26572
26573 @@ -921,6 +928,7 @@ void mark_rodata_ro(void)
26574 unsigned long start = PFN_ALIGN(_text);
26575 unsigned long size = PFN_ALIGN(_etext) - start;
26576
26577 + start = ktla_ktva(start);
26578 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
26579 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
26580 size >> 10);
26581 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
26582 index 3baff25..8b37564 100644
26583 --- a/arch/x86/mm/init_64.c
26584 +++ b/arch/x86/mm/init_64.c
26585 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
26586 * around without checking the pgd every time.
26587 */
26588
26589 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
26590 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
26591 EXPORT_SYMBOL_GPL(__supported_pte_mask);
26592
26593 int force_personality32;
26594 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
26595
26596 for (address = start; address <= end; address += PGDIR_SIZE) {
26597 const pgd_t *pgd_ref = pgd_offset_k(address);
26598 +
26599 +#ifdef CONFIG_PAX_PER_CPU_PGD
26600 + unsigned long cpu;
26601 +#else
26602 struct page *page;
26603 +#endif
26604
26605 if (pgd_none(*pgd_ref))
26606 continue;
26607
26608 spin_lock(&pgd_lock);
26609 +
26610 +#ifdef CONFIG_PAX_PER_CPU_PGD
26611 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
26612 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
26613 +#else
26614 list_for_each_entry(page, &pgd_list, lru) {
26615 pgd_t *pgd;
26616 spinlock_t *pgt_lock;
26617 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
26618 /* the pgt_lock only for Xen */
26619 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
26620 spin_lock(pgt_lock);
26621 +#endif
26622
26623 if (pgd_none(*pgd))
26624 set_pgd(pgd, *pgd_ref);
26625 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
26626 BUG_ON(pgd_page_vaddr(*pgd)
26627 != pgd_page_vaddr(*pgd_ref));
26628
26629 +#ifndef CONFIG_PAX_PER_CPU_PGD
26630 spin_unlock(pgt_lock);
26631 +#endif
26632 +
26633 }
26634 spin_unlock(&pgd_lock);
26635 }
26636 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
26637 {
26638 if (pgd_none(*pgd)) {
26639 pud_t *pud = (pud_t *)spp_getpage();
26640 - pgd_populate(&init_mm, pgd, pud);
26641 + pgd_populate_kernel(&init_mm, pgd, pud);
26642 if (pud != pud_offset(pgd, 0))
26643 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
26644 pud, pud_offset(pgd, 0));
26645 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
26646 {
26647 if (pud_none(*pud)) {
26648 pmd_t *pmd = (pmd_t *) spp_getpage();
26649 - pud_populate(&init_mm, pud, pmd);
26650 + pud_populate_kernel(&init_mm, pud, pmd);
26651 if (pmd != pmd_offset(pud, 0))
26652 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
26653 pmd, pmd_offset(pud, 0));
26654 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
26655 pmd = fill_pmd(pud, vaddr);
26656 pte = fill_pte(pmd, vaddr);
26657
26658 + pax_open_kernel();
26659 set_pte(pte, new_pte);
26660 + pax_close_kernel();
26661
26662 /*
26663 * It's enough to flush this one mapping.
26664 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
26665 pgd = pgd_offset_k((unsigned long)__va(phys));
26666 if (pgd_none(*pgd)) {
26667 pud = (pud_t *) spp_getpage();
26668 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
26669 - _PAGE_USER));
26670 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
26671 }
26672 pud = pud_offset(pgd, (unsigned long)__va(phys));
26673 if (pud_none(*pud)) {
26674 pmd = (pmd_t *) spp_getpage();
26675 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
26676 - _PAGE_USER));
26677 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
26678 }
26679 pmd = pmd_offset(pud, phys);
26680 BUG_ON(!pmd_none(*pmd));
26681 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
26682 if (pfn >= pgt_buf_top)
26683 panic("alloc_low_page: ran out of memory");
26684
26685 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
26686 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
26687 clear_page(adr);
26688 *phys = pfn * PAGE_SIZE;
26689 return adr;
26690 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
26691
26692 phys = __pa(virt);
26693 left = phys & (PAGE_SIZE - 1);
26694 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
26695 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
26696 adr = (void *)(((unsigned long)adr) | left);
26697
26698 return adr;
26699 @@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
26700 unmap_low_page(pmd);
26701
26702 spin_lock(&init_mm.page_table_lock);
26703 - pud_populate(&init_mm, pud, __va(pmd_phys));
26704 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
26705 spin_unlock(&init_mm.page_table_lock);
26706 }
26707 __flush_tlb_all();
26708 @@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
26709 unmap_low_page(pud);
26710
26711 spin_lock(&init_mm.page_table_lock);
26712 - pgd_populate(&init_mm, pgd, __va(pud_phys));
26713 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
26714 spin_unlock(&init_mm.page_table_lock);
26715 pgd_changed = true;
26716 }
26717 @@ -691,6 +705,12 @@ void __init mem_init(void)
26718
26719 pci_iommu_alloc();
26720
26721 +#ifdef CONFIG_PAX_PER_CPU_PGD
26722 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
26723 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26724 + KERNEL_PGD_PTRS);
26725 +#endif
26726 +
26727 /* clear_bss() already clear the empty_zero_page */
26728
26729 reservedpages = 0;
26730 @@ -851,8 +871,8 @@ int kern_addr_valid(unsigned long addr)
26731 static struct vm_area_struct gate_vma = {
26732 .vm_start = VSYSCALL_START,
26733 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
26734 - .vm_page_prot = PAGE_READONLY_EXEC,
26735 - .vm_flags = VM_READ | VM_EXEC
26736 + .vm_page_prot = PAGE_READONLY,
26737 + .vm_flags = VM_READ
26738 };
26739
26740 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
26741 @@ -886,7 +906,7 @@ int in_gate_area_no_mm(unsigned long addr)
26742
26743 const char *arch_vma_name(struct vm_area_struct *vma)
26744 {
26745 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26746 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26747 return "[vdso]";
26748 if (vma == &gate_vma)
26749 return "[vsyscall]";
26750 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
26751 index 7b179b4..6bd1777 100644
26752 --- a/arch/x86/mm/iomap_32.c
26753 +++ b/arch/x86/mm/iomap_32.c
26754 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
26755 type = kmap_atomic_idx_push();
26756 idx = type + KM_TYPE_NR * smp_processor_id();
26757 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
26758 +
26759 + pax_open_kernel();
26760 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
26761 + pax_close_kernel();
26762 +
26763 arch_flush_lazy_mmu_mode();
26764
26765 return (void *)vaddr;
26766 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
26767 index 78fe3f1..2f9433c 100644
26768 --- a/arch/x86/mm/ioremap.c
26769 +++ b/arch/x86/mm/ioremap.c
26770 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
26771 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
26772 int is_ram = page_is_ram(pfn);
26773
26774 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
26775 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
26776 return NULL;
26777 WARN_ON_ONCE(is_ram);
26778 }
26779 @@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
26780 *
26781 * Caller must ensure there is only one unmapping for the same pointer.
26782 */
26783 -void iounmap(volatile void __iomem *addr)
26784 +void iounmap(const volatile void __iomem *addr)
26785 {
26786 struct vm_struct *p, *o;
26787
26788 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
26789
26790 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
26791 if (page_is_ram(start >> PAGE_SHIFT))
26792 +#ifdef CONFIG_HIGHMEM
26793 + if ((start >> PAGE_SHIFT) < max_low_pfn)
26794 +#endif
26795 return __va(phys);
26796
26797 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
26798 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
26799 early_param("early_ioremap_debug", early_ioremap_debug_setup);
26800
26801 static __initdata int after_paging_init;
26802 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
26803 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
26804
26805 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
26806 {
26807 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
26808 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
26809
26810 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
26811 - memset(bm_pte, 0, sizeof(bm_pte));
26812 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
26813 + pmd_populate_user(&init_mm, pmd, bm_pte);
26814
26815 /*
26816 * The boot-ioremap range spans multiple pmds, for which
26817 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
26818 index d87dd6d..bf3fa66 100644
26819 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
26820 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
26821 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
26822 * memory (e.g. tracked pages)? For now, we need this to avoid
26823 * invoking kmemcheck for PnP BIOS calls.
26824 */
26825 - if (regs->flags & X86_VM_MASK)
26826 + if (v8086_mode(regs))
26827 return false;
26828 - if (regs->cs != __KERNEL_CS)
26829 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
26830 return false;
26831
26832 pte = kmemcheck_pte_lookup(address);
26833 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
26834 index 845df68..1d8d29f 100644
26835 --- a/arch/x86/mm/mmap.c
26836 +++ b/arch/x86/mm/mmap.c
26837 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
26838 * Leave an at least ~128 MB hole with possible stack randomization.
26839 */
26840 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
26841 -#define MAX_GAP (TASK_SIZE/6*5)
26842 +#define MAX_GAP (pax_task_size/6*5)
26843
26844 static int mmap_is_legacy(void)
26845 {
26846 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
26847 return rnd << PAGE_SHIFT;
26848 }
26849
26850 -static unsigned long mmap_base(void)
26851 +static unsigned long mmap_base(struct mm_struct *mm)
26852 {
26853 unsigned long gap = rlimit(RLIMIT_STACK);
26854 + unsigned long pax_task_size = TASK_SIZE;
26855 +
26856 +#ifdef CONFIG_PAX_SEGMEXEC
26857 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26858 + pax_task_size = SEGMEXEC_TASK_SIZE;
26859 +#endif
26860
26861 if (gap < MIN_GAP)
26862 gap = MIN_GAP;
26863 else if (gap > MAX_GAP)
26864 gap = MAX_GAP;
26865
26866 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
26867 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
26868 }
26869
26870 /*
26871 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
26872 * does, but not when emulating X86_32
26873 */
26874 -static unsigned long mmap_legacy_base(void)
26875 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
26876 {
26877 - if (mmap_is_ia32())
26878 + if (mmap_is_ia32()) {
26879 +
26880 +#ifdef CONFIG_PAX_SEGMEXEC
26881 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26882 + return SEGMEXEC_TASK_UNMAPPED_BASE;
26883 + else
26884 +#endif
26885 +
26886 return TASK_UNMAPPED_BASE;
26887 - else
26888 + } else
26889 return TASK_UNMAPPED_BASE + mmap_rnd();
26890 }
26891
26892 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
26893 void arch_pick_mmap_layout(struct mm_struct *mm)
26894 {
26895 if (mmap_is_legacy()) {
26896 - mm->mmap_base = mmap_legacy_base();
26897 + mm->mmap_base = mmap_legacy_base(mm);
26898 +
26899 +#ifdef CONFIG_PAX_RANDMMAP
26900 + if (mm->pax_flags & MF_PAX_RANDMMAP)
26901 + mm->mmap_base += mm->delta_mmap;
26902 +#endif
26903 +
26904 mm->get_unmapped_area = arch_get_unmapped_area;
26905 mm->unmap_area = arch_unmap_area;
26906 } else {
26907 - mm->mmap_base = mmap_base();
26908 + mm->mmap_base = mmap_base(mm);
26909 +
26910 +#ifdef CONFIG_PAX_RANDMMAP
26911 + if (mm->pax_flags & MF_PAX_RANDMMAP)
26912 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
26913 +#endif
26914 +
26915 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
26916 mm->unmap_area = arch_unmap_area_topdown;
26917 }
26918 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
26919 index dc0b727..f612039 100644
26920 --- a/arch/x86/mm/mmio-mod.c
26921 +++ b/arch/x86/mm/mmio-mod.c
26922 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
26923 break;
26924 default:
26925 {
26926 - unsigned char *ip = (unsigned char *)instptr;
26927 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
26928 my_trace->opcode = MMIO_UNKNOWN_OP;
26929 my_trace->width = 0;
26930 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
26931 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
26932 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
26933 void __iomem *addr)
26934 {
26935 - static atomic_t next_id;
26936 + static atomic_unchecked_t next_id;
26937 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
26938 /* These are page-unaligned. */
26939 struct mmiotrace_map map = {
26940 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
26941 .private = trace
26942 },
26943 .phys = offset,
26944 - .id = atomic_inc_return(&next_id)
26945 + .id = atomic_inc_return_unchecked(&next_id)
26946 };
26947 map.map_id = trace->id;
26948
26949 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
26950 ioremap_trace_core(offset, size, addr);
26951 }
26952
26953 -static void iounmap_trace_core(volatile void __iomem *addr)
26954 +static void iounmap_trace_core(const volatile void __iomem *addr)
26955 {
26956 struct mmiotrace_map map = {
26957 .phys = 0,
26958 @@ -328,7 +328,7 @@ not_enabled:
26959 }
26960 }
26961
26962 -void mmiotrace_iounmap(volatile void __iomem *addr)
26963 +void mmiotrace_iounmap(const volatile void __iomem *addr)
26964 {
26965 might_sleep();
26966 if (is_enabled()) /* recheck and proper locking in *_core() */
26967 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
26968 index b008656..773eac2 100644
26969 --- a/arch/x86/mm/pageattr-test.c
26970 +++ b/arch/x86/mm/pageattr-test.c
26971 @@ -36,7 +36,7 @@ enum {
26972
26973 static int pte_testbit(pte_t pte)
26974 {
26975 - return pte_flags(pte) & _PAGE_UNUSED1;
26976 + return pte_flags(pte) & _PAGE_CPA_TEST;
26977 }
26978
26979 struct split_state {
26980 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
26981 index a718e0d..77419bc 100644
26982 --- a/arch/x86/mm/pageattr.c
26983 +++ b/arch/x86/mm/pageattr.c
26984 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26985 */
26986 #ifdef CONFIG_PCI_BIOS
26987 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
26988 - pgprot_val(forbidden) |= _PAGE_NX;
26989 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
26990 #endif
26991
26992 /*
26993 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26994 * Does not cover __inittext since that is gone later on. On
26995 * 64bit we do not enforce !NX on the low mapping
26996 */
26997 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
26998 - pgprot_val(forbidden) |= _PAGE_NX;
26999 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
27000 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
27001
27002 +#ifdef CONFIG_DEBUG_RODATA
27003 /*
27004 * The .rodata section needs to be read-only. Using the pfn
27005 * catches all aliases.
27006 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
27007 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
27008 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
27009 pgprot_val(forbidden) |= _PAGE_RW;
27010 +#endif
27011
27012 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
27013 /*
27014 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
27015 }
27016 #endif
27017
27018 +#ifdef CONFIG_PAX_KERNEXEC
27019 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
27020 + pgprot_val(forbidden) |= _PAGE_RW;
27021 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
27022 + }
27023 +#endif
27024 +
27025 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
27026
27027 return prot;
27028 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
27029 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
27030 {
27031 /* change init_mm */
27032 + pax_open_kernel();
27033 set_pte_atomic(kpte, pte);
27034 +
27035 #ifdef CONFIG_X86_32
27036 if (!SHARED_KERNEL_PMD) {
27037 +
27038 +#ifdef CONFIG_PAX_PER_CPU_PGD
27039 + unsigned long cpu;
27040 +#else
27041 struct page *page;
27042 +#endif
27043
27044 +#ifdef CONFIG_PAX_PER_CPU_PGD
27045 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
27046 + pgd_t *pgd = get_cpu_pgd(cpu);
27047 +#else
27048 list_for_each_entry(page, &pgd_list, lru) {
27049 - pgd_t *pgd;
27050 + pgd_t *pgd = (pgd_t *)page_address(page);
27051 +#endif
27052 +
27053 pud_t *pud;
27054 pmd_t *pmd;
27055
27056 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
27057 + pgd += pgd_index(address);
27058 pud = pud_offset(pgd, address);
27059 pmd = pmd_offset(pud, address);
27060 set_pte_atomic((pte_t *)pmd, pte);
27061 }
27062 }
27063 #endif
27064 + pax_close_kernel();
27065 }
27066
27067 static int
27068 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
27069 index 0eb572e..92f5c1e 100644
27070 --- a/arch/x86/mm/pat.c
27071 +++ b/arch/x86/mm/pat.c
27072 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
27073
27074 if (!entry) {
27075 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
27076 - current->comm, current->pid, start, end - 1);
27077 + current->comm, task_pid_nr(current), start, end - 1);
27078 return -EINVAL;
27079 }
27080
27081 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27082
27083 while (cursor < to) {
27084 if (!devmem_is_allowed(pfn)) {
27085 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
27086 - current->comm, from, to - 1);
27087 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
27088 + current->comm, from, to - 1, cursor);
27089 return 0;
27090 }
27091 cursor += PAGE_SIZE;
27092 @@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
27093 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
27094 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
27095 "for [mem %#010Lx-%#010Lx]\n",
27096 - current->comm, current->pid,
27097 + current->comm, task_pid_nr(current),
27098 cattr_name(flags),
27099 base, (unsigned long long)(base + size-1));
27100 return -EINVAL;
27101 @@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
27102 flags = lookup_memtype(paddr);
27103 if (want_flags != flags) {
27104 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
27105 - current->comm, current->pid,
27106 + current->comm, task_pid_nr(current),
27107 cattr_name(want_flags),
27108 (unsigned long long)paddr,
27109 (unsigned long long)(paddr + size - 1),
27110 @@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
27111 free_memtype(paddr, paddr + size);
27112 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
27113 " for [mem %#010Lx-%#010Lx], got %s\n",
27114 - current->comm, current->pid,
27115 + current->comm, task_pid_nr(current),
27116 cattr_name(want_flags),
27117 (unsigned long long)paddr,
27118 (unsigned long long)(paddr + size - 1),
27119 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
27120 index 9f0614d..92ae64a 100644
27121 --- a/arch/x86/mm/pf_in.c
27122 +++ b/arch/x86/mm/pf_in.c
27123 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
27124 int i;
27125 enum reason_type rv = OTHERS;
27126
27127 - p = (unsigned char *)ins_addr;
27128 + p = (unsigned char *)ktla_ktva(ins_addr);
27129 p += skip_prefix(p, &prf);
27130 p += get_opcode(p, &opcode);
27131
27132 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
27133 struct prefix_bits prf;
27134 int i;
27135
27136 - p = (unsigned char *)ins_addr;
27137 + p = (unsigned char *)ktla_ktva(ins_addr);
27138 p += skip_prefix(p, &prf);
27139 p += get_opcode(p, &opcode);
27140
27141 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
27142 struct prefix_bits prf;
27143 int i;
27144
27145 - p = (unsigned char *)ins_addr;
27146 + p = (unsigned char *)ktla_ktva(ins_addr);
27147 p += skip_prefix(p, &prf);
27148 p += get_opcode(p, &opcode);
27149
27150 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
27151 struct prefix_bits prf;
27152 int i;
27153
27154 - p = (unsigned char *)ins_addr;
27155 + p = (unsigned char *)ktla_ktva(ins_addr);
27156 p += skip_prefix(p, &prf);
27157 p += get_opcode(p, &opcode);
27158 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
27159 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
27160 struct prefix_bits prf;
27161 int i;
27162
27163 - p = (unsigned char *)ins_addr;
27164 + p = (unsigned char *)ktla_ktva(ins_addr);
27165 p += skip_prefix(p, &prf);
27166 p += get_opcode(p, &opcode);
27167 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
27168 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
27169 index 8573b83..4f3ed7e 100644
27170 --- a/arch/x86/mm/pgtable.c
27171 +++ b/arch/x86/mm/pgtable.c
27172 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
27173 list_del(&page->lru);
27174 }
27175
27176 -#define UNSHARED_PTRS_PER_PGD \
27177 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
27178 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27179 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
27180
27181 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
27182 +{
27183 + unsigned int count = USER_PGD_PTRS;
27184
27185 + while (count--)
27186 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
27187 +}
27188 +#endif
27189 +
27190 +#ifdef CONFIG_PAX_PER_CPU_PGD
27191 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
27192 +{
27193 + unsigned int count = USER_PGD_PTRS;
27194 +
27195 + while (count--) {
27196 + pgd_t pgd;
27197 +
27198 +#ifdef CONFIG_X86_64
27199 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
27200 +#else
27201 + pgd = *src++;
27202 +#endif
27203 +
27204 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27205 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
27206 +#endif
27207 +
27208 + *dst++ = pgd;
27209 + }
27210 +
27211 +}
27212 +#endif
27213 +
27214 +#ifdef CONFIG_X86_64
27215 +#define pxd_t pud_t
27216 +#define pyd_t pgd_t
27217 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
27218 +#define pxd_free(mm, pud) pud_free((mm), (pud))
27219 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
27220 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
27221 +#define PYD_SIZE PGDIR_SIZE
27222 +#else
27223 +#define pxd_t pmd_t
27224 +#define pyd_t pud_t
27225 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
27226 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
27227 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
27228 +#define pyd_offset(mm, address) pud_offset((mm), (address))
27229 +#define PYD_SIZE PUD_SIZE
27230 +#endif
27231 +
27232 +#ifdef CONFIG_PAX_PER_CPU_PGD
27233 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
27234 +static inline void pgd_dtor(pgd_t *pgd) {}
27235 +#else
27236 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
27237 {
27238 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
27239 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
27240 pgd_list_del(pgd);
27241 spin_unlock(&pgd_lock);
27242 }
27243 +#endif
27244
27245 /*
27246 * List of all pgd's needed for non-PAE so it can invalidate entries
27247 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
27248 * -- wli
27249 */
27250
27251 -#ifdef CONFIG_X86_PAE
27252 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
27253 /*
27254 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
27255 * updating the top-level pagetable entries to guarantee the
27256 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
27257 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
27258 * and initialize the kernel pmds here.
27259 */
27260 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
27261 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
27262
27263 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
27264 {
27265 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
27266 */
27267 flush_tlb_mm(mm);
27268 }
27269 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
27270 +#define PREALLOCATED_PXDS USER_PGD_PTRS
27271 #else /* !CONFIG_X86_PAE */
27272
27273 /* No need to prepopulate any pagetable entries in non-PAE modes. */
27274 -#define PREALLOCATED_PMDS 0
27275 +#define PREALLOCATED_PXDS 0
27276
27277 #endif /* CONFIG_X86_PAE */
27278
27279 -static void free_pmds(pmd_t *pmds[])
27280 +static void free_pxds(pxd_t *pxds[])
27281 {
27282 int i;
27283
27284 - for(i = 0; i < PREALLOCATED_PMDS; i++)
27285 - if (pmds[i])
27286 - free_page((unsigned long)pmds[i]);
27287 + for(i = 0; i < PREALLOCATED_PXDS; i++)
27288 + if (pxds[i])
27289 + free_page((unsigned long)pxds[i]);
27290 }
27291
27292 -static int preallocate_pmds(pmd_t *pmds[])
27293 +static int preallocate_pxds(pxd_t *pxds[])
27294 {
27295 int i;
27296 bool failed = false;
27297
27298 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
27299 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
27300 - if (pmd == NULL)
27301 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
27302 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
27303 + if (pxd == NULL)
27304 failed = true;
27305 - pmds[i] = pmd;
27306 + pxds[i] = pxd;
27307 }
27308
27309 if (failed) {
27310 - free_pmds(pmds);
27311 + free_pxds(pxds);
27312 return -ENOMEM;
27313 }
27314
27315 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
27316 * preallocate which never got a corresponding vma will need to be
27317 * freed manually.
27318 */
27319 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
27320 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
27321 {
27322 int i;
27323
27324 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
27325 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
27326 pgd_t pgd = pgdp[i];
27327
27328 if (pgd_val(pgd) != 0) {
27329 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
27330 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
27331
27332 - pgdp[i] = native_make_pgd(0);
27333 + set_pgd(pgdp + i, native_make_pgd(0));
27334
27335 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
27336 - pmd_free(mm, pmd);
27337 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
27338 + pxd_free(mm, pxd);
27339 }
27340 }
27341 }
27342
27343 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
27344 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
27345 {
27346 - pud_t *pud;
27347 + pyd_t *pyd;
27348 unsigned long addr;
27349 int i;
27350
27351 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
27352 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
27353 return;
27354
27355 - pud = pud_offset(pgd, 0);
27356 +#ifdef CONFIG_X86_64
27357 + pyd = pyd_offset(mm, 0L);
27358 +#else
27359 + pyd = pyd_offset(pgd, 0L);
27360 +#endif
27361
27362 - for (addr = i = 0; i < PREALLOCATED_PMDS;
27363 - i++, pud++, addr += PUD_SIZE) {
27364 - pmd_t *pmd = pmds[i];
27365 + for (addr = i = 0; i < PREALLOCATED_PXDS;
27366 + i++, pyd++, addr += PYD_SIZE) {
27367 + pxd_t *pxd = pxds[i];
27368
27369 if (i >= KERNEL_PGD_BOUNDARY)
27370 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
27371 - sizeof(pmd_t) * PTRS_PER_PMD);
27372 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
27373 + sizeof(pxd_t) * PTRS_PER_PMD);
27374
27375 - pud_populate(mm, pud, pmd);
27376 + pyd_populate(mm, pyd, pxd);
27377 }
27378 }
27379
27380 pgd_t *pgd_alloc(struct mm_struct *mm)
27381 {
27382 pgd_t *pgd;
27383 - pmd_t *pmds[PREALLOCATED_PMDS];
27384 + pxd_t *pxds[PREALLOCATED_PXDS];
27385
27386 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
27387
27388 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
27389
27390 mm->pgd = pgd;
27391
27392 - if (preallocate_pmds(pmds) != 0)
27393 + if (preallocate_pxds(pxds) != 0)
27394 goto out_free_pgd;
27395
27396 if (paravirt_pgd_alloc(mm) != 0)
27397 - goto out_free_pmds;
27398 + goto out_free_pxds;
27399
27400 /*
27401 * Make sure that pre-populating the pmds is atomic with
27402 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
27403 spin_lock(&pgd_lock);
27404
27405 pgd_ctor(mm, pgd);
27406 - pgd_prepopulate_pmd(mm, pgd, pmds);
27407 + pgd_prepopulate_pxd(mm, pgd, pxds);
27408
27409 spin_unlock(&pgd_lock);
27410
27411 return pgd;
27412
27413 -out_free_pmds:
27414 - free_pmds(pmds);
27415 +out_free_pxds:
27416 + free_pxds(pxds);
27417 out_free_pgd:
27418 free_page((unsigned long)pgd);
27419 out:
27420 @@ -295,7 +356,7 @@ out:
27421
27422 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
27423 {
27424 - pgd_mop_up_pmds(mm, pgd);
27425 + pgd_mop_up_pxds(mm, pgd);
27426 pgd_dtor(pgd);
27427 paravirt_pgd_free(mm, pgd);
27428 free_page((unsigned long)pgd);
27429 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
27430 index a69bcb8..19068ab 100644
27431 --- a/arch/x86/mm/pgtable_32.c
27432 +++ b/arch/x86/mm/pgtable_32.c
27433 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
27434 return;
27435 }
27436 pte = pte_offset_kernel(pmd, vaddr);
27437 +
27438 + pax_open_kernel();
27439 if (pte_val(pteval))
27440 set_pte_at(&init_mm, vaddr, pte, pteval);
27441 else
27442 pte_clear(&init_mm, vaddr, pte);
27443 + pax_close_kernel();
27444
27445 /*
27446 * It's enough to flush this one mapping.
27447 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
27448 index 410531d..0f16030 100644
27449 --- a/arch/x86/mm/setup_nx.c
27450 +++ b/arch/x86/mm/setup_nx.c
27451 @@ -5,8 +5,10 @@
27452 #include <asm/pgtable.h>
27453 #include <asm/proto.h>
27454
27455 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27456 static int disable_nx __cpuinitdata;
27457
27458 +#ifndef CONFIG_PAX_PAGEEXEC
27459 /*
27460 * noexec = on|off
27461 *
27462 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
27463 return 0;
27464 }
27465 early_param("noexec", noexec_setup);
27466 +#endif
27467 +
27468 +#endif
27469
27470 void __cpuinit x86_configure_nx(void)
27471 {
27472 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27473 if (cpu_has_nx && !disable_nx)
27474 __supported_pte_mask |= _PAGE_NX;
27475 else
27476 +#endif
27477 __supported_pte_mask &= ~_PAGE_NX;
27478 }
27479
27480 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
27481 index 60f926c..a710970 100644
27482 --- a/arch/x86/mm/tlb.c
27483 +++ b/arch/x86/mm/tlb.c
27484 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
27485 BUG();
27486 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
27487 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
27488 +
27489 +#ifndef CONFIG_PAX_PER_CPU_PGD
27490 load_cr3(swapper_pg_dir);
27491 +#endif
27492 +
27493 }
27494 }
27495 EXPORT_SYMBOL_GPL(leave_mm);
27496 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
27497 index 877b9a1..a8ecf42 100644
27498 --- a/arch/x86/net/bpf_jit.S
27499 +++ b/arch/x86/net/bpf_jit.S
27500 @@ -9,6 +9,7 @@
27501 */
27502 #include <linux/linkage.h>
27503 #include <asm/dwarf2.h>
27504 +#include <asm/alternative-asm.h>
27505
27506 /*
27507 * Calling convention :
27508 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
27509 jle bpf_slow_path_word
27510 mov (SKBDATA,%rsi),%eax
27511 bswap %eax /* ntohl() */
27512 + pax_force_retaddr
27513 ret
27514
27515 sk_load_half:
27516 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
27517 jle bpf_slow_path_half
27518 movzwl (SKBDATA,%rsi),%eax
27519 rol $8,%ax # ntohs()
27520 + pax_force_retaddr
27521 ret
27522
27523 sk_load_byte:
27524 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
27525 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
27526 jle bpf_slow_path_byte
27527 movzbl (SKBDATA,%rsi),%eax
27528 + pax_force_retaddr
27529 ret
27530
27531 /**
27532 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
27533 movzbl (SKBDATA,%rsi),%ebx
27534 and $15,%bl
27535 shl $2,%bl
27536 + pax_force_retaddr
27537 ret
27538
27539 /* rsi contains offset and can be scratched */
27540 @@ -109,6 +114,7 @@ bpf_slow_path_word:
27541 js bpf_error
27542 mov -12(%rbp),%eax
27543 bswap %eax
27544 + pax_force_retaddr
27545 ret
27546
27547 bpf_slow_path_half:
27548 @@ -117,12 +123,14 @@ bpf_slow_path_half:
27549 mov -12(%rbp),%ax
27550 rol $8,%ax
27551 movzwl %ax,%eax
27552 + pax_force_retaddr
27553 ret
27554
27555 bpf_slow_path_byte:
27556 bpf_slow_path_common(1)
27557 js bpf_error
27558 movzbl -12(%rbp),%eax
27559 + pax_force_retaddr
27560 ret
27561
27562 bpf_slow_path_byte_msh:
27563 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
27564 and $15,%al
27565 shl $2,%al
27566 xchg %eax,%ebx
27567 + pax_force_retaddr
27568 ret
27569
27570 #define sk_negative_common(SIZE) \
27571 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
27572 sk_negative_common(4)
27573 mov (%rax), %eax
27574 bswap %eax
27575 + pax_force_retaddr
27576 ret
27577
27578 bpf_slow_path_half_neg:
27579 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
27580 mov (%rax),%ax
27581 rol $8,%ax
27582 movzwl %ax,%eax
27583 + pax_force_retaddr
27584 ret
27585
27586 bpf_slow_path_byte_neg:
27587 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
27588 .globl sk_load_byte_negative_offset
27589 sk_negative_common(1)
27590 movzbl (%rax), %eax
27591 + pax_force_retaddr
27592 ret
27593
27594 bpf_slow_path_byte_msh_neg:
27595 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
27596 and $15,%al
27597 shl $2,%al
27598 xchg %eax,%ebx
27599 + pax_force_retaddr
27600 ret
27601
27602 bpf_error:
27603 @@ -197,4 +210,5 @@ bpf_error:
27604 xor %eax,%eax
27605 mov -8(%rbp),%rbx
27606 leaveq
27607 + pax_force_retaddr
27608 ret
27609 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
27610 index 520d2bd..b895ef4 100644
27611 --- a/arch/x86/net/bpf_jit_comp.c
27612 +++ b/arch/x86/net/bpf_jit_comp.c
27613 @@ -11,6 +11,7 @@
27614 #include <asm/cacheflush.h>
27615 #include <linux/netdevice.h>
27616 #include <linux/filter.h>
27617 +#include <linux/random.h>
27618
27619 /*
27620 * Conventions :
27621 @@ -48,13 +49,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
27622 return ptr + len;
27623 }
27624
27625 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27626 +#define MAX_INSTR_CODE_SIZE 96
27627 +#else
27628 +#define MAX_INSTR_CODE_SIZE 64
27629 +#endif
27630 +
27631 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
27632
27633 #define EMIT1(b1) EMIT(b1, 1)
27634 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
27635 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
27636 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
27637 +
27638 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27639 +/* original constant will appear in ecx */
27640 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
27641 +do { \
27642 + /* mov ecx, randkey */ \
27643 + EMIT1(0xb9); \
27644 + EMIT(_key, 4); \
27645 + /* xor ecx, randkey ^ off */ \
27646 + EMIT2(0x81, 0xf1); \
27647 + EMIT((_key) ^ (_off), 4); \
27648 +} while (0)
27649 +
27650 +#define EMIT1_off32(b1, _off) \
27651 +do { \
27652 + switch (b1) { \
27653 + case 0x05: /* add eax, imm32 */ \
27654 + case 0x2d: /* sub eax, imm32 */ \
27655 + case 0x25: /* and eax, imm32 */ \
27656 + case 0x0d: /* or eax, imm32 */ \
27657 + case 0xb8: /* mov eax, imm32 */ \
27658 + case 0x3d: /* cmp eax, imm32 */ \
27659 + case 0xa9: /* test eax, imm32 */ \
27660 + DILUTE_CONST_SEQUENCE(_off, randkey); \
27661 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
27662 + break; \
27663 + case 0xbb: /* mov ebx, imm32 */ \
27664 + DILUTE_CONST_SEQUENCE(_off, randkey); \
27665 + /* mov ebx, ecx */ \
27666 + EMIT2(0x89, 0xcb); \
27667 + break; \
27668 + case 0xbe: /* mov esi, imm32 */ \
27669 + DILUTE_CONST_SEQUENCE(_off, randkey); \
27670 + /* mov esi, ecx */ \
27671 + EMIT2(0x89, 0xce); \
27672 + break; \
27673 + case 0xe9: /* jmp rel imm32 */ \
27674 + EMIT1(b1); \
27675 + EMIT(_off, 4); \
27676 + /* prevent fall-through, we're not called if off = 0 */ \
27677 + EMIT(0xcccccccc, 4); \
27678 + EMIT(0xcccccccc, 4); \
27679 + break; \
27680 + default: \
27681 + EMIT1(b1); \
27682 + EMIT(_off, 4); \
27683 + } \
27684 +} while (0)
27685 +
27686 +#define EMIT2_off32(b1, b2, _off) \
27687 +do { \
27688 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
27689 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
27690 + EMIT(randkey, 4); \
27691 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
27692 + EMIT((_off) - randkey, 4); \
27693 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
27694 + DILUTE_CONST_SEQUENCE(_off, randkey); \
27695 + /* imul eax, ecx */ \
27696 + EMIT3(0x0f, 0xaf, 0xc1); \
27697 + } else { \
27698 + EMIT2(b1, b2); \
27699 + EMIT(_off, 4); \
27700 + } \
27701 +} while (0)
27702 +#else
27703 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
27704 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
27705 +#endif
27706
27707 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
27708 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
27709 @@ -89,6 +164,24 @@ do { \
27710 #define X86_JBE 0x76
27711 #define X86_JA 0x77
27712
27713 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27714 +#define APPEND_FLOW_VERIFY() \
27715 +do { \
27716 + /* mov ecx, randkey */ \
27717 + EMIT1(0xb9); \
27718 + EMIT(randkey, 4); \
27719 + /* cmp ecx, randkey */ \
27720 + EMIT2(0x81, 0xf9); \
27721 + EMIT(randkey, 4); \
27722 + /* jz after 8 int 3s */ \
27723 + EMIT2(0x74, 0x08); \
27724 + EMIT(0xcccccccc, 4); \
27725 + EMIT(0xcccccccc, 4); \
27726 +} while (0)
27727 +#else
27728 +#define APPEND_FLOW_VERIFY() do { } while (0)
27729 +#endif
27730 +
27731 #define EMIT_COND_JMP(op, offset) \
27732 do { \
27733 if (is_near(offset)) \
27734 @@ -96,6 +189,7 @@ do { \
27735 else { \
27736 EMIT2(0x0f, op + 0x10); \
27737 EMIT(offset, 4); /* jxx .+off32 */ \
27738 + APPEND_FLOW_VERIFY(); \
27739 } \
27740 } while (0)
27741
27742 @@ -120,12 +214,17 @@ static inline void bpf_flush_icache(void *start, void *end)
27743 set_fs(old_fs);
27744 }
27745
27746 +struct bpf_jit_work {
27747 + struct work_struct work;
27748 + void *image;
27749 +};
27750 +
27751 #define CHOOSE_LOAD_FUNC(K, func) \
27752 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
27753
27754 void bpf_jit_compile(struct sk_filter *fp)
27755 {
27756 - u8 temp[64];
27757 + u8 temp[MAX_INSTR_CODE_SIZE];
27758 u8 *prog;
27759 unsigned int proglen, oldproglen = 0;
27760 int ilen, i;
27761 @@ -138,6 +237,9 @@ void bpf_jit_compile(struct sk_filter *fp)
27762 unsigned int *addrs;
27763 const struct sock_filter *filter = fp->insns;
27764 int flen = fp->len;
27765 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27766 + unsigned int randkey;
27767 +#endif
27768
27769 if (!bpf_jit_enable)
27770 return;
27771 @@ -146,11 +248,19 @@ void bpf_jit_compile(struct sk_filter *fp)
27772 if (addrs == NULL)
27773 return;
27774
27775 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
27776 + if (!fp->work)
27777 + goto out;
27778 +
27779 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27780 + randkey = get_random_int();
27781 +#endif
27782 +
27783 /* Before first pass, make a rough estimation of addrs[]
27784 - * each bpf instruction is translated to less than 64 bytes
27785 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
27786 */
27787 for (proglen = 0, i = 0; i < flen; i++) {
27788 - proglen += 64;
27789 + proglen += MAX_INSTR_CODE_SIZE;
27790 addrs[i] = proglen;
27791 }
27792 cleanup_addr = proglen; /* epilogue address */
27793 @@ -258,10 +368,8 @@ void bpf_jit_compile(struct sk_filter *fp)
27794 case BPF_S_ALU_MUL_K: /* A *= K */
27795 if (is_imm8(K))
27796 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
27797 - else {
27798 - EMIT2(0x69, 0xc0); /* imul imm32,%eax */
27799 - EMIT(K, 4);
27800 - }
27801 + else
27802 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
27803 break;
27804 case BPF_S_ALU_DIV_X: /* A /= X; */
27805 seen |= SEEN_XREG;
27806 @@ -301,13 +409,23 @@ void bpf_jit_compile(struct sk_filter *fp)
27807 break;
27808 case BPF_S_ALU_MOD_K: /* A %= K; */
27809 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
27810 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27811 + DILUTE_CONST_SEQUENCE(K, randkey);
27812 +#else
27813 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
27814 +#endif
27815 EMIT2(0xf7, 0xf1); /* div %ecx */
27816 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
27817 break;
27818 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
27819 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27820 + DILUTE_CONST_SEQUENCE(K, randkey);
27821 + // imul rax, rcx
27822 + EMIT4(0x48, 0x0f, 0xaf, 0xc1);
27823 +#else
27824 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
27825 EMIT(K, 4);
27826 +#endif
27827 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
27828 break;
27829 case BPF_S_ALU_AND_X:
27830 @@ -543,8 +661,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
27831 if (is_imm8(K)) {
27832 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
27833 } else {
27834 - EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
27835 - EMIT(K, 4);
27836 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
27837 }
27838 } else {
27839 EMIT2(0x89,0xde); /* mov %ebx,%esi */
27840 @@ -627,17 +744,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
27841 break;
27842 default:
27843 /* hmm, too complex filter, give up with jit compiler */
27844 - goto out;
27845 + goto error;
27846 }
27847 ilen = prog - temp;
27848 if (image) {
27849 if (unlikely(proglen + ilen > oldproglen)) {
27850 pr_err("bpb_jit_compile fatal error\n");
27851 - kfree(addrs);
27852 - module_free(NULL, image);
27853 - return;
27854 + module_free_exec(NULL, image);
27855 + goto error;
27856 }
27857 + pax_open_kernel();
27858 memcpy(image + proglen, temp, ilen);
27859 + pax_close_kernel();
27860 }
27861 proglen += ilen;
27862 addrs[i] = proglen;
27863 @@ -658,11 +776,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
27864 break;
27865 }
27866 if (proglen == oldproglen) {
27867 - image = module_alloc(max_t(unsigned int,
27868 - proglen,
27869 - sizeof(struct work_struct)));
27870 + image = module_alloc_exec(proglen);
27871 if (!image)
27872 - goto out;
27873 + goto error;
27874 }
27875 oldproglen = proglen;
27876 }
27877 @@ -678,7 +794,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
27878 bpf_flush_icache(image, image + proglen);
27879
27880 fp->bpf_func = (void *)image;
27881 - }
27882 + } else
27883 +error:
27884 + kfree(fp->work);
27885 +
27886 out:
27887 kfree(addrs);
27888 return;
27889 @@ -686,18 +805,20 @@ out:
27890
27891 static void jit_free_defer(struct work_struct *arg)
27892 {
27893 - module_free(NULL, arg);
27894 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
27895 + kfree(arg);
27896 }
27897
27898 /* run from softirq, we must use a work_struct to call
27899 - * module_free() from process context
27900 + * module_free_exec() from process context
27901 */
27902 void bpf_jit_free(struct sk_filter *fp)
27903 {
27904 if (fp->bpf_func != sk_run_filter) {
27905 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
27906 + struct work_struct *work = &fp->work->work;
27907
27908 INIT_WORK(work, jit_free_defer);
27909 + fp->work->image = fp->bpf_func;
27910 schedule_work(work);
27911 }
27912 }
27913 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
27914 index d6aa6e8..266395a 100644
27915 --- a/arch/x86/oprofile/backtrace.c
27916 +++ b/arch/x86/oprofile/backtrace.c
27917 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
27918 struct stack_frame_ia32 *fp;
27919 unsigned long bytes;
27920
27921 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
27922 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
27923 if (bytes != sizeof(bufhead))
27924 return NULL;
27925
27926 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
27927 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
27928
27929 oprofile_add_trace(bufhead[0].return_address);
27930
27931 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
27932 struct stack_frame bufhead[2];
27933 unsigned long bytes;
27934
27935 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
27936 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
27937 if (bytes != sizeof(bufhead))
27938 return NULL;
27939
27940 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
27941 {
27942 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
27943
27944 - if (!user_mode_vm(regs)) {
27945 + if (!user_mode(regs)) {
27946 unsigned long stack = kernel_stack_pointer(regs);
27947 if (depth)
27948 dump_trace(NULL, regs, (unsigned long *)stack, 0,
27949 diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c
27950 index 192397c..5ba6f9e 100644
27951 --- a/arch/x86/pci/acpi.c
27952 +++ b/arch/x86/pci/acpi.c
27953 @@ -568,7 +568,7 @@ int __init pci_acpi_init(void)
27954 acpi_irq_penalty_init();
27955 pcibios_enable_irq = acpi_pci_irq_enable;
27956 pcibios_disable_irq = acpi_pci_irq_disable;
27957 - x86_init.pci.init_irq = x86_init_noop;
27958 + *(void **)&x86_init.pci.init_irq = x86_init_noop;
27959
27960 if (pci_routeirq) {
27961 /*
27962 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
27963 index e14a2ff..3fd6b58 100644
27964 --- a/arch/x86/pci/mrst.c
27965 +++ b/arch/x86/pci/mrst.c
27966 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
27967 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
27968 pci_mmcfg_late_init();
27969 pcibios_enable_irq = mrst_pci_irq_enable;
27970 - pci_root_ops = pci_mrst_ops;
27971 + pax_open_kernel();
27972 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
27973 + pax_close_kernel();
27974 pci_soc_mode = 1;
27975 /* Continue with standard init */
27976 return 1;
27977 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
27978 index da8fe05..7ee6704 100644
27979 --- a/arch/x86/pci/pcbios.c
27980 +++ b/arch/x86/pci/pcbios.c
27981 @@ -79,50 +79,93 @@ union bios32 {
27982 static struct {
27983 unsigned long address;
27984 unsigned short segment;
27985 -} bios32_indirect = { 0, __KERNEL_CS };
27986 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
27987
27988 /*
27989 * Returns the entry point for the given service, NULL on error
27990 */
27991
27992 -static unsigned long bios32_service(unsigned long service)
27993 +static unsigned long __devinit bios32_service(unsigned long service)
27994 {
27995 unsigned char return_code; /* %al */
27996 unsigned long address; /* %ebx */
27997 unsigned long length; /* %ecx */
27998 unsigned long entry; /* %edx */
27999 unsigned long flags;
28000 + struct desc_struct d, *gdt;
28001
28002 local_irq_save(flags);
28003 - __asm__("lcall *(%%edi); cld"
28004 +
28005 + gdt = get_cpu_gdt_table(smp_processor_id());
28006 +
28007 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
28008 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
28009 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
28010 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
28011 +
28012 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
28013 : "=a" (return_code),
28014 "=b" (address),
28015 "=c" (length),
28016 "=d" (entry)
28017 : "0" (service),
28018 "1" (0),
28019 - "D" (&bios32_indirect));
28020 + "D" (&bios32_indirect),
28021 + "r"(__PCIBIOS_DS)
28022 + : "memory");
28023 +
28024 + pax_open_kernel();
28025 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
28026 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
28027 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
28028 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
28029 + pax_close_kernel();
28030 +
28031 local_irq_restore(flags);
28032
28033 switch (return_code) {
28034 - case 0:
28035 - return address + entry;
28036 - case 0x80: /* Not present */
28037 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
28038 - return 0;
28039 - default: /* Shouldn't happen */
28040 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
28041 - service, return_code);
28042 + case 0: {
28043 + int cpu;
28044 + unsigned char flags;
28045 +
28046 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
28047 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
28048 + printk(KERN_WARNING "bios32_service: not valid\n");
28049 return 0;
28050 + }
28051 + address = address + PAGE_OFFSET;
28052 + length += 16UL; /* some BIOSs underreport this... */
28053 + flags = 4;
28054 + if (length >= 64*1024*1024) {
28055 + length >>= PAGE_SHIFT;
28056 + flags |= 8;
28057 + }
28058 +
28059 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
28060 + gdt = get_cpu_gdt_table(cpu);
28061 + pack_descriptor(&d, address, length, 0x9b, flags);
28062 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
28063 + pack_descriptor(&d, address, length, 0x93, flags);
28064 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
28065 + }
28066 + return entry;
28067 + }
28068 + case 0x80: /* Not present */
28069 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
28070 + return 0;
28071 + default: /* Shouldn't happen */
28072 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
28073 + service, return_code);
28074 + return 0;
28075 }
28076 }
28077
28078 static struct {
28079 unsigned long address;
28080 unsigned short segment;
28081 -} pci_indirect = { 0, __KERNEL_CS };
28082 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
28083
28084 -static int pci_bios_present;
28085 +static int pci_bios_present __read_only;
28086
28087 static int __devinit check_pcibios(void)
28088 {
28089 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
28090 unsigned long flags, pcibios_entry;
28091
28092 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
28093 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
28094 + pci_indirect.address = pcibios_entry;
28095
28096 local_irq_save(flags);
28097 - __asm__(
28098 - "lcall *(%%edi); cld\n\t"
28099 + __asm__("movw %w6, %%ds\n\t"
28100 + "lcall *%%ss:(%%edi); cld\n\t"
28101 + "push %%ss\n\t"
28102 + "pop %%ds\n\t"
28103 "jc 1f\n\t"
28104 "xor %%ah, %%ah\n"
28105 "1:"
28106 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
28107 "=b" (ebx),
28108 "=c" (ecx)
28109 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
28110 - "D" (&pci_indirect)
28111 + "D" (&pci_indirect),
28112 + "r" (__PCIBIOS_DS)
28113 : "memory");
28114 local_irq_restore(flags);
28115
28116 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28117
28118 switch (len) {
28119 case 1:
28120 - __asm__("lcall *(%%esi); cld\n\t"
28121 + __asm__("movw %w6, %%ds\n\t"
28122 + "lcall *%%ss:(%%esi); cld\n\t"
28123 + "push %%ss\n\t"
28124 + "pop %%ds\n\t"
28125 "jc 1f\n\t"
28126 "xor %%ah, %%ah\n"
28127 "1:"
28128 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28129 : "1" (PCIBIOS_READ_CONFIG_BYTE),
28130 "b" (bx),
28131 "D" ((long)reg),
28132 - "S" (&pci_indirect));
28133 + "S" (&pci_indirect),
28134 + "r" (__PCIBIOS_DS));
28135 /*
28136 * Zero-extend the result beyond 8 bits, do not trust the
28137 * BIOS having done it:
28138 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28139 *value &= 0xff;
28140 break;
28141 case 2:
28142 - __asm__("lcall *(%%esi); cld\n\t"
28143 + __asm__("movw %w6, %%ds\n\t"
28144 + "lcall *%%ss:(%%esi); cld\n\t"
28145 + "push %%ss\n\t"
28146 + "pop %%ds\n\t"
28147 "jc 1f\n\t"
28148 "xor %%ah, %%ah\n"
28149 "1:"
28150 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28151 : "1" (PCIBIOS_READ_CONFIG_WORD),
28152 "b" (bx),
28153 "D" ((long)reg),
28154 - "S" (&pci_indirect));
28155 + "S" (&pci_indirect),
28156 + "r" (__PCIBIOS_DS));
28157 /*
28158 * Zero-extend the result beyond 16 bits, do not trust the
28159 * BIOS having done it:
28160 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28161 *value &= 0xffff;
28162 break;
28163 case 4:
28164 - __asm__("lcall *(%%esi); cld\n\t"
28165 + __asm__("movw %w6, %%ds\n\t"
28166 + "lcall *%%ss:(%%esi); cld\n\t"
28167 + "push %%ss\n\t"
28168 + "pop %%ds\n\t"
28169 "jc 1f\n\t"
28170 "xor %%ah, %%ah\n"
28171 "1:"
28172 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28173 : "1" (PCIBIOS_READ_CONFIG_DWORD),
28174 "b" (bx),
28175 "D" ((long)reg),
28176 - "S" (&pci_indirect));
28177 + "S" (&pci_indirect),
28178 + "r" (__PCIBIOS_DS));
28179 break;
28180 }
28181
28182 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28183
28184 switch (len) {
28185 case 1:
28186 - __asm__("lcall *(%%esi); cld\n\t"
28187 + __asm__("movw %w6, %%ds\n\t"
28188 + "lcall *%%ss:(%%esi); cld\n\t"
28189 + "push %%ss\n\t"
28190 + "pop %%ds\n\t"
28191 "jc 1f\n\t"
28192 "xor %%ah, %%ah\n"
28193 "1:"
28194 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28195 "c" (value),
28196 "b" (bx),
28197 "D" ((long)reg),
28198 - "S" (&pci_indirect));
28199 + "S" (&pci_indirect),
28200 + "r" (__PCIBIOS_DS));
28201 break;
28202 case 2:
28203 - __asm__("lcall *(%%esi); cld\n\t"
28204 + __asm__("movw %w6, %%ds\n\t"
28205 + "lcall *%%ss:(%%esi); cld\n\t"
28206 + "push %%ss\n\t"
28207 + "pop %%ds\n\t"
28208 "jc 1f\n\t"
28209 "xor %%ah, %%ah\n"
28210 "1:"
28211 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28212 "c" (value),
28213 "b" (bx),
28214 "D" ((long)reg),
28215 - "S" (&pci_indirect));
28216 + "S" (&pci_indirect),
28217 + "r" (__PCIBIOS_DS));
28218 break;
28219 case 4:
28220 - __asm__("lcall *(%%esi); cld\n\t"
28221 + __asm__("movw %w6, %%ds\n\t"
28222 + "lcall *%%ss:(%%esi); cld\n\t"
28223 + "push %%ss\n\t"
28224 + "pop %%ds\n\t"
28225 "jc 1f\n\t"
28226 "xor %%ah, %%ah\n"
28227 "1:"
28228 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28229 "c" (value),
28230 "b" (bx),
28231 "D" ((long)reg),
28232 - "S" (&pci_indirect));
28233 + "S" (&pci_indirect),
28234 + "r" (__PCIBIOS_DS));
28235 break;
28236 }
28237
28238 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
28239
28240 DBG("PCI: Fetching IRQ routing table... ");
28241 __asm__("push %%es\n\t"
28242 + "movw %w8, %%ds\n\t"
28243 "push %%ds\n\t"
28244 "pop %%es\n\t"
28245 - "lcall *(%%esi); cld\n\t"
28246 + "lcall *%%ss:(%%esi); cld\n\t"
28247 "pop %%es\n\t"
28248 + "push %%ss\n\t"
28249 + "pop %%ds\n"
28250 "jc 1f\n\t"
28251 "xor %%ah, %%ah\n"
28252 "1:"
28253 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
28254 "1" (0),
28255 "D" ((long) &opt),
28256 "S" (&pci_indirect),
28257 - "m" (opt)
28258 + "m" (opt),
28259 + "r" (__PCIBIOS_DS)
28260 : "memory");
28261 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
28262 if (ret & 0xff00)
28263 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
28264 {
28265 int ret;
28266
28267 - __asm__("lcall *(%%esi); cld\n\t"
28268 + __asm__("movw %w5, %%ds\n\t"
28269 + "lcall *%%ss:(%%esi); cld\n\t"
28270 + "push %%ss\n\t"
28271 + "pop %%ds\n"
28272 "jc 1f\n\t"
28273 "xor %%ah, %%ah\n"
28274 "1:"
28275 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
28276 : "0" (PCIBIOS_SET_PCI_HW_INT),
28277 "b" ((dev->bus->number << 8) | dev->devfn),
28278 "c" ((irq << 8) | (pin + 10)),
28279 - "S" (&pci_indirect));
28280 + "S" (&pci_indirect),
28281 + "r" (__PCIBIOS_DS));
28282 return !(ret & 0xff00);
28283 }
28284 EXPORT_SYMBOL(pcibios_set_irq_routing);
28285 diff --git a/arch/x86/pci/xen.c b/arch/x86/pci/xen.c
28286 index 56ab749..3cb792a 100644
28287 --- a/arch/x86/pci/xen.c
28288 +++ b/arch/x86/pci/xen.c
28289 @@ -395,9 +395,9 @@ int __init pci_xen_init(void)
28290 #endif
28291
28292 #ifdef CONFIG_PCI_MSI
28293 - x86_msi.setup_msi_irqs = xen_setup_msi_irqs;
28294 - x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28295 - x86_msi.teardown_msi_irqs = xen_teardown_msi_irqs;
28296 + *(void **)&x86_msi.setup_msi_irqs = xen_setup_msi_irqs;
28297 + *(void **)&x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28298 + *(void **)&x86_msi.teardown_msi_irqs = xen_teardown_msi_irqs;
28299 #endif
28300 return 0;
28301 }
28302 @@ -416,8 +416,8 @@ int __init pci_xen_hvm_init(void)
28303 #endif
28304
28305 #ifdef CONFIG_PCI_MSI
28306 - x86_msi.setup_msi_irqs = xen_hvm_setup_msi_irqs;
28307 - x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28308 + *(void **)&x86_msi.setup_msi_irqs = xen_hvm_setup_msi_irqs;
28309 + *(void **)&x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28310 #endif
28311 return 0;
28312 }
28313 @@ -474,9 +474,9 @@ int __init pci_xen_initial_domain(void)
28314 int irq;
28315
28316 #ifdef CONFIG_PCI_MSI
28317 - x86_msi.setup_msi_irqs = xen_initdom_setup_msi_irqs;
28318 - x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28319 - x86_msi.restore_msi_irqs = xen_initdom_restore_msi_irqs;
28320 + *(void **)&x86_msi.setup_msi_irqs = xen_initdom_setup_msi_irqs;
28321 + *(void **)&x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28322 + *(void **)&x86_msi.restore_msi_irqs = xen_initdom_restore_msi_irqs;
28323 #endif
28324 xen_setup_acpi_sci();
28325 __acpi_register_gsi = acpi_register_gsi_xen;
28326 diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
28327 index 77cf009..7fe44c8 100644
28328 --- a/arch/x86/platform/efi/efi.c
28329 +++ b/arch/x86/platform/efi/efi.c
28330 @@ -746,8 +746,8 @@ void __init efi_init(void)
28331
28332 #ifdef CONFIG_X86_32
28333 if (efi_is_native()) {
28334 - x86_platform.get_wallclock = efi_get_time;
28335 - x86_platform.set_wallclock = efi_set_rtc_mmss;
28336 + *(void **)&x86_platform.get_wallclock = efi_get_time;
28337 + *(void **)&x86_platform.set_wallclock = efi_set_rtc_mmss;
28338 }
28339 #endif
28340
28341 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
28342 index 40e4469..1ab536e 100644
28343 --- a/arch/x86/platform/efi/efi_32.c
28344 +++ b/arch/x86/platform/efi/efi_32.c
28345 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
28346 {
28347 struct desc_ptr gdt_descr;
28348
28349 +#ifdef CONFIG_PAX_KERNEXEC
28350 + struct desc_struct d;
28351 +#endif
28352 +
28353 local_irq_save(efi_rt_eflags);
28354
28355 load_cr3(initial_page_table);
28356 __flush_tlb_all();
28357
28358 +#ifdef CONFIG_PAX_KERNEXEC
28359 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
28360 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
28361 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
28362 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
28363 +#endif
28364 +
28365 gdt_descr.address = __pa(get_cpu_gdt_table(0));
28366 gdt_descr.size = GDT_SIZE - 1;
28367 load_gdt(&gdt_descr);
28368 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
28369 {
28370 struct desc_ptr gdt_descr;
28371
28372 +#ifdef CONFIG_PAX_KERNEXEC
28373 + struct desc_struct d;
28374 +
28375 + memset(&d, 0, sizeof d);
28376 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
28377 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
28378 +#endif
28379 +
28380 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
28381 gdt_descr.size = GDT_SIZE - 1;
28382 load_gdt(&gdt_descr);
28383 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
28384 index fbe66e6..eae5e38 100644
28385 --- a/arch/x86/platform/efi/efi_stub_32.S
28386 +++ b/arch/x86/platform/efi/efi_stub_32.S
28387 @@ -6,7 +6,9 @@
28388 */
28389
28390 #include <linux/linkage.h>
28391 +#include <linux/init.h>
28392 #include <asm/page_types.h>
28393 +#include <asm/segment.h>
28394
28395 /*
28396 * efi_call_phys(void *, ...) is a function with variable parameters.
28397 @@ -20,7 +22,7 @@
28398 * service functions will comply with gcc calling convention, too.
28399 */
28400
28401 -.text
28402 +__INIT
28403 ENTRY(efi_call_phys)
28404 /*
28405 * 0. The function can only be called in Linux kernel. So CS has been
28406 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
28407 * The mapping of lower virtual memory has been created in prelog and
28408 * epilog.
28409 */
28410 - movl $1f, %edx
28411 - subl $__PAGE_OFFSET, %edx
28412 - jmp *%edx
28413 +#ifdef CONFIG_PAX_KERNEXEC
28414 + movl $(__KERNEXEC_EFI_DS), %edx
28415 + mov %edx, %ds
28416 + mov %edx, %es
28417 + mov %edx, %ss
28418 + addl $2f,(1f)
28419 + ljmp *(1f)
28420 +
28421 +__INITDATA
28422 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
28423 +.previous
28424 +
28425 +2:
28426 + subl $2b,(1b)
28427 +#else
28428 + jmp 1f-__PAGE_OFFSET
28429 1:
28430 +#endif
28431
28432 /*
28433 * 2. Now on the top of stack is the return
28434 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
28435 * parameter 2, ..., param n. To make things easy, we save the return
28436 * address of efi_call_phys in a global variable.
28437 */
28438 - popl %edx
28439 - movl %edx, saved_return_addr
28440 - /* get the function pointer into ECX*/
28441 - popl %ecx
28442 - movl %ecx, efi_rt_function_ptr
28443 - movl $2f, %edx
28444 - subl $__PAGE_OFFSET, %edx
28445 - pushl %edx
28446 + popl (saved_return_addr)
28447 + popl (efi_rt_function_ptr)
28448
28449 /*
28450 * 3. Clear PG bit in %CR0.
28451 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
28452 /*
28453 * 5. Call the physical function.
28454 */
28455 - jmp *%ecx
28456 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
28457
28458 -2:
28459 /*
28460 * 6. After EFI runtime service returns, control will return to
28461 * following instruction. We'd better readjust stack pointer first.
28462 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
28463 movl %cr0, %edx
28464 orl $0x80000000, %edx
28465 movl %edx, %cr0
28466 - jmp 1f
28467 -1:
28468 +
28469 /*
28470 * 8. Now restore the virtual mode from flat mode by
28471 * adding EIP with PAGE_OFFSET.
28472 */
28473 - movl $1f, %edx
28474 - jmp *%edx
28475 +#ifdef CONFIG_PAX_KERNEXEC
28476 + movl $(__KERNEL_DS), %edx
28477 + mov %edx, %ds
28478 + mov %edx, %es
28479 + mov %edx, %ss
28480 + ljmp $(__KERNEL_CS),$1f
28481 +#else
28482 + jmp 1f+__PAGE_OFFSET
28483 +#endif
28484 1:
28485
28486 /*
28487 * 9. Balance the stack. And because EAX contain the return value,
28488 * we'd better not clobber it.
28489 */
28490 - leal efi_rt_function_ptr, %edx
28491 - movl (%edx), %ecx
28492 - pushl %ecx
28493 + pushl (efi_rt_function_ptr)
28494
28495 /*
28496 - * 10. Push the saved return address onto the stack and return.
28497 + * 10. Return to the saved return address.
28498 */
28499 - leal saved_return_addr, %edx
28500 - movl (%edx), %ecx
28501 - pushl %ecx
28502 - ret
28503 + jmpl *(saved_return_addr)
28504 ENDPROC(efi_call_phys)
28505 .previous
28506
28507 -.data
28508 +__INITDATA
28509 saved_return_addr:
28510 .long 0
28511 efi_rt_function_ptr:
28512 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
28513 index 4c07cca..2c8427d 100644
28514 --- a/arch/x86/platform/efi/efi_stub_64.S
28515 +++ b/arch/x86/platform/efi/efi_stub_64.S
28516 @@ -7,6 +7,7 @@
28517 */
28518
28519 #include <linux/linkage.h>
28520 +#include <asm/alternative-asm.h>
28521
28522 #define SAVE_XMM \
28523 mov %rsp, %rax; \
28524 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
28525 call *%rdi
28526 addq $32, %rsp
28527 RESTORE_XMM
28528 + pax_force_retaddr 0, 1
28529 ret
28530 ENDPROC(efi_call0)
28531
28532 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
28533 call *%rdi
28534 addq $32, %rsp
28535 RESTORE_XMM
28536 + pax_force_retaddr 0, 1
28537 ret
28538 ENDPROC(efi_call1)
28539
28540 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
28541 call *%rdi
28542 addq $32, %rsp
28543 RESTORE_XMM
28544 + pax_force_retaddr 0, 1
28545 ret
28546 ENDPROC(efi_call2)
28547
28548 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
28549 call *%rdi
28550 addq $32, %rsp
28551 RESTORE_XMM
28552 + pax_force_retaddr 0, 1
28553 ret
28554 ENDPROC(efi_call3)
28555
28556 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
28557 call *%rdi
28558 addq $32, %rsp
28559 RESTORE_XMM
28560 + pax_force_retaddr 0, 1
28561 ret
28562 ENDPROC(efi_call4)
28563
28564 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
28565 call *%rdi
28566 addq $48, %rsp
28567 RESTORE_XMM
28568 + pax_force_retaddr 0, 1
28569 ret
28570 ENDPROC(efi_call5)
28571
28572 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
28573 call *%rdi
28574 addq $48, %rsp
28575 RESTORE_XMM
28576 + pax_force_retaddr 0, 1
28577 ret
28578 ENDPROC(efi_call6)
28579 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
28580 index fd41a92..bc8091d 100644
28581 --- a/arch/x86/platform/mrst/mrst.c
28582 +++ b/arch/x86/platform/mrst/mrst.c
28583 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
28584 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
28585 int sfi_mrtc_num;
28586
28587 -static void mrst_power_off(void)
28588 +static __noreturn void mrst_power_off(void)
28589 {
28590 + BUG();
28591 }
28592
28593 -static void mrst_reboot(void)
28594 +static __noreturn void mrst_reboot(void)
28595 {
28596 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
28597 + BUG();
28598 }
28599
28600 /* parse all the mtimer info to a static mtimer array */
28601 @@ -233,14 +235,14 @@ static void __init mrst_time_init(void)
28602 case MRST_TIMER_APBT_ONLY:
28603 break;
28604 case MRST_TIMER_LAPIC_APBT:
28605 - x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
28606 - x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
28607 + *(void **)&x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
28608 + *(void **)&x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
28609 break;
28610 default:
28611 if (!boot_cpu_has(X86_FEATURE_ARAT))
28612 break;
28613 - x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
28614 - x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
28615 + *(void **)&x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
28616 + *(void **)&x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
28617 return;
28618 }
28619 /* we need at least one APB timer */
28620 @@ -282,35 +284,35 @@ static unsigned char mrst_get_nmi_reason(void)
28621 */
28622 void __init x86_mrst_early_setup(void)
28623 {
28624 - x86_init.resources.probe_roms = x86_init_noop;
28625 - x86_init.resources.reserve_resources = x86_init_noop;
28626 + *(void **)&x86_init.resources.probe_roms = x86_init_noop;
28627 + *(void **)&x86_init.resources.reserve_resources = x86_init_noop;
28628
28629 - x86_init.timers.timer_init = mrst_time_init;
28630 - x86_init.timers.setup_percpu_clockev = x86_init_noop;
28631 + *(void **)&x86_init.timers.timer_init = mrst_time_init;
28632 + *(void **)&x86_init.timers.setup_percpu_clockev = x86_init_noop;
28633
28634 - x86_init.irqs.pre_vector_init = x86_init_noop;
28635 + *(void **)&x86_init.irqs.pre_vector_init = x86_init_noop;
28636
28637 - x86_init.oem.arch_setup = mrst_arch_setup;
28638 + *(void **)&x86_init.oem.arch_setup = mrst_arch_setup;
28639
28640 - x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock;
28641 + *(void **)&x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock;
28642
28643 - x86_platform.calibrate_tsc = mrst_calibrate_tsc;
28644 - x86_platform.i8042_detect = mrst_i8042_detect;
28645 - x86_init.timers.wallclock_init = mrst_rtc_init;
28646 - x86_platform.get_nmi_reason = mrst_get_nmi_reason;
28647 + *(void **)&x86_platform.calibrate_tsc = mrst_calibrate_tsc;
28648 + *(void **)&x86_platform.i8042_detect = mrst_i8042_detect;
28649 + *(void **)&x86_init.timers.wallclock_init = mrst_rtc_init;
28650 + *(void **)&x86_platform.get_nmi_reason = mrst_get_nmi_reason;
28651
28652 - x86_init.pci.init = pci_mrst_init;
28653 - x86_init.pci.fixup_irqs = x86_init_noop;
28654 + *(void **)&x86_init.pci.init = pci_mrst_init;
28655 + *(void **)&x86_init.pci.fixup_irqs = x86_init_noop;
28656
28657 legacy_pic = &null_legacy_pic;
28658
28659 /* Moorestown specific power_off/restart method */
28660 pm_power_off = mrst_power_off;
28661 - machine_ops.emergency_restart = mrst_reboot;
28662 + *(void **)&machine_ops.emergency_restart = mrst_reboot;
28663
28664 /* Avoid searching for BIOS MP tables */
28665 - x86_init.mpparse.find_smp_config = x86_init_noop;
28666 - x86_init.mpparse.get_smp_config = x86_init_uint_noop;
28667 + *(void **)&x86_init.mpparse.find_smp_config = x86_init_noop;
28668 + *(void **)&x86_init.mpparse.get_smp_config = x86_init_uint_noop;
28669 set_bit(MP_BUS_ISA, mp_bus_not_pci);
28670 }
28671
28672 diff --git a/arch/x86/platform/mrst/vrtc.c b/arch/x86/platform/mrst/vrtc.c
28673 index 225bd0f..22e8086 100644
28674 --- a/arch/x86/platform/mrst/vrtc.c
28675 +++ b/arch/x86/platform/mrst/vrtc.c
28676 @@ -120,8 +120,8 @@ void __init mrst_rtc_init(void)
28677
28678 vrtc_virt_base = (void __iomem *)set_fixmap_offset_nocache(FIX_LNW_VRTC,
28679 vrtc_paddr);
28680 - x86_platform.get_wallclock = vrtc_get_time;
28681 - x86_platform.set_wallclock = vrtc_set_mmss;
28682 + *(void **)&x86_platform.get_wallclock = vrtc_get_time;
28683 + *(void **)&x86_platform.set_wallclock = vrtc_set_mmss;
28684 }
28685
28686 /*
28687 diff --git a/arch/x86/platform/olpc/olpc.c b/arch/x86/platform/olpc/olpc.c
28688 index 2737608..0d62cc2 100644
28689 --- a/arch/x86/platform/olpc/olpc.c
28690 +++ b/arch/x86/platform/olpc/olpc.c
28691 @@ -395,7 +395,7 @@ static int __init olpc_init(void)
28692 * XO-1 only. */
28693 if (olpc_platform_info.boardrev < olpc_board_pre(0xd0) &&
28694 !cs5535_has_vsa2())
28695 - x86_init.pci.arch_init = pci_olpc_init;
28696 + *(void **)&x86_init.pci.arch_init = pci_olpc_init;
28697 #endif
28698
28699 if (olpc_platform_info.boardrev < olpc_board_pre(0xd0)) { /* XO-1 */
28700 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
28701 index d6ee929..3637cb5 100644
28702 --- a/arch/x86/platform/olpc/olpc_dt.c
28703 +++ b/arch/x86/platform/olpc/olpc_dt.c
28704 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
28705 return res;
28706 }
28707
28708 -static struct of_pdt_ops prom_olpc_ops __initdata = {
28709 +static struct of_pdt_ops prom_olpc_ops __initconst = {
28710 .nextprop = olpc_dt_nextprop,
28711 .getproplen = olpc_dt_getproplen,
28712 .getproperty = olpc_dt_getproperty,
28713 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
28714 index 218cdb1..c1178eb 100644
28715 --- a/arch/x86/power/cpu.c
28716 +++ b/arch/x86/power/cpu.c
28717 @@ -132,7 +132,7 @@ static void do_fpu_end(void)
28718 static void fix_processor_context(void)
28719 {
28720 int cpu = smp_processor_id();
28721 - struct tss_struct *t = &per_cpu(init_tss, cpu);
28722 + struct tss_struct *t = init_tss + cpu;
28723
28724 set_tss_desc(cpu, t); /*
28725 * This just modifies memory; should not be
28726 @@ -142,8 +142,6 @@ static void fix_processor_context(void)
28727 */
28728
28729 #ifdef CONFIG_X86_64
28730 - get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
28731 -
28732 syscall_init(); /* This sets MSR_*STAR and related */
28733 #endif
28734 load_TR_desc(); /* This does ltr */
28735 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
28736 index cbca565..bae7133 100644
28737 --- a/arch/x86/realmode/init.c
28738 +++ b/arch/x86/realmode/init.c
28739 @@ -62,7 +62,13 @@ void __init setup_real_mode(void)
28740 __va(real_mode_header->trampoline_header);
28741
28742 #ifdef CONFIG_X86_32
28743 - trampoline_header->start = __pa(startup_32_smp);
28744 + trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
28745 +
28746 +#ifdef CONFIG_PAX_KERNEXEC
28747 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
28748 +#endif
28749 +
28750 + trampoline_header->boot_cs = __BOOT_CS;
28751 trampoline_header->gdt_limit = __BOOT_DS + 7;
28752 trampoline_header->gdt_base = __pa(boot_gdt);
28753 #else
28754 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
28755 index 8869287..d577672 100644
28756 --- a/arch/x86/realmode/rm/Makefile
28757 +++ b/arch/x86/realmode/rm/Makefile
28758 @@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
28759 $(call cc-option, -fno-unit-at-a-time)) \
28760 $(call cc-option, -fno-stack-protector) \
28761 $(call cc-option, -mpreferred-stack-boundary=2)
28762 +ifdef CONSTIFY_PLUGIN
28763 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
28764 +endif
28765 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
28766 GCOV_PROFILE := n
28767 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
28768 index a28221d..93c40f1 100644
28769 --- a/arch/x86/realmode/rm/header.S
28770 +++ b/arch/x86/realmode/rm/header.S
28771 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
28772 #endif
28773 /* APM/BIOS reboot */
28774 .long pa_machine_real_restart_asm
28775 -#ifdef CONFIG_X86_64
28776 +#ifdef CONFIG_X86_32
28777 + .long __KERNEL_CS
28778 +#else
28779 .long __KERNEL32_CS
28780 #endif
28781 END(real_mode_header)
28782 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
28783 index c1b2791..f9e31c7 100644
28784 --- a/arch/x86/realmode/rm/trampoline_32.S
28785 +++ b/arch/x86/realmode/rm/trampoline_32.S
28786 @@ -25,6 +25,12 @@
28787 #include <asm/page_types.h>
28788 #include "realmode.h"
28789
28790 +#ifdef CONFIG_PAX_KERNEXEC
28791 +#define ta(X) (X)
28792 +#else
28793 +#define ta(X) (pa_ ## X)
28794 +#endif
28795 +
28796 .text
28797 .code16
28798
28799 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
28800
28801 cli # We should be safe anyway
28802
28803 - movl tr_start, %eax # where we need to go
28804 -
28805 movl $0xA5A5A5A5, trampoline_status
28806 # write marker for master knows we're running
28807
28808 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
28809 movw $1, %dx # protected mode (PE) bit
28810 lmsw %dx # into protected mode
28811
28812 - ljmpl $__BOOT_CS, $pa_startup_32
28813 + ljmpl *(trampoline_header)
28814
28815 .section ".text32","ax"
28816 .code32
28817 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
28818 .balign 8
28819 GLOBAL(trampoline_header)
28820 tr_start: .space 4
28821 - tr_gdt_pad: .space 2
28822 + tr_boot_cs: .space 2
28823 tr_gdt: .space 6
28824 END(trampoline_header)
28825
28826 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
28827 index bb360dc..3e5945f 100644
28828 --- a/arch/x86/realmode/rm/trampoline_64.S
28829 +++ b/arch/x86/realmode/rm/trampoline_64.S
28830 @@ -107,7 +107,7 @@ ENTRY(startup_32)
28831 wrmsr
28832
28833 # Enable paging and in turn activate Long Mode
28834 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
28835 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
28836 movl %eax, %cr0
28837
28838 /*
28839 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
28840 index 5a1847d..deccb30 100644
28841 --- a/arch/x86/tools/relocs.c
28842 +++ b/arch/x86/tools/relocs.c
28843 @@ -12,10 +12,13 @@
28844 #include <regex.h>
28845 #include <tools/le_byteshift.h>
28846
28847 +#include "../../../include/generated/autoconf.h"
28848 +
28849 static void die(char *fmt, ...);
28850
28851 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
28852 static Elf32_Ehdr ehdr;
28853 +static Elf32_Phdr *phdr;
28854 static unsigned long reloc_count, reloc_idx;
28855 static unsigned long *relocs;
28856 static unsigned long reloc16_count, reloc16_idx;
28857 @@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
28858 }
28859 }
28860
28861 +static void read_phdrs(FILE *fp)
28862 +{
28863 + unsigned int i;
28864 +
28865 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
28866 + if (!phdr) {
28867 + die("Unable to allocate %d program headers\n",
28868 + ehdr.e_phnum);
28869 + }
28870 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
28871 + die("Seek to %d failed: %s\n",
28872 + ehdr.e_phoff, strerror(errno));
28873 + }
28874 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
28875 + die("Cannot read ELF program headers: %s\n",
28876 + strerror(errno));
28877 + }
28878 + for(i = 0; i < ehdr.e_phnum; i++) {
28879 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
28880 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
28881 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
28882 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
28883 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
28884 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
28885 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
28886 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
28887 + }
28888 +
28889 +}
28890 +
28891 static void read_shdrs(FILE *fp)
28892 {
28893 - int i;
28894 + unsigned int i;
28895 Elf32_Shdr shdr;
28896
28897 secs = calloc(ehdr.e_shnum, sizeof(struct section));
28898 @@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
28899
28900 static void read_strtabs(FILE *fp)
28901 {
28902 - int i;
28903 + unsigned int i;
28904 for (i = 0; i < ehdr.e_shnum; i++) {
28905 struct section *sec = &secs[i];
28906 if (sec->shdr.sh_type != SHT_STRTAB) {
28907 @@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
28908
28909 static void read_symtabs(FILE *fp)
28910 {
28911 - int i,j;
28912 + unsigned int i,j;
28913 for (i = 0; i < ehdr.e_shnum; i++) {
28914 struct section *sec = &secs[i];
28915 if (sec->shdr.sh_type != SHT_SYMTAB) {
28916 @@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
28917 }
28918
28919
28920 -static void read_relocs(FILE *fp)
28921 +static void read_relocs(FILE *fp, int use_real_mode)
28922 {
28923 - int i,j;
28924 + unsigned int i,j;
28925 + uint32_t base;
28926 +
28927 for (i = 0; i < ehdr.e_shnum; i++) {
28928 struct section *sec = &secs[i];
28929 if (sec->shdr.sh_type != SHT_REL) {
28930 @@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
28931 die("Cannot read symbol table: %s\n",
28932 strerror(errno));
28933 }
28934 + base = 0;
28935 +
28936 +#ifdef CONFIG_X86_32
28937 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
28938 + if (phdr[j].p_type != PT_LOAD )
28939 + continue;
28940 + if (secs[sec->shdr.sh_info].shdr.sh_offset < phdr[j].p_offset || secs[sec->shdr.sh_info].shdr.sh_offset >= phdr[j].p_offset + phdr[j].p_filesz)
28941 + continue;
28942 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
28943 + break;
28944 + }
28945 +#endif
28946 +
28947 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
28948 Elf32_Rel *rel = &sec->reltab[j];
28949 - rel->r_offset = elf32_to_cpu(rel->r_offset);
28950 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
28951 rel->r_info = elf32_to_cpu(rel->r_info);
28952 }
28953 }
28954 @@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
28955
28956 static void print_absolute_symbols(void)
28957 {
28958 - int i;
28959 + unsigned int i;
28960 printf("Absolute symbols\n");
28961 printf(" Num: Value Size Type Bind Visibility Name\n");
28962 for (i = 0; i < ehdr.e_shnum; i++) {
28963 struct section *sec = &secs[i];
28964 char *sym_strtab;
28965 - int j;
28966 + unsigned int j;
28967
28968 if (sec->shdr.sh_type != SHT_SYMTAB) {
28969 continue;
28970 @@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
28971
28972 static void print_absolute_relocs(void)
28973 {
28974 - int i, printed = 0;
28975 + unsigned int i, printed = 0;
28976
28977 for (i = 0; i < ehdr.e_shnum; i++) {
28978 struct section *sec = &secs[i];
28979 struct section *sec_applies, *sec_symtab;
28980 char *sym_strtab;
28981 Elf32_Sym *sh_symtab;
28982 - int j;
28983 + unsigned int j;
28984 if (sec->shdr.sh_type != SHT_REL) {
28985 continue;
28986 }
28987 @@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
28988 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
28989 int use_real_mode)
28990 {
28991 - int i;
28992 + unsigned int i;
28993 /* Walk through the relocations */
28994 for (i = 0; i < ehdr.e_shnum; i++) {
28995 char *sym_strtab;
28996 Elf32_Sym *sh_symtab;
28997 struct section *sec_applies, *sec_symtab;
28998 - int j;
28999 + unsigned int j;
29000 struct section *sec = &secs[i];
29001
29002 if (sec->shdr.sh_type != SHT_REL) {
29003 @@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
29004 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
29005 r_type = ELF32_R_TYPE(rel->r_info);
29006
29007 + if (!use_real_mode) {
29008 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
29009 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
29010 + continue;
29011 +
29012 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
29013 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
29014 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
29015 + continue;
29016 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
29017 + continue;
29018 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
29019 + continue;
29020 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
29021 + continue;
29022 +#endif
29023 + }
29024 +
29025 shn_abs = sym->st_shndx == SHN_ABS;
29026
29027 switch (r_type) {
29028 @@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
29029
29030 static void emit_relocs(int as_text, int use_real_mode)
29031 {
29032 - int i;
29033 + unsigned int i;
29034 /* Count how many relocations I have and allocate space for them. */
29035 reloc_count = 0;
29036 walk_relocs(count_reloc, use_real_mode);
29037 @@ -808,10 +874,11 @@ int main(int argc, char **argv)
29038 fname, strerror(errno));
29039 }
29040 read_ehdr(fp);
29041 + read_phdrs(fp);
29042 read_shdrs(fp);
29043 read_strtabs(fp);
29044 read_symtabs(fp);
29045 - read_relocs(fp);
29046 + read_relocs(fp, use_real_mode);
29047 if (show_absolute_syms) {
29048 print_absolute_symbols();
29049 return 0;
29050 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
29051 index fd14be1..e3c79c0 100644
29052 --- a/arch/x86/vdso/Makefile
29053 +++ b/arch/x86/vdso/Makefile
29054 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
29055 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
29056 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
29057
29058 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
29059 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
29060 GCOV_PROFILE := n
29061
29062 #
29063 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
29064 index 0faad64..39ef157 100644
29065 --- a/arch/x86/vdso/vdso32-setup.c
29066 +++ b/arch/x86/vdso/vdso32-setup.c
29067 @@ -25,6 +25,7 @@
29068 #include <asm/tlbflush.h>
29069 #include <asm/vdso.h>
29070 #include <asm/proto.h>
29071 +#include <asm/mman.h>
29072
29073 enum {
29074 VDSO_DISABLED = 0,
29075 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
29076 void enable_sep_cpu(void)
29077 {
29078 int cpu = get_cpu();
29079 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
29080 + struct tss_struct *tss = init_tss + cpu;
29081
29082 if (!boot_cpu_has(X86_FEATURE_SEP)) {
29083 put_cpu();
29084 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
29085 gate_vma.vm_start = FIXADDR_USER_START;
29086 gate_vma.vm_end = FIXADDR_USER_END;
29087 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
29088 - gate_vma.vm_page_prot = __P101;
29089 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
29090
29091 return 0;
29092 }
29093 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
29094 if (compat)
29095 addr = VDSO_HIGH_BASE;
29096 else {
29097 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
29098 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
29099 if (IS_ERR_VALUE(addr)) {
29100 ret = addr;
29101 goto up_fail;
29102 }
29103 }
29104
29105 - current->mm->context.vdso = (void *)addr;
29106 + current->mm->context.vdso = addr;
29107
29108 if (compat_uses_vma || !compat) {
29109 /*
29110 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
29111 }
29112
29113 current_thread_info()->sysenter_return =
29114 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
29115 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
29116
29117 up_fail:
29118 if (ret)
29119 - current->mm->context.vdso = NULL;
29120 + current->mm->context.vdso = 0;
29121
29122 up_write(&mm->mmap_sem);
29123
29124 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
29125
29126 const char *arch_vma_name(struct vm_area_struct *vma)
29127 {
29128 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
29129 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
29130 return "[vdso]";
29131 +
29132 +#ifdef CONFIG_PAX_SEGMEXEC
29133 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
29134 + return "[vdso]";
29135 +#endif
29136 +
29137 return NULL;
29138 }
29139
29140 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
29141 * Check to see if the corresponding task was created in compat vdso
29142 * mode.
29143 */
29144 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
29145 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
29146 return &gate_vma;
29147 return NULL;
29148 }
29149 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
29150 index 00aaf04..4a26505 100644
29151 --- a/arch/x86/vdso/vma.c
29152 +++ b/arch/x86/vdso/vma.c
29153 @@ -16,8 +16,6 @@
29154 #include <asm/vdso.h>
29155 #include <asm/page.h>
29156
29157 -unsigned int __read_mostly vdso_enabled = 1;
29158 -
29159 extern char vdso_start[], vdso_end[];
29160 extern unsigned short vdso_sync_cpuid;
29161
29162 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
29163 * unaligned here as a result of stack start randomization.
29164 */
29165 addr = PAGE_ALIGN(addr);
29166 - addr = align_addr(addr, NULL, ALIGN_VDSO);
29167
29168 return addr;
29169 }
29170 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
29171 unsigned size)
29172 {
29173 struct mm_struct *mm = current->mm;
29174 - unsigned long addr;
29175 + unsigned long addr = 0;
29176 int ret;
29177
29178 - if (!vdso_enabled)
29179 - return 0;
29180 -
29181 down_write(&mm->mmap_sem);
29182 +
29183 +#ifdef CONFIG_PAX_RANDMMAP
29184 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
29185 +#endif
29186 +
29187 addr = vdso_addr(mm->start_stack, size);
29188 + addr = align_addr(addr, NULL, ALIGN_VDSO);
29189 addr = get_unmapped_area(NULL, addr, size, 0, 0);
29190 if (IS_ERR_VALUE(addr)) {
29191 ret = addr;
29192 goto up_fail;
29193 }
29194
29195 - current->mm->context.vdso = (void *)addr;
29196 + mm->context.vdso = addr;
29197
29198 ret = install_special_mapping(mm, addr, size,
29199 VM_READ|VM_EXEC|
29200 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
29201 pages);
29202 - if (ret) {
29203 - current->mm->context.vdso = NULL;
29204 - goto up_fail;
29205 - }
29206 + if (ret)
29207 + mm->context.vdso = 0;
29208
29209 up_fail:
29210 up_write(&mm->mmap_sem);
29211 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
29212 vdsox32_size);
29213 }
29214 #endif
29215 -
29216 -static __init int vdso_setup(char *s)
29217 -{
29218 - vdso_enabled = simple_strtoul(s, NULL, 0);
29219 - return 0;
29220 -}
29221 -__setup("vdso=", vdso_setup);
29222 diff --git a/arch/x86/xen/apic.c b/arch/x86/xen/apic.c
29223 index 7005ced..530d6eb 100644
29224 --- a/arch/x86/xen/apic.c
29225 +++ b/arch/x86/xen/apic.c
29226 @@ -30,5 +30,5 @@ static unsigned int xen_io_apic_read(unsigned apic, unsigned reg)
29227
29228 void __init xen_init_apic(void)
29229 {
29230 - x86_io_apic_ops.read = xen_io_apic_read;
29231 + *(void **)&x86_io_apic_ops.read = xen_io_apic_read;
29232 }
29233 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
29234 index 586d838..9181904 100644
29235 --- a/arch/x86/xen/enlighten.c
29236 +++ b/arch/x86/xen/enlighten.c
29237 @@ -99,8 +99,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
29238
29239 struct shared_info xen_dummy_shared_info;
29240
29241 -void *xen_initial_gdt;
29242 -
29243 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
29244 __read_mostly int xen_have_vector_callback;
29245 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
29246 @@ -473,8 +471,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
29247 {
29248 unsigned long va = dtr->address;
29249 unsigned int size = dtr->size + 1;
29250 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
29251 - unsigned long frames[pages];
29252 + unsigned long frames[65536 / PAGE_SIZE];
29253 int f;
29254
29255 /*
29256 @@ -522,8 +519,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
29257 {
29258 unsigned long va = dtr->address;
29259 unsigned int size = dtr->size + 1;
29260 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
29261 - unsigned long frames[pages];
29262 + unsigned long frames[65536 / PAGE_SIZE];
29263 int f;
29264
29265 /*
29266 @@ -918,21 +914,21 @@ static u32 xen_safe_apic_wait_icr_idle(void)
29267
29268 static void set_xen_basic_apic_ops(void)
29269 {
29270 - apic->read = xen_apic_read;
29271 - apic->write = xen_apic_write;
29272 - apic->icr_read = xen_apic_icr_read;
29273 - apic->icr_write = xen_apic_icr_write;
29274 - apic->wait_icr_idle = xen_apic_wait_icr_idle;
29275 - apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
29276 - apic->set_apic_id = xen_set_apic_id;
29277 - apic->get_apic_id = xen_get_apic_id;
29278 + *(void **)&apic->read = xen_apic_read;
29279 + *(void **)&apic->write = xen_apic_write;
29280 + *(void **)&apic->icr_read = xen_apic_icr_read;
29281 + *(void **)&apic->icr_write = xen_apic_icr_write;
29282 + *(void **)&apic->wait_icr_idle = xen_apic_wait_icr_idle;
29283 + *(void **)&apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
29284 + *(void **)&apic->set_apic_id = xen_set_apic_id;
29285 + *(void **)&apic->get_apic_id = xen_get_apic_id;
29286
29287 #ifdef CONFIG_SMP
29288 - apic->send_IPI_allbutself = xen_send_IPI_allbutself;
29289 - apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
29290 - apic->send_IPI_mask = xen_send_IPI_mask;
29291 - apic->send_IPI_all = xen_send_IPI_all;
29292 - apic->send_IPI_self = xen_send_IPI_self;
29293 + *(void **)&apic->send_IPI_allbutself = xen_send_IPI_allbutself;
29294 + *(void **)&apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
29295 + *(void **)&apic->send_IPI_mask = xen_send_IPI_mask;
29296 + *(void **)&apic->send_IPI_all = xen_send_IPI_all;
29297 + *(void **)&apic->send_IPI_self = xen_send_IPI_self;
29298 #endif
29299 }
29300
29301 @@ -1222,30 +1218,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
29302 #endif
29303 };
29304
29305 -static void xen_reboot(int reason)
29306 +static __noreturn void xen_reboot(int reason)
29307 {
29308 struct sched_shutdown r = { .reason = reason };
29309
29310 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
29311 - BUG();
29312 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
29313 + BUG();
29314 }
29315
29316 -static void xen_restart(char *msg)
29317 +static __noreturn void xen_restart(char *msg)
29318 {
29319 xen_reboot(SHUTDOWN_reboot);
29320 }
29321
29322 -static void xen_emergency_restart(void)
29323 +static __noreturn void xen_emergency_restart(void)
29324 {
29325 xen_reboot(SHUTDOWN_reboot);
29326 }
29327
29328 -static void xen_machine_halt(void)
29329 +static __noreturn void xen_machine_halt(void)
29330 {
29331 xen_reboot(SHUTDOWN_poweroff);
29332 }
29333
29334 -static void xen_machine_power_off(void)
29335 +static __noreturn void xen_machine_power_off(void)
29336 {
29337 if (pm_power_off)
29338 pm_power_off();
29339 @@ -1290,14 +1286,14 @@ static const struct machine_ops xen_machine_ops __initconst = {
29340 */
29341 static void __init xen_setup_stackprotector(void)
29342 {
29343 - pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry_boot;
29344 - pv_cpu_ops.load_gdt = xen_load_gdt_boot;
29345 + *(void **)&pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry_boot;
29346 + *(void **)&pv_cpu_ops.load_gdt = xen_load_gdt_boot;
29347
29348 setup_stack_canary_segment(0);
29349 switch_to_new_gdt(0);
29350
29351 - pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry;
29352 - pv_cpu_ops.load_gdt = xen_load_gdt;
29353 + *(void **)&pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry;
29354 + *(void **)&pv_cpu_ops.load_gdt = xen_load_gdt;
29355 }
29356
29357 /* First C function to be called on Xen boot */
29358 @@ -1315,13 +1311,13 @@ asmlinkage void __init xen_start_kernel(void)
29359
29360 /* Install Xen paravirt ops */
29361 pv_info = xen_info;
29362 - pv_init_ops = xen_init_ops;
29363 - pv_cpu_ops = xen_cpu_ops;
29364 - pv_apic_ops = xen_apic_ops;
29365 + memcpy((void *)&pv_init_ops, &xen_init_ops, sizeof pv_init_ops);
29366 + memcpy((void *)&pv_cpu_ops, &xen_cpu_ops, sizeof pv_cpu_ops);
29367 + memcpy((void *)&pv_apic_ops, &xen_apic_ops, sizeof pv_apic_ops);
29368
29369 - x86_init.resources.memory_setup = xen_memory_setup;
29370 - x86_init.oem.arch_setup = xen_arch_setup;
29371 - x86_init.oem.banner = xen_banner;
29372 + *(void **)&x86_init.resources.memory_setup = xen_memory_setup;
29373 + *(void **)&x86_init.oem.arch_setup = xen_arch_setup;
29374 + *(void **)&x86_init.oem.banner = xen_banner;
29375
29376 xen_init_time_ops();
29377
29378 @@ -1347,7 +1343,17 @@ asmlinkage void __init xen_start_kernel(void)
29379 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
29380
29381 /* Work out if we support NX */
29382 - x86_configure_nx();
29383 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29384 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
29385 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
29386 + unsigned l, h;
29387 +
29388 + __supported_pte_mask |= _PAGE_NX;
29389 + rdmsr(MSR_EFER, l, h);
29390 + l |= EFER_NX;
29391 + wrmsr(MSR_EFER, l, h);
29392 + }
29393 +#endif
29394
29395 xen_setup_features();
29396
29397 @@ -1376,14 +1382,7 @@ asmlinkage void __init xen_start_kernel(void)
29398 pv_mmu_ops.ptep_modify_prot_commit = xen_ptep_modify_prot_commit;
29399 }
29400
29401 - machine_ops = xen_machine_ops;
29402 -
29403 - /*
29404 - * The only reliable way to retain the initial address of the
29405 - * percpu gdt_page is to remember it here, so we can go and
29406 - * mark it RW later, when the initial percpu area is freed.
29407 - */
29408 - xen_initial_gdt = &per_cpu(gdt_page, 0);
29409 + memcpy((void *)&machine_ops, &xen_machine_ops, sizeof machine_ops);
29410
29411 xen_smp_init();
29412
29413 @@ -1450,7 +1449,7 @@ asmlinkage void __init xen_start_kernel(void)
29414 add_preferred_console("tty", 0, NULL);
29415 add_preferred_console("hvc", 0, NULL);
29416 if (pci_xen)
29417 - x86_init.pci.arch_init = pci_xen_init;
29418 + *(void **)&x86_init.pci.arch_init = pci_xen_init;
29419 } else {
29420 const struct dom0_vga_console_info *info =
29421 (void *)((char *)xen_start_info +
29422 @@ -1476,8 +1475,8 @@ asmlinkage void __init xen_start_kernel(void)
29423 xen_acpi_sleep_register();
29424
29425 /* Avoid searching for BIOS MP tables */
29426 - x86_init.mpparse.find_smp_config = x86_init_noop;
29427 - x86_init.mpparse.get_smp_config = x86_init_uint_noop;
29428 + *(void **)&x86_init.mpparse.find_smp_config = x86_init_noop;
29429 + *(void **)&x86_init.mpparse.get_smp_config = x86_init_uint_noop;
29430 }
29431 #ifdef CONFIG_PCI
29432 /* PCI BIOS service won't work from a PV guest. */
29433 @@ -1583,7 +1582,7 @@ static void __init xen_hvm_guest_init(void)
29434 xen_hvm_smp_init();
29435 register_cpu_notifier(&xen_hvm_cpu_notifier);
29436 xen_unplug_emulated_devices();
29437 - x86_init.irqs.intr_init = xen_init_IRQ;
29438 + *(void **)&x86_init.irqs.intr_init = xen_init_IRQ;
29439 xen_hvm_init_time_ops();
29440 xen_hvm_init_mmu_ops();
29441 }
29442 diff --git a/arch/x86/xen/irq.c b/arch/x86/xen/irq.c
29443 index 01a4dc0..3ca0cc9 100644
29444 --- a/arch/x86/xen/irq.c
29445 +++ b/arch/x86/xen/irq.c
29446 @@ -130,5 +130,5 @@ static const struct pv_irq_ops xen_irq_ops __initconst = {
29447 void __init xen_init_irq_ops(void)
29448 {
29449 pv_irq_ops = xen_irq_ops;
29450 - x86_init.irqs.intr_init = xen_init_IRQ;
29451 + *(void **)&x86_init.irqs.intr_init = xen_init_IRQ;
29452 }
29453 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
29454 index dcf5f2d..5f72fe7 100644
29455 --- a/arch/x86/xen/mmu.c
29456 +++ b/arch/x86/xen/mmu.c
29457 @@ -1881,6 +1881,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
29458 /* L3_k[510] -> level2_kernel_pgt
29459 * L3_i[511] -> level2_fixmap_pgt */
29460 convert_pfn_mfn(level3_kernel_pgt);
29461 + convert_pfn_mfn(level3_vmalloc_start_pgt);
29462 + convert_pfn_mfn(level3_vmalloc_end_pgt);
29463 + convert_pfn_mfn(level3_vmemmap_pgt);
29464
29465 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
29466 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
29467 @@ -1910,8 +1913,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
29468 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
29469 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
29470 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
29471 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
29472 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
29473 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
29474 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
29475 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
29476 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
29477 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
29478 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
29479
29480 @@ -2097,6 +2104,7 @@ static void __init xen_post_allocator_init(void)
29481 pv_mmu_ops.set_pud = xen_set_pud;
29482 #if PAGETABLE_LEVELS == 4
29483 pv_mmu_ops.set_pgd = xen_set_pgd;
29484 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
29485 #endif
29486
29487 /* This will work as long as patching hasn't happened yet
29488 @@ -2178,6 +2186,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
29489 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
29490 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
29491 .set_pgd = xen_set_pgd_hyper,
29492 + .set_pgd_batched = xen_set_pgd_hyper,
29493
29494 .alloc_pud = xen_alloc_pmd_init,
29495 .release_pud = xen_release_pmd_init,
29496 @@ -2197,8 +2206,8 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
29497
29498 void __init xen_init_mmu_ops(void)
29499 {
29500 - x86_init.mapping.pagetable_reserve = xen_mapping_pagetable_reserve;
29501 - x86_init.paging.pagetable_init = xen_pagetable_init;
29502 + *(void **)&x86_init.mapping.pagetable_reserve = xen_mapping_pagetable_reserve;
29503 + *(void **)&x86_init.paging.pagetable_init = xen_pagetable_init;
29504 pv_mmu_ops = xen_mmu_ops;
29505
29506 memset(dummy_mapping, 0xff, PAGE_SIZE);
29507 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
29508 index 353c50f..a0b9b0d 100644
29509 --- a/arch/x86/xen/smp.c
29510 +++ b/arch/x86/xen/smp.c
29511 @@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
29512 {
29513 BUG_ON(smp_processor_id() != 0);
29514 native_smp_prepare_boot_cpu();
29515 -
29516 - /* We've switched to the "real" per-cpu gdt, so make sure the
29517 - old memory can be recycled */
29518 - make_lowmem_page_readwrite(xen_initial_gdt);
29519 -
29520 xen_filter_cpu_maps();
29521 xen_setup_vcpu_info_placement();
29522 }
29523 @@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
29524 gdt = get_cpu_gdt_table(cpu);
29525
29526 ctxt->flags = VGCF_IN_KERNEL;
29527 - ctxt->user_regs.ds = __USER_DS;
29528 - ctxt->user_regs.es = __USER_DS;
29529 + ctxt->user_regs.ds = __KERNEL_DS;
29530 + ctxt->user_regs.es = __KERNEL_DS;
29531 ctxt->user_regs.ss = __KERNEL_DS;
29532 #ifdef CONFIG_X86_32
29533 ctxt->user_regs.fs = __KERNEL_PERCPU;
29534 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
29535 + savesegment(gs, ctxt->user_regs.gs);
29536 #else
29537 ctxt->gs_base_kernel = per_cpu_offset(cpu);
29538 #endif
29539 @@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
29540 int rc;
29541
29542 per_cpu(current_task, cpu) = idle;
29543 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
29544 #ifdef CONFIG_X86_32
29545 irq_ctx_init(cpu);
29546 #else
29547 clear_tsk_thread_flag(idle, TIF_FORK);
29548 - per_cpu(kernel_stack, cpu) =
29549 - (unsigned long)task_stack_page(idle) -
29550 - KERNEL_STACK_OFFSET + THREAD_SIZE;
29551 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
29552 #endif
29553 xen_setup_runstate_info(cpu);
29554 xen_setup_timer(cpu);
29555 @@ -637,7 +631,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
29556
29557 void __init xen_smp_init(void)
29558 {
29559 - smp_ops = xen_smp_ops;
29560 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
29561 xen_fill_possible_map();
29562 xen_init_spinlocks();
29563 }
29564 @@ -672,10 +666,10 @@ void __init xen_hvm_smp_init(void)
29565 {
29566 if (!xen_have_vector_callback)
29567 return;
29568 - smp_ops.smp_prepare_cpus = xen_hvm_smp_prepare_cpus;
29569 - smp_ops.smp_send_reschedule = xen_smp_send_reschedule;
29570 - smp_ops.cpu_up = xen_hvm_cpu_up;
29571 - smp_ops.cpu_die = xen_hvm_cpu_die;
29572 - smp_ops.send_call_func_ipi = xen_smp_send_call_function_ipi;
29573 - smp_ops.send_call_func_single_ipi = xen_smp_send_call_function_single_ipi;
29574 + *(void **)&smp_ops.smp_prepare_cpus = xen_hvm_smp_prepare_cpus;
29575 + *(void **)&smp_ops.smp_send_reschedule = xen_smp_send_reschedule;
29576 + *(void **)&smp_ops.cpu_up = xen_hvm_cpu_up;
29577 + *(void **)&smp_ops.cpu_die = xen_hvm_cpu_die;
29578 + *(void **)&smp_ops.send_call_func_ipi = xen_smp_send_call_function_ipi;
29579 + *(void **)&smp_ops.send_call_func_single_ipi = xen_smp_send_call_function_single_ipi;
29580 }
29581 diff --git a/arch/x86/xen/spinlock.c b/arch/x86/xen/spinlock.c
29582 index 83e866d..ef60385 100644
29583 --- a/arch/x86/xen/spinlock.c
29584 +++ b/arch/x86/xen/spinlock.c
29585 @@ -390,12 +390,12 @@ void __init xen_init_spinlocks(void)
29586 {
29587 BUILD_BUG_ON(sizeof(struct xen_spinlock) > sizeof(arch_spinlock_t));
29588
29589 - pv_lock_ops.spin_is_locked = xen_spin_is_locked;
29590 - pv_lock_ops.spin_is_contended = xen_spin_is_contended;
29591 - pv_lock_ops.spin_lock = xen_spin_lock;
29592 - pv_lock_ops.spin_lock_flags = xen_spin_lock_flags;
29593 - pv_lock_ops.spin_trylock = xen_spin_trylock;
29594 - pv_lock_ops.spin_unlock = xen_spin_unlock;
29595 + *(void **)&pv_lock_ops.spin_is_locked = xen_spin_is_locked;
29596 + *(void **)&pv_lock_ops.spin_is_contended = xen_spin_is_contended;
29597 + *(void **)&pv_lock_ops.spin_lock = xen_spin_lock;
29598 + *(void **)&pv_lock_ops.spin_lock_flags = xen_spin_lock_flags;
29599 + *(void **)&pv_lock_ops.spin_trylock = xen_spin_trylock;
29600 + *(void **)&pv_lock_ops.spin_unlock = xen_spin_unlock;
29601 }
29602
29603 #ifdef CONFIG_XEN_DEBUG_FS
29604 diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c
29605 index 0296a95..3c51a2d 100644
29606 --- a/arch/x86/xen/time.c
29607 +++ b/arch/x86/xen/time.c
29608 @@ -481,15 +481,15 @@ static void __init xen_time_init(void)
29609
29610 void __init xen_init_time_ops(void)
29611 {
29612 - pv_time_ops = xen_time_ops;
29613 + memcpy((void *)&pv_time_ops, &xen_time_ops, sizeof pv_time_ops);
29614
29615 - x86_init.timers.timer_init = xen_time_init;
29616 - x86_init.timers.setup_percpu_clockev = x86_init_noop;
29617 - x86_cpuinit.setup_percpu_clockev = x86_init_noop;
29618 + *(void **)&x86_init.timers.timer_init = xen_time_init;
29619 + *(void **)&x86_init.timers.setup_percpu_clockev = x86_init_noop;
29620 + *(void **)&x86_cpuinit.setup_percpu_clockev = x86_init_noop;
29621
29622 - x86_platform.calibrate_tsc = xen_tsc_khz;
29623 - x86_platform.get_wallclock = xen_get_wallclock;
29624 - x86_platform.set_wallclock = xen_set_wallclock;
29625 + *(void **)&x86_platform.calibrate_tsc = xen_tsc_khz;
29626 + *(void **)&x86_platform.get_wallclock = xen_get_wallclock;
29627 + *(void **)&x86_platform.set_wallclock = xen_set_wallclock;
29628 }
29629
29630 #ifdef CONFIG_XEN_PVHVM
29631 @@ -514,12 +514,12 @@ void __init xen_hvm_init_time_ops(void)
29632 return;
29633 }
29634
29635 - pv_time_ops = xen_time_ops;
29636 - x86_init.timers.setup_percpu_clockev = xen_time_init;
29637 - x86_cpuinit.setup_percpu_clockev = xen_hvm_setup_cpu_clockevents;
29638 + memcpy((void *)&pv_time_ops, &xen_time_ops, sizeof pv_time_ops);
29639 + *(void **)&x86_init.timers.setup_percpu_clockev = xen_time_init;
29640 + *(void **)&x86_cpuinit.setup_percpu_clockev = xen_hvm_setup_cpu_clockevents;
29641
29642 - x86_platform.calibrate_tsc = xen_tsc_khz;
29643 - x86_platform.get_wallclock = xen_get_wallclock;
29644 - x86_platform.set_wallclock = xen_set_wallclock;
29645 + *(void **)&x86_platform.calibrate_tsc = xen_tsc_khz;
29646 + *(void **)&x86_platform.get_wallclock = xen_get_wallclock;
29647 + *(void **)&x86_platform.set_wallclock = xen_set_wallclock;
29648 }
29649 #endif
29650 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
29651 index f9643fc..602e8af 100644
29652 --- a/arch/x86/xen/xen-asm_32.S
29653 +++ b/arch/x86/xen/xen-asm_32.S
29654 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
29655 ESP_OFFSET=4 # bytes pushed onto stack
29656
29657 /*
29658 - * Store vcpu_info pointer for easy access. Do it this way to
29659 - * avoid having to reload %fs
29660 + * Store vcpu_info pointer for easy access.
29661 */
29662 #ifdef CONFIG_SMP
29663 - GET_THREAD_INFO(%eax)
29664 - movl TI_cpu(%eax), %eax
29665 - movl __per_cpu_offset(,%eax,4), %eax
29666 - mov xen_vcpu(%eax), %eax
29667 + push %fs
29668 + mov $(__KERNEL_PERCPU), %eax
29669 + mov %eax, %fs
29670 + mov PER_CPU_VAR(xen_vcpu), %eax
29671 + pop %fs
29672 #else
29673 movl xen_vcpu, %eax
29674 #endif
29675 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
29676 index 7faed58..ba4427c 100644
29677 --- a/arch/x86/xen/xen-head.S
29678 +++ b/arch/x86/xen/xen-head.S
29679 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
29680 #ifdef CONFIG_X86_32
29681 mov %esi,xen_start_info
29682 mov $init_thread_union+THREAD_SIZE,%esp
29683 +#ifdef CONFIG_SMP
29684 + movl $cpu_gdt_table,%edi
29685 + movl $__per_cpu_load,%eax
29686 + movw %ax,__KERNEL_PERCPU + 2(%edi)
29687 + rorl $16,%eax
29688 + movb %al,__KERNEL_PERCPU + 4(%edi)
29689 + movb %ah,__KERNEL_PERCPU + 7(%edi)
29690 + movl $__per_cpu_end - 1,%eax
29691 + subl $__per_cpu_start,%eax
29692 + movw %ax,__KERNEL_PERCPU + 0(%edi)
29693 +#endif
29694 #else
29695 mov %rsi,xen_start_info
29696 mov $init_thread_union+THREAD_SIZE,%rsp
29697 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
29698 index a95b417..b6dbd0b 100644
29699 --- a/arch/x86/xen/xen-ops.h
29700 +++ b/arch/x86/xen/xen-ops.h
29701 @@ -10,8 +10,6 @@
29702 extern const char xen_hypervisor_callback[];
29703 extern const char xen_failsafe_callback[];
29704
29705 -extern void *xen_initial_gdt;
29706 -
29707 struct trap_info;
29708 void xen_copy_trap_info(struct trap_info *traps);
29709
29710 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
29711 index 525bd3d..ef888b1 100644
29712 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
29713 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
29714 @@ -119,9 +119,9 @@
29715 ----------------------------------------------------------------------*/
29716
29717 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
29718 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
29719 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
29720 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
29721 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
29722
29723 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
29724 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
29725 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
29726 index 2f33760..835e50a 100644
29727 --- a/arch/xtensa/variants/fsf/include/variant/core.h
29728 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
29729 @@ -11,6 +11,7 @@
29730 #ifndef _XTENSA_CORE_H
29731 #define _XTENSA_CORE_H
29732
29733 +#include <linux/const.h>
29734
29735 /****************************************************************************
29736 Parameters Useful for Any Code, USER or PRIVILEGED
29737 @@ -112,9 +113,9 @@
29738 ----------------------------------------------------------------------*/
29739
29740 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
29741 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
29742 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
29743 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
29744 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
29745
29746 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
29747 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
29748 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
29749 index af00795..2bb8105 100644
29750 --- a/arch/xtensa/variants/s6000/include/variant/core.h
29751 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
29752 @@ -11,6 +11,7 @@
29753 #ifndef _XTENSA_CORE_CONFIGURATION_H
29754 #define _XTENSA_CORE_CONFIGURATION_H
29755
29756 +#include <linux/const.h>
29757
29758 /****************************************************************************
29759 Parameters Useful for Any Code, USER or PRIVILEGED
29760 @@ -118,9 +119,9 @@
29761 ----------------------------------------------------------------------*/
29762
29763 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
29764 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
29765 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
29766 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
29767 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
29768
29769 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
29770 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
29771 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
29772 index 58916af..9cb880b 100644
29773 --- a/block/blk-iopoll.c
29774 +++ b/block/blk-iopoll.c
29775 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
29776 }
29777 EXPORT_SYMBOL(blk_iopoll_complete);
29778
29779 -static void blk_iopoll_softirq(struct softirq_action *h)
29780 +static void blk_iopoll_softirq(void)
29781 {
29782 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
29783 int rearm = 0, budget = blk_iopoll_budget;
29784 diff --git a/block/blk-map.c b/block/blk-map.c
29785 index 623e1cd..ca1e109 100644
29786 --- a/block/blk-map.c
29787 +++ b/block/blk-map.c
29788 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
29789 if (!len || !kbuf)
29790 return -EINVAL;
29791
29792 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
29793 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
29794 if (do_copy)
29795 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
29796 else
29797 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
29798 index 467c8de..4bddc6d 100644
29799 --- a/block/blk-softirq.c
29800 +++ b/block/blk-softirq.c
29801 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
29802 * Softirq action handler - move entries to local list and loop over them
29803 * while passing them to the queue registered handler.
29804 */
29805 -static void blk_done_softirq(struct softirq_action *h)
29806 +static void blk_done_softirq(void)
29807 {
29808 struct list_head *cpu_list, local_list;
29809
29810 diff --git a/block/bsg.c b/block/bsg.c
29811 index ff64ae3..593560c 100644
29812 --- a/block/bsg.c
29813 +++ b/block/bsg.c
29814 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
29815 struct sg_io_v4 *hdr, struct bsg_device *bd,
29816 fmode_t has_write_perm)
29817 {
29818 + unsigned char tmpcmd[sizeof(rq->__cmd)];
29819 + unsigned char *cmdptr;
29820 +
29821 if (hdr->request_len > BLK_MAX_CDB) {
29822 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
29823 if (!rq->cmd)
29824 return -ENOMEM;
29825 - }
29826 + cmdptr = rq->cmd;
29827 + } else
29828 + cmdptr = tmpcmd;
29829
29830 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
29831 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
29832 hdr->request_len))
29833 return -EFAULT;
29834
29835 + if (cmdptr != rq->cmd)
29836 + memcpy(rq->cmd, cmdptr, hdr->request_len);
29837 +
29838 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
29839 if (blk_verify_command(rq->cmd, has_write_perm))
29840 return -EPERM;
29841 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
29842 index 7c668c8..db3521c 100644
29843 --- a/block/compat_ioctl.c
29844 +++ b/block/compat_ioctl.c
29845 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
29846 err |= __get_user(f->spec1, &uf->spec1);
29847 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
29848 err |= __get_user(name, &uf->name);
29849 - f->name = compat_ptr(name);
29850 + f->name = (void __force_kernel *)compat_ptr(name);
29851 if (err) {
29852 err = -EFAULT;
29853 goto out;
29854 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
29855 index 6296b40..417c00f 100644
29856 --- a/block/partitions/efi.c
29857 +++ b/block/partitions/efi.c
29858 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
29859 if (!gpt)
29860 return NULL;
29861
29862 + if (!le32_to_cpu(gpt->num_partition_entries))
29863 + return NULL;
29864 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
29865 + if (!pte)
29866 + return NULL;
29867 +
29868 count = le32_to_cpu(gpt->num_partition_entries) *
29869 le32_to_cpu(gpt->sizeof_partition_entry);
29870 - if (!count)
29871 - return NULL;
29872 - pte = kzalloc(count, GFP_KERNEL);
29873 - if (!pte)
29874 - return NULL;
29875 -
29876 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
29877 (u8 *) pte,
29878 count) < count) {
29879 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
29880 index 9a87daa..fb17486 100644
29881 --- a/block/scsi_ioctl.c
29882 +++ b/block/scsi_ioctl.c
29883 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
29884 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
29885 struct sg_io_hdr *hdr, fmode_t mode)
29886 {
29887 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
29888 + unsigned char tmpcmd[sizeof(rq->__cmd)];
29889 + unsigned char *cmdptr;
29890 +
29891 + if (rq->cmd != rq->__cmd)
29892 + cmdptr = rq->cmd;
29893 + else
29894 + cmdptr = tmpcmd;
29895 +
29896 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
29897 return -EFAULT;
29898 +
29899 + if (cmdptr != rq->cmd)
29900 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
29901 +
29902 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
29903 return -EPERM;
29904
29905 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
29906 int err;
29907 unsigned int in_len, out_len, bytes, opcode, cmdlen;
29908 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
29909 + unsigned char tmpcmd[sizeof(rq->__cmd)];
29910 + unsigned char *cmdptr;
29911
29912 if (!sic)
29913 return -EINVAL;
29914 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
29915 */
29916 err = -EFAULT;
29917 rq->cmd_len = cmdlen;
29918 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
29919 +
29920 + if (rq->cmd != rq->__cmd)
29921 + cmdptr = rq->cmd;
29922 + else
29923 + cmdptr = tmpcmd;
29924 +
29925 + if (copy_from_user(cmdptr, sic->data, cmdlen))
29926 goto error;
29927
29928 + if (rq->cmd != cmdptr)
29929 + memcpy(rq->cmd, cmdptr, cmdlen);
29930 +
29931 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
29932 goto error;
29933
29934 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
29935 index 7bdd61b..afec999 100644
29936 --- a/crypto/cryptd.c
29937 +++ b/crypto/cryptd.c
29938 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
29939
29940 struct cryptd_blkcipher_request_ctx {
29941 crypto_completion_t complete;
29942 -};
29943 +} __no_const;
29944
29945 struct cryptd_hash_ctx {
29946 struct crypto_shash *child;
29947 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
29948
29949 struct cryptd_aead_request_ctx {
29950 crypto_completion_t complete;
29951 -};
29952 +} __no_const;
29953
29954 static void cryptd_queue_worker(struct work_struct *work);
29955
29956 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
29957 index e6defd8..c26a225 100644
29958 --- a/drivers/acpi/apei/cper.c
29959 +++ b/drivers/acpi/apei/cper.c
29960 @@ -38,12 +38,12 @@
29961 */
29962 u64 cper_next_record_id(void)
29963 {
29964 - static atomic64_t seq;
29965 + static atomic64_unchecked_t seq;
29966
29967 - if (!atomic64_read(&seq))
29968 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
29969 + if (!atomic64_read_unchecked(&seq))
29970 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
29971
29972 - return atomic64_inc_return(&seq);
29973 + return atomic64_inc_return_unchecked(&seq);
29974 }
29975 EXPORT_SYMBOL_GPL(cper_next_record_id);
29976
29977 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
29978 index 7586544..636a2f0 100644
29979 --- a/drivers/acpi/ec_sys.c
29980 +++ b/drivers/acpi/ec_sys.c
29981 @@ -12,6 +12,7 @@
29982 #include <linux/acpi.h>
29983 #include <linux/debugfs.h>
29984 #include <linux/module.h>
29985 +#include <linux/uaccess.h>
29986 #include "internal.h"
29987
29988 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
29989 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
29990 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
29991 */
29992 unsigned int size = EC_SPACE_SIZE;
29993 - u8 *data = (u8 *) buf;
29994 + u8 data;
29995 loff_t init_off = *off;
29996 int err = 0;
29997
29998 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
29999 size = count;
30000
30001 while (size) {
30002 - err = ec_read(*off, &data[*off - init_off]);
30003 + err = ec_read(*off, &data);
30004 if (err)
30005 return err;
30006 + if (put_user(data, &buf[*off - init_off]))
30007 + return -EFAULT;
30008 *off += 1;
30009 size--;
30010 }
30011 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
30012
30013 unsigned int size = count;
30014 loff_t init_off = *off;
30015 - u8 *data = (u8 *) buf;
30016 int err = 0;
30017
30018 if (*off >= EC_SPACE_SIZE)
30019 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
30020 }
30021
30022 while (size) {
30023 - u8 byte_write = data[*off - init_off];
30024 + u8 byte_write;
30025 + if (get_user(byte_write, &buf[*off - init_off]))
30026 + return -EFAULT;
30027 err = ec_write(*off, byte_write);
30028 if (err)
30029 return err;
30030 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
30031 index 27adb09..ef98796b 100644
30032 --- a/drivers/acpi/proc.c
30033 +++ b/drivers/acpi/proc.c
30034 @@ -362,16 +362,13 @@ acpi_system_write_wakeup_device(struct file *file,
30035 struct list_head *node, *next;
30036 char strbuf[5];
30037 char str[5] = "";
30038 - unsigned int len = count;
30039
30040 - if (len > 4)
30041 - len = 4;
30042 - if (len < 0)
30043 - return -EFAULT;
30044 + if (count > 4)
30045 + count = 4;
30046
30047 - if (copy_from_user(strbuf, buffer, len))
30048 + if (copy_from_user(strbuf, buffer, count))
30049 return -EFAULT;
30050 - strbuf[len] = '\0';
30051 + strbuf[count] = '\0';
30052 sscanf(strbuf, "%s", str);
30053
30054 mutex_lock(&acpi_device_lock);
30055 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
30056 index bd4e5dc..0497b66 100644
30057 --- a/drivers/acpi/processor_driver.c
30058 +++ b/drivers/acpi/processor_driver.c
30059 @@ -552,7 +552,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
30060 return 0;
30061 #endif
30062
30063 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
30064 + BUG_ON(pr->id >= nr_cpu_ids);
30065
30066 /*
30067 * Buggy BIOS check
30068 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
30069 index c8ac4fe..631818e 100644
30070 --- a/drivers/ata/libata-core.c
30071 +++ b/drivers/ata/libata-core.c
30072 @@ -4779,7 +4779,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
30073 struct ata_port *ap;
30074 unsigned int tag;
30075
30076 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30077 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30078 ap = qc->ap;
30079
30080 qc->flags = 0;
30081 @@ -4795,7 +4795,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
30082 struct ata_port *ap;
30083 struct ata_link *link;
30084
30085 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30086 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30087 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
30088 ap = qc->ap;
30089 link = qc->dev->link;
30090 @@ -5891,6 +5891,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
30091 return;
30092
30093 spin_lock(&lock);
30094 + pax_open_kernel();
30095
30096 for (cur = ops->inherits; cur; cur = cur->inherits) {
30097 void **inherit = (void **)cur;
30098 @@ -5904,8 +5905,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
30099 if (IS_ERR(*pp))
30100 *pp = NULL;
30101
30102 - ops->inherits = NULL;
30103 + *(struct ata_port_operations **)&ops->inherits = NULL;
30104
30105 + pax_close_kernel();
30106 spin_unlock(&lock);
30107 }
30108
30109 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
30110 index 371fd2c..0836c78 100644
30111 --- a/drivers/ata/pata_arasan_cf.c
30112 +++ b/drivers/ata/pata_arasan_cf.c
30113 @@ -861,7 +861,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
30114 /* Handle platform specific quirks */
30115 if (pdata->quirk) {
30116 if (pdata->quirk & CF_BROKEN_PIO) {
30117 - ap->ops->set_piomode = NULL;
30118 + pax_open_kernel();
30119 + *(void **)&ap->ops->set_piomode = NULL;
30120 + pax_close_kernel();
30121 ap->pio_mask = 0;
30122 }
30123 if (pdata->quirk & CF_BROKEN_MWDMA)
30124 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
30125 index f9b983a..887b9d8 100644
30126 --- a/drivers/atm/adummy.c
30127 +++ b/drivers/atm/adummy.c
30128 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
30129 vcc->pop(vcc, skb);
30130 else
30131 dev_kfree_skb_any(skb);
30132 - atomic_inc(&vcc->stats->tx);
30133 + atomic_inc_unchecked(&vcc->stats->tx);
30134
30135 return 0;
30136 }
30137 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
30138 index ff7bb8a..568fc0b 100644
30139 --- a/drivers/atm/ambassador.c
30140 +++ b/drivers/atm/ambassador.c
30141 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
30142 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
30143
30144 // VC layer stats
30145 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
30146 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
30147
30148 // free the descriptor
30149 kfree (tx_descr);
30150 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
30151 dump_skb ("<<<", vc, skb);
30152
30153 // VC layer stats
30154 - atomic_inc(&atm_vcc->stats->rx);
30155 + atomic_inc_unchecked(&atm_vcc->stats->rx);
30156 __net_timestamp(skb);
30157 // end of our responsibility
30158 atm_vcc->push (atm_vcc, skb);
30159 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
30160 } else {
30161 PRINTK (KERN_INFO, "dropped over-size frame");
30162 // should we count this?
30163 - atomic_inc(&atm_vcc->stats->rx_drop);
30164 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
30165 }
30166
30167 } else {
30168 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
30169 }
30170
30171 if (check_area (skb->data, skb->len)) {
30172 - atomic_inc(&atm_vcc->stats->tx_err);
30173 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
30174 return -ENOMEM; // ?
30175 }
30176
30177 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
30178 index b22d71c..d6e1049 100644
30179 --- a/drivers/atm/atmtcp.c
30180 +++ b/drivers/atm/atmtcp.c
30181 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
30182 if (vcc->pop) vcc->pop(vcc,skb);
30183 else dev_kfree_skb(skb);
30184 if (dev_data) return 0;
30185 - atomic_inc(&vcc->stats->tx_err);
30186 + atomic_inc_unchecked(&vcc->stats->tx_err);
30187 return -ENOLINK;
30188 }
30189 size = skb->len+sizeof(struct atmtcp_hdr);
30190 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
30191 if (!new_skb) {
30192 if (vcc->pop) vcc->pop(vcc,skb);
30193 else dev_kfree_skb(skb);
30194 - atomic_inc(&vcc->stats->tx_err);
30195 + atomic_inc_unchecked(&vcc->stats->tx_err);
30196 return -ENOBUFS;
30197 }
30198 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
30199 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
30200 if (vcc->pop) vcc->pop(vcc,skb);
30201 else dev_kfree_skb(skb);
30202 out_vcc->push(out_vcc,new_skb);
30203 - atomic_inc(&vcc->stats->tx);
30204 - atomic_inc(&out_vcc->stats->rx);
30205 + atomic_inc_unchecked(&vcc->stats->tx);
30206 + atomic_inc_unchecked(&out_vcc->stats->rx);
30207 return 0;
30208 }
30209
30210 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
30211 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
30212 read_unlock(&vcc_sklist_lock);
30213 if (!out_vcc) {
30214 - atomic_inc(&vcc->stats->tx_err);
30215 + atomic_inc_unchecked(&vcc->stats->tx_err);
30216 goto done;
30217 }
30218 skb_pull(skb,sizeof(struct atmtcp_hdr));
30219 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
30220 __net_timestamp(new_skb);
30221 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
30222 out_vcc->push(out_vcc,new_skb);
30223 - atomic_inc(&vcc->stats->tx);
30224 - atomic_inc(&out_vcc->stats->rx);
30225 + atomic_inc_unchecked(&vcc->stats->tx);
30226 + atomic_inc_unchecked(&out_vcc->stats->rx);
30227 done:
30228 if (vcc->pop) vcc->pop(vcc,skb);
30229 else dev_kfree_skb(skb);
30230 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
30231 index 81e44f7..498ea36 100644
30232 --- a/drivers/atm/eni.c
30233 +++ b/drivers/atm/eni.c
30234 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
30235 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
30236 vcc->dev->number);
30237 length = 0;
30238 - atomic_inc(&vcc->stats->rx_err);
30239 + atomic_inc_unchecked(&vcc->stats->rx_err);
30240 }
30241 else {
30242 length = ATM_CELL_SIZE-1; /* no HEC */
30243 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
30244 size);
30245 }
30246 eff = length = 0;
30247 - atomic_inc(&vcc->stats->rx_err);
30248 + atomic_inc_unchecked(&vcc->stats->rx_err);
30249 }
30250 else {
30251 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
30252 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
30253 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
30254 vcc->dev->number,vcc->vci,length,size << 2,descr);
30255 length = eff = 0;
30256 - atomic_inc(&vcc->stats->rx_err);
30257 + atomic_inc_unchecked(&vcc->stats->rx_err);
30258 }
30259 }
30260 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
30261 @@ -767,7 +767,7 @@ rx_dequeued++;
30262 vcc->push(vcc,skb);
30263 pushed++;
30264 }
30265 - atomic_inc(&vcc->stats->rx);
30266 + atomic_inc_unchecked(&vcc->stats->rx);
30267 }
30268 wake_up(&eni_dev->rx_wait);
30269 }
30270 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
30271 PCI_DMA_TODEVICE);
30272 if (vcc->pop) vcc->pop(vcc,skb);
30273 else dev_kfree_skb_irq(skb);
30274 - atomic_inc(&vcc->stats->tx);
30275 + atomic_inc_unchecked(&vcc->stats->tx);
30276 wake_up(&eni_dev->tx_wait);
30277 dma_complete++;
30278 }
30279 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
30280 index 86fed1b..6dc4721 100644
30281 --- a/drivers/atm/firestream.c
30282 +++ b/drivers/atm/firestream.c
30283 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
30284 }
30285 }
30286
30287 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
30288 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
30289
30290 fs_dprintk (FS_DEBUG_TXMEM, "i");
30291 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
30292 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
30293 #endif
30294 skb_put (skb, qe->p1 & 0xffff);
30295 ATM_SKB(skb)->vcc = atm_vcc;
30296 - atomic_inc(&atm_vcc->stats->rx);
30297 + atomic_inc_unchecked(&atm_vcc->stats->rx);
30298 __net_timestamp(skb);
30299 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
30300 atm_vcc->push (atm_vcc, skb);
30301 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
30302 kfree (pe);
30303 }
30304 if (atm_vcc)
30305 - atomic_inc(&atm_vcc->stats->rx_drop);
30306 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
30307 break;
30308 case 0x1f: /* Reassembly abort: no buffers. */
30309 /* Silently increment error counter. */
30310 if (atm_vcc)
30311 - atomic_inc(&atm_vcc->stats->rx_drop);
30312 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
30313 break;
30314 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
30315 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
30316 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
30317 index 361f5ae..7fc552d 100644
30318 --- a/drivers/atm/fore200e.c
30319 +++ b/drivers/atm/fore200e.c
30320 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
30321 #endif
30322 /* check error condition */
30323 if (*entry->status & STATUS_ERROR)
30324 - atomic_inc(&vcc->stats->tx_err);
30325 + atomic_inc_unchecked(&vcc->stats->tx_err);
30326 else
30327 - atomic_inc(&vcc->stats->tx);
30328 + atomic_inc_unchecked(&vcc->stats->tx);
30329 }
30330 }
30331
30332 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
30333 if (skb == NULL) {
30334 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
30335
30336 - atomic_inc(&vcc->stats->rx_drop);
30337 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30338 return -ENOMEM;
30339 }
30340
30341 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
30342
30343 dev_kfree_skb_any(skb);
30344
30345 - atomic_inc(&vcc->stats->rx_drop);
30346 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30347 return -ENOMEM;
30348 }
30349
30350 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
30351
30352 vcc->push(vcc, skb);
30353 - atomic_inc(&vcc->stats->rx);
30354 + atomic_inc_unchecked(&vcc->stats->rx);
30355
30356 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
30357
30358 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
30359 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
30360 fore200e->atm_dev->number,
30361 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
30362 - atomic_inc(&vcc->stats->rx_err);
30363 + atomic_inc_unchecked(&vcc->stats->rx_err);
30364 }
30365 }
30366
30367 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
30368 goto retry_here;
30369 }
30370
30371 - atomic_inc(&vcc->stats->tx_err);
30372 + atomic_inc_unchecked(&vcc->stats->tx_err);
30373
30374 fore200e->tx_sat++;
30375 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
30376 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
30377 index b182c2f..1c6fa8a 100644
30378 --- a/drivers/atm/he.c
30379 +++ b/drivers/atm/he.c
30380 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
30381
30382 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
30383 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
30384 - atomic_inc(&vcc->stats->rx_drop);
30385 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30386 goto return_host_buffers;
30387 }
30388
30389 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
30390 RBRQ_LEN_ERR(he_dev->rbrq_head)
30391 ? "LEN_ERR" : "",
30392 vcc->vpi, vcc->vci);
30393 - atomic_inc(&vcc->stats->rx_err);
30394 + atomic_inc_unchecked(&vcc->stats->rx_err);
30395 goto return_host_buffers;
30396 }
30397
30398 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
30399 vcc->push(vcc, skb);
30400 spin_lock(&he_dev->global_lock);
30401
30402 - atomic_inc(&vcc->stats->rx);
30403 + atomic_inc_unchecked(&vcc->stats->rx);
30404
30405 return_host_buffers:
30406 ++pdus_assembled;
30407 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
30408 tpd->vcc->pop(tpd->vcc, tpd->skb);
30409 else
30410 dev_kfree_skb_any(tpd->skb);
30411 - atomic_inc(&tpd->vcc->stats->tx_err);
30412 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
30413 }
30414 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
30415 return;
30416 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30417 vcc->pop(vcc, skb);
30418 else
30419 dev_kfree_skb_any(skb);
30420 - atomic_inc(&vcc->stats->tx_err);
30421 + atomic_inc_unchecked(&vcc->stats->tx_err);
30422 return -EINVAL;
30423 }
30424
30425 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30426 vcc->pop(vcc, skb);
30427 else
30428 dev_kfree_skb_any(skb);
30429 - atomic_inc(&vcc->stats->tx_err);
30430 + atomic_inc_unchecked(&vcc->stats->tx_err);
30431 return -EINVAL;
30432 }
30433 #endif
30434 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30435 vcc->pop(vcc, skb);
30436 else
30437 dev_kfree_skb_any(skb);
30438 - atomic_inc(&vcc->stats->tx_err);
30439 + atomic_inc_unchecked(&vcc->stats->tx_err);
30440 spin_unlock_irqrestore(&he_dev->global_lock, flags);
30441 return -ENOMEM;
30442 }
30443 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30444 vcc->pop(vcc, skb);
30445 else
30446 dev_kfree_skb_any(skb);
30447 - atomic_inc(&vcc->stats->tx_err);
30448 + atomic_inc_unchecked(&vcc->stats->tx_err);
30449 spin_unlock_irqrestore(&he_dev->global_lock, flags);
30450 return -ENOMEM;
30451 }
30452 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30453 __enqueue_tpd(he_dev, tpd, cid);
30454 spin_unlock_irqrestore(&he_dev->global_lock, flags);
30455
30456 - atomic_inc(&vcc->stats->tx);
30457 + atomic_inc_unchecked(&vcc->stats->tx);
30458
30459 return 0;
30460 }
30461 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
30462 index 7d01c2a..4e3ac01 100644
30463 --- a/drivers/atm/horizon.c
30464 +++ b/drivers/atm/horizon.c
30465 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
30466 {
30467 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
30468 // VC layer stats
30469 - atomic_inc(&vcc->stats->rx);
30470 + atomic_inc_unchecked(&vcc->stats->rx);
30471 __net_timestamp(skb);
30472 // end of our responsibility
30473 vcc->push (vcc, skb);
30474 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
30475 dev->tx_iovec = NULL;
30476
30477 // VC layer stats
30478 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
30479 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
30480
30481 // free the skb
30482 hrz_kfree_skb (skb);
30483 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
30484 index 8974bd2..b856f85 100644
30485 --- a/drivers/atm/idt77252.c
30486 +++ b/drivers/atm/idt77252.c
30487 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
30488 else
30489 dev_kfree_skb(skb);
30490
30491 - atomic_inc(&vcc->stats->tx);
30492 + atomic_inc_unchecked(&vcc->stats->tx);
30493 }
30494
30495 atomic_dec(&scq->used);
30496 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30497 if ((sb = dev_alloc_skb(64)) == NULL) {
30498 printk("%s: Can't allocate buffers for aal0.\n",
30499 card->name);
30500 - atomic_add(i, &vcc->stats->rx_drop);
30501 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
30502 break;
30503 }
30504 if (!atm_charge(vcc, sb->truesize)) {
30505 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
30506 card->name);
30507 - atomic_add(i - 1, &vcc->stats->rx_drop);
30508 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
30509 dev_kfree_skb(sb);
30510 break;
30511 }
30512 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30513 ATM_SKB(sb)->vcc = vcc;
30514 __net_timestamp(sb);
30515 vcc->push(vcc, sb);
30516 - atomic_inc(&vcc->stats->rx);
30517 + atomic_inc_unchecked(&vcc->stats->rx);
30518
30519 cell += ATM_CELL_PAYLOAD;
30520 }
30521 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30522 "(CDC: %08x)\n",
30523 card->name, len, rpp->len, readl(SAR_REG_CDC));
30524 recycle_rx_pool_skb(card, rpp);
30525 - atomic_inc(&vcc->stats->rx_err);
30526 + atomic_inc_unchecked(&vcc->stats->rx_err);
30527 return;
30528 }
30529 if (stat & SAR_RSQE_CRC) {
30530 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
30531 recycle_rx_pool_skb(card, rpp);
30532 - atomic_inc(&vcc->stats->rx_err);
30533 + atomic_inc_unchecked(&vcc->stats->rx_err);
30534 return;
30535 }
30536 if (skb_queue_len(&rpp->queue) > 1) {
30537 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30538 RXPRINTK("%s: Can't alloc RX skb.\n",
30539 card->name);
30540 recycle_rx_pool_skb(card, rpp);
30541 - atomic_inc(&vcc->stats->rx_err);
30542 + atomic_inc_unchecked(&vcc->stats->rx_err);
30543 return;
30544 }
30545 if (!atm_charge(vcc, skb->truesize)) {
30546 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30547 __net_timestamp(skb);
30548
30549 vcc->push(vcc, skb);
30550 - atomic_inc(&vcc->stats->rx);
30551 + atomic_inc_unchecked(&vcc->stats->rx);
30552
30553 return;
30554 }
30555 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30556 __net_timestamp(skb);
30557
30558 vcc->push(vcc, skb);
30559 - atomic_inc(&vcc->stats->rx);
30560 + atomic_inc_unchecked(&vcc->stats->rx);
30561
30562 if (skb->truesize > SAR_FB_SIZE_3)
30563 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
30564 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
30565 if (vcc->qos.aal != ATM_AAL0) {
30566 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
30567 card->name, vpi, vci);
30568 - atomic_inc(&vcc->stats->rx_drop);
30569 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30570 goto drop;
30571 }
30572
30573 if ((sb = dev_alloc_skb(64)) == NULL) {
30574 printk("%s: Can't allocate buffers for AAL0.\n",
30575 card->name);
30576 - atomic_inc(&vcc->stats->rx_err);
30577 + atomic_inc_unchecked(&vcc->stats->rx_err);
30578 goto drop;
30579 }
30580
30581 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
30582 ATM_SKB(sb)->vcc = vcc;
30583 __net_timestamp(sb);
30584 vcc->push(vcc, sb);
30585 - atomic_inc(&vcc->stats->rx);
30586 + atomic_inc_unchecked(&vcc->stats->rx);
30587
30588 drop:
30589 skb_pull(queue, 64);
30590 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
30591
30592 if (vc == NULL) {
30593 printk("%s: NULL connection in send().\n", card->name);
30594 - atomic_inc(&vcc->stats->tx_err);
30595 + atomic_inc_unchecked(&vcc->stats->tx_err);
30596 dev_kfree_skb(skb);
30597 return -EINVAL;
30598 }
30599 if (!test_bit(VCF_TX, &vc->flags)) {
30600 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
30601 - atomic_inc(&vcc->stats->tx_err);
30602 + atomic_inc_unchecked(&vcc->stats->tx_err);
30603 dev_kfree_skb(skb);
30604 return -EINVAL;
30605 }
30606 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
30607 break;
30608 default:
30609 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
30610 - atomic_inc(&vcc->stats->tx_err);
30611 + atomic_inc_unchecked(&vcc->stats->tx_err);
30612 dev_kfree_skb(skb);
30613 return -EINVAL;
30614 }
30615
30616 if (skb_shinfo(skb)->nr_frags != 0) {
30617 printk("%s: No scatter-gather yet.\n", card->name);
30618 - atomic_inc(&vcc->stats->tx_err);
30619 + atomic_inc_unchecked(&vcc->stats->tx_err);
30620 dev_kfree_skb(skb);
30621 return -EINVAL;
30622 }
30623 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
30624
30625 err = queue_skb(card, vc, skb, oam);
30626 if (err) {
30627 - atomic_inc(&vcc->stats->tx_err);
30628 + atomic_inc_unchecked(&vcc->stats->tx_err);
30629 dev_kfree_skb(skb);
30630 return err;
30631 }
30632 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
30633 skb = dev_alloc_skb(64);
30634 if (!skb) {
30635 printk("%s: Out of memory in send_oam().\n", card->name);
30636 - atomic_inc(&vcc->stats->tx_err);
30637 + atomic_inc_unchecked(&vcc->stats->tx_err);
30638 return -ENOMEM;
30639 }
30640 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
30641 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
30642 index 96cce6d..62c3ec5 100644
30643 --- a/drivers/atm/iphase.c
30644 +++ b/drivers/atm/iphase.c
30645 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
30646 status = (u_short) (buf_desc_ptr->desc_mode);
30647 if (status & (RX_CER | RX_PTE | RX_OFL))
30648 {
30649 - atomic_inc(&vcc->stats->rx_err);
30650 + atomic_inc_unchecked(&vcc->stats->rx_err);
30651 IF_ERR(printk("IA: bad packet, dropping it");)
30652 if (status & RX_CER) {
30653 IF_ERR(printk(" cause: packet CRC error\n");)
30654 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
30655 len = dma_addr - buf_addr;
30656 if (len > iadev->rx_buf_sz) {
30657 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
30658 - atomic_inc(&vcc->stats->rx_err);
30659 + atomic_inc_unchecked(&vcc->stats->rx_err);
30660 goto out_free_desc;
30661 }
30662
30663 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
30664 ia_vcc = INPH_IA_VCC(vcc);
30665 if (ia_vcc == NULL)
30666 {
30667 - atomic_inc(&vcc->stats->rx_err);
30668 + atomic_inc_unchecked(&vcc->stats->rx_err);
30669 atm_return(vcc, skb->truesize);
30670 dev_kfree_skb_any(skb);
30671 goto INCR_DLE;
30672 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
30673 if ((length > iadev->rx_buf_sz) || (length >
30674 (skb->len - sizeof(struct cpcs_trailer))))
30675 {
30676 - atomic_inc(&vcc->stats->rx_err);
30677 + atomic_inc_unchecked(&vcc->stats->rx_err);
30678 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
30679 length, skb->len);)
30680 atm_return(vcc, skb->truesize);
30681 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
30682
30683 IF_RX(printk("rx_dle_intr: skb push");)
30684 vcc->push(vcc,skb);
30685 - atomic_inc(&vcc->stats->rx);
30686 + atomic_inc_unchecked(&vcc->stats->rx);
30687 iadev->rx_pkt_cnt++;
30688 }
30689 INCR_DLE:
30690 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
30691 {
30692 struct k_sonet_stats *stats;
30693 stats = &PRIV(_ia_dev[board])->sonet_stats;
30694 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
30695 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
30696 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
30697 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
30698 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
30699 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
30700 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
30701 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
30702 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
30703 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
30704 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
30705 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
30706 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
30707 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
30708 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
30709 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
30710 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
30711 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
30712 }
30713 ia_cmds.status = 0;
30714 break;
30715 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
30716 if ((desc == 0) || (desc > iadev->num_tx_desc))
30717 {
30718 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
30719 - atomic_inc(&vcc->stats->tx);
30720 + atomic_inc_unchecked(&vcc->stats->tx);
30721 if (vcc->pop)
30722 vcc->pop(vcc, skb);
30723 else
30724 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
30725 ATM_DESC(skb) = vcc->vci;
30726 skb_queue_tail(&iadev->tx_dma_q, skb);
30727
30728 - atomic_inc(&vcc->stats->tx);
30729 + atomic_inc_unchecked(&vcc->stats->tx);
30730 iadev->tx_pkt_cnt++;
30731 /* Increment transaction counter */
30732 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
30733
30734 #if 0
30735 /* add flow control logic */
30736 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
30737 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
30738 if (iavcc->vc_desc_cnt > 10) {
30739 vcc->tx_quota = vcc->tx_quota * 3 / 4;
30740 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
30741 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
30742 index 68c7588..7036683 100644
30743 --- a/drivers/atm/lanai.c
30744 +++ b/drivers/atm/lanai.c
30745 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
30746 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
30747 lanai_endtx(lanai, lvcc);
30748 lanai_free_skb(lvcc->tx.atmvcc, skb);
30749 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
30750 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
30751 }
30752
30753 /* Try to fill the buffer - don't call unless there is backlog */
30754 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
30755 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
30756 __net_timestamp(skb);
30757 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
30758 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
30759 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
30760 out:
30761 lvcc->rx.buf.ptr = end;
30762 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
30763 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30764 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
30765 "vcc %d\n", lanai->number, (unsigned int) s, vci);
30766 lanai->stats.service_rxnotaal5++;
30767 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30768 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30769 return 0;
30770 }
30771 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
30772 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30773 int bytes;
30774 read_unlock(&vcc_sklist_lock);
30775 DPRINTK("got trashed rx pdu on vci %d\n", vci);
30776 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30777 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30778 lvcc->stats.x.aal5.service_trash++;
30779 bytes = (SERVICE_GET_END(s) * 16) -
30780 (((unsigned long) lvcc->rx.buf.ptr) -
30781 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30782 }
30783 if (s & SERVICE_STREAM) {
30784 read_unlock(&vcc_sklist_lock);
30785 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30786 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30787 lvcc->stats.x.aal5.service_stream++;
30788 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
30789 "PDU on VCI %d!\n", lanai->number, vci);
30790 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30791 return 0;
30792 }
30793 DPRINTK("got rx crc error on vci %d\n", vci);
30794 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30795 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30796 lvcc->stats.x.aal5.service_rxcrc++;
30797 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
30798 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
30799 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
30800 index 1c70c45..300718d 100644
30801 --- a/drivers/atm/nicstar.c
30802 +++ b/drivers/atm/nicstar.c
30803 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30804 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
30805 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
30806 card->index);
30807 - atomic_inc(&vcc->stats->tx_err);
30808 + atomic_inc_unchecked(&vcc->stats->tx_err);
30809 dev_kfree_skb_any(skb);
30810 return -EINVAL;
30811 }
30812 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30813 if (!vc->tx) {
30814 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
30815 card->index);
30816 - atomic_inc(&vcc->stats->tx_err);
30817 + atomic_inc_unchecked(&vcc->stats->tx_err);
30818 dev_kfree_skb_any(skb);
30819 return -EINVAL;
30820 }
30821 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30822 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
30823 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
30824 card->index);
30825 - atomic_inc(&vcc->stats->tx_err);
30826 + atomic_inc_unchecked(&vcc->stats->tx_err);
30827 dev_kfree_skb_any(skb);
30828 return -EINVAL;
30829 }
30830
30831 if (skb_shinfo(skb)->nr_frags != 0) {
30832 printk("nicstar%d: No scatter-gather yet.\n", card->index);
30833 - atomic_inc(&vcc->stats->tx_err);
30834 + atomic_inc_unchecked(&vcc->stats->tx_err);
30835 dev_kfree_skb_any(skb);
30836 return -EINVAL;
30837 }
30838 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30839 }
30840
30841 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
30842 - atomic_inc(&vcc->stats->tx_err);
30843 + atomic_inc_unchecked(&vcc->stats->tx_err);
30844 dev_kfree_skb_any(skb);
30845 return -EIO;
30846 }
30847 - atomic_inc(&vcc->stats->tx);
30848 + atomic_inc_unchecked(&vcc->stats->tx);
30849
30850 return 0;
30851 }
30852 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30853 printk
30854 ("nicstar%d: Can't allocate buffers for aal0.\n",
30855 card->index);
30856 - atomic_add(i, &vcc->stats->rx_drop);
30857 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
30858 break;
30859 }
30860 if (!atm_charge(vcc, sb->truesize)) {
30861 RXPRINTK
30862 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
30863 card->index);
30864 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
30865 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
30866 dev_kfree_skb_any(sb);
30867 break;
30868 }
30869 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30870 ATM_SKB(sb)->vcc = vcc;
30871 __net_timestamp(sb);
30872 vcc->push(vcc, sb);
30873 - atomic_inc(&vcc->stats->rx);
30874 + atomic_inc_unchecked(&vcc->stats->rx);
30875 cell += ATM_CELL_PAYLOAD;
30876 }
30877
30878 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30879 if (iovb == NULL) {
30880 printk("nicstar%d: Out of iovec buffers.\n",
30881 card->index);
30882 - atomic_inc(&vcc->stats->rx_drop);
30883 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30884 recycle_rx_buf(card, skb);
30885 return;
30886 }
30887 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30888 small or large buffer itself. */
30889 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
30890 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
30891 - atomic_inc(&vcc->stats->rx_err);
30892 + atomic_inc_unchecked(&vcc->stats->rx_err);
30893 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
30894 NS_MAX_IOVECS);
30895 NS_PRV_IOVCNT(iovb) = 0;
30896 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30897 ("nicstar%d: Expected a small buffer, and this is not one.\n",
30898 card->index);
30899 which_list(card, skb);
30900 - atomic_inc(&vcc->stats->rx_err);
30901 + atomic_inc_unchecked(&vcc->stats->rx_err);
30902 recycle_rx_buf(card, skb);
30903 vc->rx_iov = NULL;
30904 recycle_iov_buf(card, iovb);
30905 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30906 ("nicstar%d: Expected a large buffer, and this is not one.\n",
30907 card->index);
30908 which_list(card, skb);
30909 - atomic_inc(&vcc->stats->rx_err);
30910 + atomic_inc_unchecked(&vcc->stats->rx_err);
30911 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
30912 NS_PRV_IOVCNT(iovb));
30913 vc->rx_iov = NULL;
30914 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30915 printk(" - PDU size mismatch.\n");
30916 else
30917 printk(".\n");
30918 - atomic_inc(&vcc->stats->rx_err);
30919 + atomic_inc_unchecked(&vcc->stats->rx_err);
30920 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
30921 NS_PRV_IOVCNT(iovb));
30922 vc->rx_iov = NULL;
30923 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30924 /* skb points to a small buffer */
30925 if (!atm_charge(vcc, skb->truesize)) {
30926 push_rxbufs(card, skb);
30927 - atomic_inc(&vcc->stats->rx_drop);
30928 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30929 } else {
30930 skb_put(skb, len);
30931 dequeue_sm_buf(card, skb);
30932 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30933 ATM_SKB(skb)->vcc = vcc;
30934 __net_timestamp(skb);
30935 vcc->push(vcc, skb);
30936 - atomic_inc(&vcc->stats->rx);
30937 + atomic_inc_unchecked(&vcc->stats->rx);
30938 }
30939 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
30940 struct sk_buff *sb;
30941 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30942 if (len <= NS_SMBUFSIZE) {
30943 if (!atm_charge(vcc, sb->truesize)) {
30944 push_rxbufs(card, sb);
30945 - atomic_inc(&vcc->stats->rx_drop);
30946 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30947 } else {
30948 skb_put(sb, len);
30949 dequeue_sm_buf(card, sb);
30950 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30951 ATM_SKB(sb)->vcc = vcc;
30952 __net_timestamp(sb);
30953 vcc->push(vcc, sb);
30954 - atomic_inc(&vcc->stats->rx);
30955 + atomic_inc_unchecked(&vcc->stats->rx);
30956 }
30957
30958 push_rxbufs(card, skb);
30959 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30960
30961 if (!atm_charge(vcc, skb->truesize)) {
30962 push_rxbufs(card, skb);
30963 - atomic_inc(&vcc->stats->rx_drop);
30964 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30965 } else {
30966 dequeue_lg_buf(card, skb);
30967 #ifdef NS_USE_DESTRUCTORS
30968 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30969 ATM_SKB(skb)->vcc = vcc;
30970 __net_timestamp(skb);
30971 vcc->push(vcc, skb);
30972 - atomic_inc(&vcc->stats->rx);
30973 + atomic_inc_unchecked(&vcc->stats->rx);
30974 }
30975
30976 push_rxbufs(card, sb);
30977 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30978 printk
30979 ("nicstar%d: Out of huge buffers.\n",
30980 card->index);
30981 - atomic_inc(&vcc->stats->rx_drop);
30982 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30983 recycle_iovec_rx_bufs(card,
30984 (struct iovec *)
30985 iovb->data,
30986 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30987 card->hbpool.count++;
30988 } else
30989 dev_kfree_skb_any(hb);
30990 - atomic_inc(&vcc->stats->rx_drop);
30991 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30992 } else {
30993 /* Copy the small buffer to the huge buffer */
30994 sb = (struct sk_buff *)iov->iov_base;
30995 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30996 #endif /* NS_USE_DESTRUCTORS */
30997 __net_timestamp(hb);
30998 vcc->push(vcc, hb);
30999 - atomic_inc(&vcc->stats->rx);
31000 + atomic_inc_unchecked(&vcc->stats->rx);
31001 }
31002 }
31003
31004 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
31005 index 1853a45..cf2426d 100644
31006 --- a/drivers/atm/solos-pci.c
31007 +++ b/drivers/atm/solos-pci.c
31008 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
31009 }
31010 atm_charge(vcc, skb->truesize);
31011 vcc->push(vcc, skb);
31012 - atomic_inc(&vcc->stats->rx);
31013 + atomic_inc_unchecked(&vcc->stats->rx);
31014 break;
31015
31016 case PKT_STATUS:
31017 @@ -1010,7 +1010,7 @@ static uint32_t fpga_tx(struct solos_card *card)
31018 vcc = SKB_CB(oldskb)->vcc;
31019
31020 if (vcc) {
31021 - atomic_inc(&vcc->stats->tx);
31022 + atomic_inc_unchecked(&vcc->stats->tx);
31023 solos_pop(vcc, oldskb);
31024 } else
31025 dev_kfree_skb_irq(oldskb);
31026 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
31027 index 0215934..ce9f5b1 100644
31028 --- a/drivers/atm/suni.c
31029 +++ b/drivers/atm/suni.c
31030 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
31031
31032
31033 #define ADD_LIMITED(s,v) \
31034 - atomic_add((v),&stats->s); \
31035 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
31036 + atomic_add_unchecked((v),&stats->s); \
31037 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
31038
31039
31040 static void suni_hz(unsigned long from_timer)
31041 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
31042 index 5120a96..e2572bd 100644
31043 --- a/drivers/atm/uPD98402.c
31044 +++ b/drivers/atm/uPD98402.c
31045 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
31046 struct sonet_stats tmp;
31047 int error = 0;
31048
31049 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
31050 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
31051 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
31052 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
31053 if (zero && !error) {
31054 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
31055
31056
31057 #define ADD_LIMITED(s,v) \
31058 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
31059 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
31060 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
31061 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
31062 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
31063 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
31064
31065
31066 static void stat_event(struct atm_dev *dev)
31067 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
31068 if (reason & uPD98402_INT_PFM) stat_event(dev);
31069 if (reason & uPD98402_INT_PCO) {
31070 (void) GET(PCOCR); /* clear interrupt cause */
31071 - atomic_add(GET(HECCT),
31072 + atomic_add_unchecked(GET(HECCT),
31073 &PRIV(dev)->sonet_stats.uncorr_hcs);
31074 }
31075 if ((reason & uPD98402_INT_RFO) &&
31076 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
31077 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
31078 uPD98402_INT_LOS),PIMR); /* enable them */
31079 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
31080 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
31081 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
31082 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
31083 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
31084 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
31085 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
31086 return 0;
31087 }
31088
31089 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
31090 index abe4e20..83c4727 100644
31091 --- a/drivers/atm/zatm.c
31092 +++ b/drivers/atm/zatm.c
31093 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
31094 }
31095 if (!size) {
31096 dev_kfree_skb_irq(skb);
31097 - if (vcc) atomic_inc(&vcc->stats->rx_err);
31098 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
31099 continue;
31100 }
31101 if (!atm_charge(vcc,skb->truesize)) {
31102 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
31103 skb->len = size;
31104 ATM_SKB(skb)->vcc = vcc;
31105 vcc->push(vcc,skb);
31106 - atomic_inc(&vcc->stats->rx);
31107 + atomic_inc_unchecked(&vcc->stats->rx);
31108 }
31109 zout(pos & 0xffff,MTA(mbx));
31110 #if 0 /* probably a stupid idea */
31111 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
31112 skb_queue_head(&zatm_vcc->backlog,skb);
31113 break;
31114 }
31115 - atomic_inc(&vcc->stats->tx);
31116 + atomic_inc_unchecked(&vcc->stats->tx);
31117 wake_up(&zatm_vcc->tx_wait);
31118 }
31119
31120 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
31121 index 147d1a4..d0fd4b0 100644
31122 --- a/drivers/base/devtmpfs.c
31123 +++ b/drivers/base/devtmpfs.c
31124 @@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
31125 if (!thread)
31126 return 0;
31127
31128 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
31129 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
31130 if (err)
31131 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
31132 else
31133 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
31134 index e6ee5e8..98ad7fc 100644
31135 --- a/drivers/base/power/wakeup.c
31136 +++ b/drivers/base/power/wakeup.c
31137 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
31138 * They need to be modified together atomically, so it's better to use one
31139 * atomic variable to hold them both.
31140 */
31141 -static atomic_t combined_event_count = ATOMIC_INIT(0);
31142 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
31143
31144 #define IN_PROGRESS_BITS (sizeof(int) * 4)
31145 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
31146
31147 static void split_counters(unsigned int *cnt, unsigned int *inpr)
31148 {
31149 - unsigned int comb = atomic_read(&combined_event_count);
31150 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
31151
31152 *cnt = (comb >> IN_PROGRESS_BITS);
31153 *inpr = comb & MAX_IN_PROGRESS;
31154 @@ -389,7 +389,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
31155 ws->start_prevent_time = ws->last_time;
31156
31157 /* Increment the counter of events in progress. */
31158 - cec = atomic_inc_return(&combined_event_count);
31159 + cec = atomic_inc_return_unchecked(&combined_event_count);
31160
31161 trace_wakeup_source_activate(ws->name, cec);
31162 }
31163 @@ -515,7 +515,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
31164 * Increment the counter of registered wakeup events and decrement the
31165 * couter of wakeup events in progress simultaneously.
31166 */
31167 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
31168 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
31169 trace_wakeup_source_deactivate(ws->name, cec);
31170
31171 split_counters(&cnt, &inpr);
31172 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
31173 index ca83f96..69d4ea9 100644
31174 --- a/drivers/block/cciss.c
31175 +++ b/drivers/block/cciss.c
31176 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
31177 int err;
31178 u32 cp;
31179
31180 + memset(&arg64, 0, sizeof(arg64));
31181 +
31182 err = 0;
31183 err |=
31184 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
31185 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
31186 while (!list_empty(&h->reqQ)) {
31187 c = list_entry(h->reqQ.next, CommandList_struct, list);
31188 /* can't do anything if fifo is full */
31189 - if ((h->access.fifo_full(h))) {
31190 + if ((h->access->fifo_full(h))) {
31191 dev_warn(&h->pdev->dev, "fifo full\n");
31192 break;
31193 }
31194 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
31195 h->Qdepth--;
31196
31197 /* Tell the controller execute command */
31198 - h->access.submit_command(h, c);
31199 + h->access->submit_command(h, c);
31200
31201 /* Put job onto the completed Q */
31202 addQ(&h->cmpQ, c);
31203 @@ -3443,17 +3445,17 @@ startio:
31204
31205 static inline unsigned long get_next_completion(ctlr_info_t *h)
31206 {
31207 - return h->access.command_completed(h);
31208 + return h->access->command_completed(h);
31209 }
31210
31211 static inline int interrupt_pending(ctlr_info_t *h)
31212 {
31213 - return h->access.intr_pending(h);
31214 + return h->access->intr_pending(h);
31215 }
31216
31217 static inline long interrupt_not_for_us(ctlr_info_t *h)
31218 {
31219 - return ((h->access.intr_pending(h) == 0) ||
31220 + return ((h->access->intr_pending(h) == 0) ||
31221 (h->interrupts_enabled == 0));
31222 }
31223
31224 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
31225 u32 a;
31226
31227 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
31228 - return h->access.command_completed(h);
31229 + return h->access->command_completed(h);
31230
31231 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
31232 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
31233 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
31234 trans_support & CFGTBL_Trans_use_short_tags);
31235
31236 /* Change the access methods to the performant access methods */
31237 - h->access = SA5_performant_access;
31238 + h->access = &SA5_performant_access;
31239 h->transMethod = CFGTBL_Trans_Performant;
31240
31241 return;
31242 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
31243 if (prod_index < 0)
31244 return -ENODEV;
31245 h->product_name = products[prod_index].product_name;
31246 - h->access = *(products[prod_index].access);
31247 + h->access = products[prod_index].access;
31248
31249 if (cciss_board_disabled(h)) {
31250 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
31251 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
31252 }
31253
31254 /* make sure the board interrupts are off */
31255 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
31256 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
31257 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
31258 if (rc)
31259 goto clean2;
31260 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
31261 * fake ones to scoop up any residual completions.
31262 */
31263 spin_lock_irqsave(&h->lock, flags);
31264 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
31265 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
31266 spin_unlock_irqrestore(&h->lock, flags);
31267 free_irq(h->intr[h->intr_mode], h);
31268 rc = cciss_request_irq(h, cciss_msix_discard_completions,
31269 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
31270 dev_info(&h->pdev->dev, "Board READY.\n");
31271 dev_info(&h->pdev->dev,
31272 "Waiting for stale completions to drain.\n");
31273 - h->access.set_intr_mask(h, CCISS_INTR_ON);
31274 + h->access->set_intr_mask(h, CCISS_INTR_ON);
31275 msleep(10000);
31276 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
31277 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
31278
31279 rc = controller_reset_failed(h->cfgtable);
31280 if (rc)
31281 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
31282 cciss_scsi_setup(h);
31283
31284 /* Turn the interrupts on so we can service requests */
31285 - h->access.set_intr_mask(h, CCISS_INTR_ON);
31286 + h->access->set_intr_mask(h, CCISS_INTR_ON);
31287
31288 /* Get the firmware version */
31289 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
31290 @@ -5210,7 +5212,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
31291 kfree(flush_buf);
31292 if (return_code != IO_OK)
31293 dev_warn(&h->pdev->dev, "Error flushing cache\n");
31294 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
31295 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
31296 free_irq(h->intr[h->intr_mode], h);
31297 }
31298
31299 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
31300 index 7fda30e..eb5dfe0 100644
31301 --- a/drivers/block/cciss.h
31302 +++ b/drivers/block/cciss.h
31303 @@ -101,7 +101,7 @@ struct ctlr_info
31304 /* information about each logical volume */
31305 drive_info_struct *drv[CISS_MAX_LUN];
31306
31307 - struct access_method access;
31308 + struct access_method *access;
31309
31310 /* queue and queue Info */
31311 struct list_head reqQ;
31312 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
31313 index 9125bbe..eede5c8 100644
31314 --- a/drivers/block/cpqarray.c
31315 +++ b/drivers/block/cpqarray.c
31316 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
31317 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
31318 goto Enomem4;
31319 }
31320 - hba[i]->access.set_intr_mask(hba[i], 0);
31321 + hba[i]->access->set_intr_mask(hba[i], 0);
31322 if (request_irq(hba[i]->intr, do_ida_intr,
31323 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
31324 {
31325 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
31326 add_timer(&hba[i]->timer);
31327
31328 /* Enable IRQ now that spinlock and rate limit timer are set up */
31329 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
31330 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
31331
31332 for(j=0; j<NWD; j++) {
31333 struct gendisk *disk = ida_gendisk[i][j];
31334 @@ -694,7 +694,7 @@ DBGINFO(
31335 for(i=0; i<NR_PRODUCTS; i++) {
31336 if (board_id == products[i].board_id) {
31337 c->product_name = products[i].product_name;
31338 - c->access = *(products[i].access);
31339 + c->access = products[i].access;
31340 break;
31341 }
31342 }
31343 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
31344 hba[ctlr]->intr = intr;
31345 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
31346 hba[ctlr]->product_name = products[j].product_name;
31347 - hba[ctlr]->access = *(products[j].access);
31348 + hba[ctlr]->access = products[j].access;
31349 hba[ctlr]->ctlr = ctlr;
31350 hba[ctlr]->board_id = board_id;
31351 hba[ctlr]->pci_dev = NULL; /* not PCI */
31352 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
31353
31354 while((c = h->reqQ) != NULL) {
31355 /* Can't do anything if we're busy */
31356 - if (h->access.fifo_full(h) == 0)
31357 + if (h->access->fifo_full(h) == 0)
31358 return;
31359
31360 /* Get the first entry from the request Q */
31361 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
31362 h->Qdepth--;
31363
31364 /* Tell the controller to do our bidding */
31365 - h->access.submit_command(h, c);
31366 + h->access->submit_command(h, c);
31367
31368 /* Get onto the completion Q */
31369 addQ(&h->cmpQ, c);
31370 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
31371 unsigned long flags;
31372 __u32 a,a1;
31373
31374 - istat = h->access.intr_pending(h);
31375 + istat = h->access->intr_pending(h);
31376 /* Is this interrupt for us? */
31377 if (istat == 0)
31378 return IRQ_NONE;
31379 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
31380 */
31381 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
31382 if (istat & FIFO_NOT_EMPTY) {
31383 - while((a = h->access.command_completed(h))) {
31384 + while((a = h->access->command_completed(h))) {
31385 a1 = a; a &= ~3;
31386 if ((c = h->cmpQ) == NULL)
31387 {
31388 @@ -1449,11 +1449,11 @@ static int sendcmd(
31389 /*
31390 * Disable interrupt
31391 */
31392 - info_p->access.set_intr_mask(info_p, 0);
31393 + info_p->access->set_intr_mask(info_p, 0);
31394 /* Make sure there is room in the command FIFO */
31395 /* Actually it should be completely empty at this time. */
31396 for (i = 200000; i > 0; i--) {
31397 - temp = info_p->access.fifo_full(info_p);
31398 + temp = info_p->access->fifo_full(info_p);
31399 if (temp != 0) {
31400 break;
31401 }
31402 @@ -1466,7 +1466,7 @@ DBG(
31403 /*
31404 * Send the cmd
31405 */
31406 - info_p->access.submit_command(info_p, c);
31407 + info_p->access->submit_command(info_p, c);
31408 complete = pollcomplete(ctlr);
31409
31410 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
31411 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
31412 * we check the new geometry. Then turn interrupts back on when
31413 * we're done.
31414 */
31415 - host->access.set_intr_mask(host, 0);
31416 + host->access->set_intr_mask(host, 0);
31417 getgeometry(ctlr);
31418 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
31419 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
31420
31421 for(i=0; i<NWD; i++) {
31422 struct gendisk *disk = ida_gendisk[ctlr][i];
31423 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
31424 /* Wait (up to 2 seconds) for a command to complete */
31425
31426 for (i = 200000; i > 0; i--) {
31427 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
31428 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
31429 if (done == 0) {
31430 udelay(10); /* a short fixed delay */
31431 } else
31432 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
31433 index be73e9d..7fbf140 100644
31434 --- a/drivers/block/cpqarray.h
31435 +++ b/drivers/block/cpqarray.h
31436 @@ -99,7 +99,7 @@ struct ctlr_info {
31437 drv_info_t drv[NWD];
31438 struct proc_dir_entry *proc;
31439
31440 - struct access_method access;
31441 + struct access_method *access;
31442
31443 cmdlist_t *reqQ;
31444 cmdlist_t *cmpQ;
31445 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
31446 index b953cc7..e3dc580 100644
31447 --- a/drivers/block/drbd/drbd_int.h
31448 +++ b/drivers/block/drbd/drbd_int.h
31449 @@ -735,7 +735,7 @@ struct drbd_request;
31450 struct drbd_epoch {
31451 struct list_head list;
31452 unsigned int barrier_nr;
31453 - atomic_t epoch_size; /* increased on every request added. */
31454 + atomic_unchecked_t epoch_size; /* increased on every request added. */
31455 atomic_t active; /* increased on every req. added, and dec on every finished. */
31456 unsigned long flags;
31457 };
31458 @@ -1116,7 +1116,7 @@ struct drbd_conf {
31459 void *int_dig_in;
31460 void *int_dig_vv;
31461 wait_queue_head_t seq_wait;
31462 - atomic_t packet_seq;
31463 + atomic_unchecked_t packet_seq;
31464 unsigned int peer_seq;
31465 spinlock_t peer_seq_lock;
31466 unsigned int minor;
31467 @@ -1658,30 +1658,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
31468
31469 static inline void drbd_tcp_cork(struct socket *sock)
31470 {
31471 - int __user val = 1;
31472 + int val = 1;
31473 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
31474 - (char __user *)&val, sizeof(val));
31475 + (char __force_user *)&val, sizeof(val));
31476 }
31477
31478 static inline void drbd_tcp_uncork(struct socket *sock)
31479 {
31480 - int __user val = 0;
31481 + int val = 0;
31482 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
31483 - (char __user *)&val, sizeof(val));
31484 + (char __force_user *)&val, sizeof(val));
31485 }
31486
31487 static inline void drbd_tcp_nodelay(struct socket *sock)
31488 {
31489 - int __user val = 1;
31490 + int val = 1;
31491 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
31492 - (char __user *)&val, sizeof(val));
31493 + (char __force_user *)&val, sizeof(val));
31494 }
31495
31496 static inline void drbd_tcp_quickack(struct socket *sock)
31497 {
31498 - int __user val = 2;
31499 + int val = 2;
31500 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
31501 - (char __user *)&val, sizeof(val));
31502 + (char __force_user *)&val, sizeof(val));
31503 }
31504
31505 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
31506 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
31507 index f55683a..2101b96 100644
31508 --- a/drivers/block/drbd/drbd_main.c
31509 +++ b/drivers/block/drbd/drbd_main.c
31510 @@ -2556,7 +2556,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
31511 p.sector = sector;
31512 p.block_id = block_id;
31513 p.blksize = blksize;
31514 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
31515 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
31516
31517 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
31518 return false;
31519 @@ -2854,7 +2854,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
31520
31521 p.sector = cpu_to_be64(req->sector);
31522 p.block_id = (unsigned long)req;
31523 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
31524 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
31525
31526 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
31527
31528 @@ -3139,7 +3139,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
31529 atomic_set(&mdev->unacked_cnt, 0);
31530 atomic_set(&mdev->local_cnt, 0);
31531 atomic_set(&mdev->net_cnt, 0);
31532 - atomic_set(&mdev->packet_seq, 0);
31533 + atomic_set_unchecked(&mdev->packet_seq, 0);
31534 atomic_set(&mdev->pp_in_use, 0);
31535 atomic_set(&mdev->pp_in_use_by_net, 0);
31536 atomic_set(&mdev->rs_sect_in, 0);
31537 @@ -3221,8 +3221,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
31538 mdev->receiver.t_state);
31539
31540 /* no need to lock it, I'm the only thread alive */
31541 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
31542 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
31543 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
31544 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
31545 mdev->al_writ_cnt =
31546 mdev->bm_writ_cnt =
31547 mdev->read_cnt =
31548 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
31549 index edb490a..ecd69da 100644
31550 --- a/drivers/block/drbd/drbd_nl.c
31551 +++ b/drivers/block/drbd/drbd_nl.c
31552 @@ -2407,7 +2407,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
31553 module_put(THIS_MODULE);
31554 }
31555
31556 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
31557 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
31558
31559 static unsigned short *
31560 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
31561 @@ -2478,7 +2478,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
31562 cn_reply->id.idx = CN_IDX_DRBD;
31563 cn_reply->id.val = CN_VAL_DRBD;
31564
31565 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
31566 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
31567 cn_reply->ack = 0; /* not used here. */
31568 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31569 (int)((char *)tl - (char *)reply->tag_list);
31570 @@ -2510,7 +2510,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
31571 cn_reply->id.idx = CN_IDX_DRBD;
31572 cn_reply->id.val = CN_VAL_DRBD;
31573
31574 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
31575 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
31576 cn_reply->ack = 0; /* not used here. */
31577 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31578 (int)((char *)tl - (char *)reply->tag_list);
31579 @@ -2588,7 +2588,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
31580 cn_reply->id.idx = CN_IDX_DRBD;
31581 cn_reply->id.val = CN_VAL_DRBD;
31582
31583 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
31584 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
31585 cn_reply->ack = 0; // not used here.
31586 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31587 (int)((char*)tl - (char*)reply->tag_list);
31588 @@ -2627,7 +2627,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
31589 cn_reply->id.idx = CN_IDX_DRBD;
31590 cn_reply->id.val = CN_VAL_DRBD;
31591
31592 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
31593 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
31594 cn_reply->ack = 0; /* not used here. */
31595 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31596 (int)((char *)tl - (char *)reply->tag_list);
31597 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
31598 index c74ca2d..860c819 100644
31599 --- a/drivers/block/drbd/drbd_receiver.c
31600 +++ b/drivers/block/drbd/drbd_receiver.c
31601 @@ -898,7 +898,7 @@ retry:
31602 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
31603 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
31604
31605 - atomic_set(&mdev->packet_seq, 0);
31606 + atomic_set_unchecked(&mdev->packet_seq, 0);
31607 mdev->peer_seq = 0;
31608
31609 if (drbd_send_protocol(mdev) == -1)
31610 @@ -999,7 +999,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
31611 do {
31612 next_epoch = NULL;
31613
31614 - epoch_size = atomic_read(&epoch->epoch_size);
31615 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
31616
31617 switch (ev & ~EV_CLEANUP) {
31618 case EV_PUT:
31619 @@ -1035,7 +1035,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
31620 rv = FE_DESTROYED;
31621 } else {
31622 epoch->flags = 0;
31623 - atomic_set(&epoch->epoch_size, 0);
31624 + atomic_set_unchecked(&epoch->epoch_size, 0);
31625 /* atomic_set(&epoch->active, 0); is already zero */
31626 if (rv == FE_STILL_LIVE)
31627 rv = FE_RECYCLED;
31628 @@ -1210,14 +1210,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
31629 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
31630 drbd_flush(mdev);
31631
31632 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
31633 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
31634 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
31635 if (epoch)
31636 break;
31637 }
31638
31639 epoch = mdev->current_epoch;
31640 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
31641 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
31642
31643 D_ASSERT(atomic_read(&epoch->active) == 0);
31644 D_ASSERT(epoch->flags == 0);
31645 @@ -1229,11 +1229,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
31646 }
31647
31648 epoch->flags = 0;
31649 - atomic_set(&epoch->epoch_size, 0);
31650 + atomic_set_unchecked(&epoch->epoch_size, 0);
31651 atomic_set(&epoch->active, 0);
31652
31653 spin_lock(&mdev->epoch_lock);
31654 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
31655 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
31656 list_add(&epoch->list, &mdev->current_epoch->list);
31657 mdev->current_epoch = epoch;
31658 mdev->epochs++;
31659 @@ -1702,7 +1702,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
31660 spin_unlock(&mdev->peer_seq_lock);
31661
31662 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
31663 - atomic_inc(&mdev->current_epoch->epoch_size);
31664 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
31665 return drbd_drain_block(mdev, data_size);
31666 }
31667
31668 @@ -1732,7 +1732,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
31669
31670 spin_lock(&mdev->epoch_lock);
31671 e->epoch = mdev->current_epoch;
31672 - atomic_inc(&e->epoch->epoch_size);
31673 + atomic_inc_unchecked(&e->epoch->epoch_size);
31674 atomic_inc(&e->epoch->active);
31675 spin_unlock(&mdev->epoch_lock);
31676
31677 @@ -3954,7 +3954,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
31678 D_ASSERT(list_empty(&mdev->done_ee));
31679
31680 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
31681 - atomic_set(&mdev->current_epoch->epoch_size, 0);
31682 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
31683 D_ASSERT(list_empty(&mdev->current_epoch->list));
31684 }
31685
31686 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
31687 index 54046e5..7759c55 100644
31688 --- a/drivers/block/loop.c
31689 +++ b/drivers/block/loop.c
31690 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
31691 mm_segment_t old_fs = get_fs();
31692
31693 set_fs(get_ds());
31694 - bw = file->f_op->write(file, buf, len, &pos);
31695 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
31696 set_fs(old_fs);
31697 if (likely(bw == len))
31698 return 0;
31699 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
31700 index d620b44..587561e 100644
31701 --- a/drivers/cdrom/cdrom.c
31702 +++ b/drivers/cdrom/cdrom.c
31703 @@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
31704 ENSURE(reset, CDC_RESET);
31705 ENSURE(generic_packet, CDC_GENERIC_PACKET);
31706 cdi->mc_flags = 0;
31707 - cdo->n_minors = 0;
31708 cdi->options = CDO_USE_FFLAGS;
31709
31710 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
31711 @@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
31712 else
31713 cdi->cdda_method = CDDA_OLD;
31714
31715 - if (!cdo->generic_packet)
31716 - cdo->generic_packet = cdrom_dummy_generic_packet;
31717 + if (!cdo->generic_packet) {
31718 + pax_open_kernel();
31719 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
31720 + pax_close_kernel();
31721 + }
31722
31723 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
31724 mutex_lock(&cdrom_mutex);
31725 @@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
31726 if (cdi->exit)
31727 cdi->exit(cdi);
31728
31729 - cdi->ops->n_minors--;
31730 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
31731 }
31732
31733 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
31734 index 75d485a..2809958 100644
31735 --- a/drivers/cdrom/gdrom.c
31736 +++ b/drivers/cdrom/gdrom.c
31737 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
31738 .audio_ioctl = gdrom_audio_ioctl,
31739 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
31740 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
31741 - .n_minors = 1,
31742 };
31743
31744 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
31745 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
31746 index 72bedad..8181ce1 100644
31747 --- a/drivers/char/Kconfig
31748 +++ b/drivers/char/Kconfig
31749 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
31750
31751 config DEVKMEM
31752 bool "/dev/kmem virtual device support"
31753 - default y
31754 + default n
31755 + depends on !GRKERNSEC_KMEM
31756 help
31757 Say Y here if you want to support the /dev/kmem device. The
31758 /dev/kmem device is rarely used, but can be used for certain
31759 @@ -581,6 +582,7 @@ config DEVPORT
31760 bool
31761 depends on !M68K
31762 depends on ISA || PCI
31763 + depends on !GRKERNSEC_KMEM
31764 default y
31765
31766 source "drivers/s390/char/Kconfig"
31767 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
31768 index 2e04433..22afc64 100644
31769 --- a/drivers/char/agp/frontend.c
31770 +++ b/drivers/char/agp/frontend.c
31771 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
31772 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
31773 return -EFAULT;
31774
31775 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
31776 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
31777 return -EFAULT;
31778
31779 client = agp_find_client_by_pid(reserve.pid);
31780 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
31781 index 21cb980..f15107c 100644
31782 --- a/drivers/char/genrtc.c
31783 +++ b/drivers/char/genrtc.c
31784 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
31785 switch (cmd) {
31786
31787 case RTC_PLL_GET:
31788 + memset(&pll, 0, sizeof(pll));
31789 if (get_rtc_pll(&pll))
31790 return -EINVAL;
31791 else
31792 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
31793 index dfd7876..c0b0885 100644
31794 --- a/drivers/char/hpet.c
31795 +++ b/drivers/char/hpet.c
31796 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
31797 }
31798
31799 static int
31800 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
31801 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
31802 struct hpet_info *info)
31803 {
31804 struct hpet_timer __iomem *timer;
31805 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
31806 index a0c84bb..9edcf60 100644
31807 --- a/drivers/char/ipmi/ipmi_msghandler.c
31808 +++ b/drivers/char/ipmi/ipmi_msghandler.c
31809 @@ -420,7 +420,7 @@ struct ipmi_smi {
31810 struct proc_dir_entry *proc_dir;
31811 char proc_dir_name[10];
31812
31813 - atomic_t stats[IPMI_NUM_STATS];
31814 + atomic_unchecked_t stats[IPMI_NUM_STATS];
31815
31816 /*
31817 * run_to_completion duplicate of smb_info, smi_info
31818 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
31819
31820
31821 #define ipmi_inc_stat(intf, stat) \
31822 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
31823 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
31824 #define ipmi_get_stat(intf, stat) \
31825 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
31826 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
31827
31828 static int is_lan_addr(struct ipmi_addr *addr)
31829 {
31830 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
31831 INIT_LIST_HEAD(&intf->cmd_rcvrs);
31832 init_waitqueue_head(&intf->waitq);
31833 for (i = 0; i < IPMI_NUM_STATS; i++)
31834 - atomic_set(&intf->stats[i], 0);
31835 + atomic_set_unchecked(&intf->stats[i], 0);
31836
31837 intf->proc_dir = NULL;
31838
31839 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
31840 index 32a6c7e..f6966a9 100644
31841 --- a/drivers/char/ipmi/ipmi_si_intf.c
31842 +++ b/drivers/char/ipmi/ipmi_si_intf.c
31843 @@ -275,7 +275,7 @@ struct smi_info {
31844 unsigned char slave_addr;
31845
31846 /* Counters and things for the proc filesystem. */
31847 - atomic_t stats[SI_NUM_STATS];
31848 + atomic_unchecked_t stats[SI_NUM_STATS];
31849
31850 struct task_struct *thread;
31851
31852 @@ -284,9 +284,9 @@ struct smi_info {
31853 };
31854
31855 #define smi_inc_stat(smi, stat) \
31856 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
31857 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
31858 #define smi_get_stat(smi, stat) \
31859 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
31860 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
31861
31862 #define SI_MAX_PARMS 4
31863
31864 @@ -3225,7 +3225,7 @@ static int try_smi_init(struct smi_info *new_smi)
31865 atomic_set(&new_smi->req_events, 0);
31866 new_smi->run_to_completion = 0;
31867 for (i = 0; i < SI_NUM_STATS; i++)
31868 - atomic_set(&new_smi->stats[i], 0);
31869 + atomic_set_unchecked(&new_smi->stats[i], 0);
31870
31871 new_smi->interrupt_disabled = 1;
31872 atomic_set(&new_smi->stop_operation, 0);
31873 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
31874 index 0537903..121c699 100644
31875 --- a/drivers/char/mem.c
31876 +++ b/drivers/char/mem.c
31877 @@ -18,6 +18,7 @@
31878 #include <linux/raw.h>
31879 #include <linux/tty.h>
31880 #include <linux/capability.h>
31881 +#include <linux/security.h>
31882 #include <linux/ptrace.h>
31883 #include <linux/device.h>
31884 #include <linux/highmem.h>
31885 @@ -37,6 +38,10 @@
31886
31887 #define DEVPORT_MINOR 4
31888
31889 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
31890 +extern const struct file_operations grsec_fops;
31891 +#endif
31892 +
31893 static inline unsigned long size_inside_page(unsigned long start,
31894 unsigned long size)
31895 {
31896 @@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31897
31898 while (cursor < to) {
31899 if (!devmem_is_allowed(pfn)) {
31900 +#ifdef CONFIG_GRKERNSEC_KMEM
31901 + gr_handle_mem_readwrite(from, to);
31902 +#else
31903 printk(KERN_INFO
31904 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
31905 current->comm, from, to);
31906 +#endif
31907 return 0;
31908 }
31909 cursor += PAGE_SIZE;
31910 @@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31911 }
31912 return 1;
31913 }
31914 +#elif defined(CONFIG_GRKERNSEC_KMEM)
31915 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31916 +{
31917 + return 0;
31918 +}
31919 #else
31920 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31921 {
31922 @@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
31923
31924 while (count > 0) {
31925 unsigned long remaining;
31926 + char *temp;
31927
31928 sz = size_inside_page(p, count);
31929
31930 @@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
31931 if (!ptr)
31932 return -EFAULT;
31933
31934 - remaining = copy_to_user(buf, ptr, sz);
31935 +#ifdef CONFIG_PAX_USERCOPY
31936 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
31937 + if (!temp) {
31938 + unxlate_dev_mem_ptr(p, ptr);
31939 + return -ENOMEM;
31940 + }
31941 + memcpy(temp, ptr, sz);
31942 +#else
31943 + temp = ptr;
31944 +#endif
31945 +
31946 + remaining = copy_to_user(buf, temp, sz);
31947 +
31948 +#ifdef CONFIG_PAX_USERCOPY
31949 + kfree(temp);
31950 +#endif
31951 +
31952 unxlate_dev_mem_ptr(p, ptr);
31953 if (remaining)
31954 return -EFAULT;
31955 @@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31956 size_t count, loff_t *ppos)
31957 {
31958 unsigned long p = *ppos;
31959 - ssize_t low_count, read, sz;
31960 + ssize_t low_count, read, sz, err = 0;
31961 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
31962 - int err = 0;
31963
31964 read = 0;
31965 if (p < (unsigned long) high_memory) {
31966 @@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31967 }
31968 #endif
31969 while (low_count > 0) {
31970 + char *temp;
31971 +
31972 sz = size_inside_page(p, low_count);
31973
31974 /*
31975 @@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31976 */
31977 kbuf = xlate_dev_kmem_ptr((char *)p);
31978
31979 - if (copy_to_user(buf, kbuf, sz))
31980 +#ifdef CONFIG_PAX_USERCOPY
31981 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
31982 + if (!temp)
31983 + return -ENOMEM;
31984 + memcpy(temp, kbuf, sz);
31985 +#else
31986 + temp = kbuf;
31987 +#endif
31988 +
31989 + err = copy_to_user(buf, temp, sz);
31990 +
31991 +#ifdef CONFIG_PAX_USERCOPY
31992 + kfree(temp);
31993 +#endif
31994 +
31995 + if (err)
31996 return -EFAULT;
31997 buf += sz;
31998 p += sz;
31999 @@ -833,6 +880,9 @@ static const struct memdev {
32000 #ifdef CONFIG_CRASH_DUMP
32001 [12] = { "oldmem", 0, &oldmem_fops, NULL },
32002 #endif
32003 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
32004 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
32005 +#endif
32006 };
32007
32008 static int memory_open(struct inode *inode, struct file *filp)
32009 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
32010 index 9df78e2..01ba9ae 100644
32011 --- a/drivers/char/nvram.c
32012 +++ b/drivers/char/nvram.c
32013 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
32014
32015 spin_unlock_irq(&rtc_lock);
32016
32017 - if (copy_to_user(buf, contents, tmp - contents))
32018 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
32019 return -EFAULT;
32020
32021 *ppos = i;
32022 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
32023 index 21721d2..4e98777 100644
32024 --- a/drivers/char/pcmcia/synclink_cs.c
32025 +++ b/drivers/char/pcmcia/synclink_cs.c
32026 @@ -2346,9 +2346,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
32027
32028 if (debug_level >= DEBUG_LEVEL_INFO)
32029 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
32030 - __FILE__,__LINE__, info->device_name, port->count);
32031 + __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
32032
32033 - WARN_ON(!port->count);
32034 + WARN_ON(!atomic_read(&port->count));
32035
32036 if (tty_port_close_start(port, tty, filp) == 0)
32037 goto cleanup;
32038 @@ -2366,7 +2366,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
32039 cleanup:
32040 if (debug_level >= DEBUG_LEVEL_INFO)
32041 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
32042 - tty->driver->name, port->count);
32043 + tty->driver->name, atomic_read(&port->count));
32044 }
32045
32046 /* Wait until the transmitter is empty.
32047 @@ -2508,7 +2508,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
32048
32049 if (debug_level >= DEBUG_LEVEL_INFO)
32050 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
32051 - __FILE__,__LINE__,tty->driver->name, port->count);
32052 + __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
32053
32054 /* If port is closing, signal caller to try again */
32055 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
32056 @@ -2528,11 +2528,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
32057 goto cleanup;
32058 }
32059 spin_lock(&port->lock);
32060 - port->count++;
32061 + atomic_inc(&port->count);
32062 spin_unlock(&port->lock);
32063 spin_unlock_irqrestore(&info->netlock, flags);
32064
32065 - if (port->count == 1) {
32066 + if (atomic_read(&port->count) == 1) {
32067 /* 1st open on this device, init hardware */
32068 retval = startup(info, tty);
32069 if (retval < 0)
32070 @@ -3886,7 +3886,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
32071 unsigned short new_crctype;
32072
32073 /* return error if TTY interface open */
32074 - if (info->port.count)
32075 + if (atomic_read(&info->port.count))
32076 return -EBUSY;
32077
32078 switch (encoding)
32079 @@ -3989,7 +3989,7 @@ static int hdlcdev_open(struct net_device *dev)
32080
32081 /* arbitrate between network and tty opens */
32082 spin_lock_irqsave(&info->netlock, flags);
32083 - if (info->port.count != 0 || info->netcount != 0) {
32084 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
32085 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
32086 spin_unlock_irqrestore(&info->netlock, flags);
32087 return -EBUSY;
32088 @@ -4078,7 +4078,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
32089 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
32090
32091 /* return error if TTY interface open */
32092 - if (info->port.count)
32093 + if (atomic_read(&info->port.count))
32094 return -EBUSY;
32095
32096 if (cmd != SIOCWANDEV)
32097 diff --git a/drivers/char/random.c b/drivers/char/random.c
32098 index b86eae9..b9c2ed7 100644
32099 --- a/drivers/char/random.c
32100 +++ b/drivers/char/random.c
32101 @@ -272,8 +272,13 @@
32102 /*
32103 * Configuration information
32104 */
32105 +#ifdef CONFIG_GRKERNSEC_RANDNET
32106 +#define INPUT_POOL_WORDS 512
32107 +#define OUTPUT_POOL_WORDS 128
32108 +#else
32109 #define INPUT_POOL_WORDS 128
32110 #define OUTPUT_POOL_WORDS 32
32111 +#endif
32112 #define SEC_XFER_SIZE 512
32113 #define EXTRACT_SIZE 10
32114
32115 @@ -313,10 +318,17 @@ static struct poolinfo {
32116 int poolwords;
32117 int tap1, tap2, tap3, tap4, tap5;
32118 } poolinfo_table[] = {
32119 +#ifdef CONFIG_GRKERNSEC_RANDNET
32120 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
32121 + { 512, 411, 308, 208, 104, 1 },
32122 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
32123 + { 128, 103, 76, 51, 25, 1 },
32124 +#else
32125 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
32126 { 128, 103, 76, 51, 25, 1 },
32127 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
32128 { 32, 26, 20, 14, 7, 1 },
32129 +#endif
32130 #if 0
32131 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
32132 { 2048, 1638, 1231, 819, 411, 1 },
32133 @@ -437,6 +449,7 @@ struct entropy_store {
32134 int entropy_count;
32135 int entropy_total;
32136 unsigned int initialized:1;
32137 + bool last_data_init;
32138 __u8 last_data[EXTRACT_SIZE];
32139 };
32140
32141 @@ -527,8 +540,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
32142 input_rotate += i ? 7 : 14;
32143 }
32144
32145 - ACCESS_ONCE(r->input_rotate) = input_rotate;
32146 - ACCESS_ONCE(r->add_ptr) = i;
32147 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
32148 + ACCESS_ONCE_RW(r->add_ptr) = i;
32149 smp_wmb();
32150
32151 if (out)
32152 @@ -957,6 +970,10 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf,
32153 ssize_t ret = 0, i;
32154 __u8 tmp[EXTRACT_SIZE];
32155
32156 + /* if last_data isn't primed, we need EXTRACT_SIZE extra bytes */
32157 + if (fips_enabled && !r->last_data_init)
32158 + nbytes += EXTRACT_SIZE;
32159 +
32160 trace_extract_entropy(r->name, nbytes, r->entropy_count, _RET_IP_);
32161 xfer_secondary_pool(r, nbytes);
32162 nbytes = account(r, nbytes, min, reserved);
32163 @@ -967,6 +984,17 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf,
32164 if (fips_enabled) {
32165 unsigned long flags;
32166
32167 +
32168 + /* prime last_data value if need be, per fips 140-2 */
32169 + if (!r->last_data_init) {
32170 + spin_lock_irqsave(&r->lock, flags);
32171 + memcpy(r->last_data, tmp, EXTRACT_SIZE);
32172 + r->last_data_init = true;
32173 + nbytes -= EXTRACT_SIZE;
32174 + spin_unlock_irqrestore(&r->lock, flags);
32175 + extract_buf(r, tmp);
32176 + }
32177 +
32178 spin_lock_irqsave(&r->lock, flags);
32179 if (!memcmp(tmp, r->last_data, EXTRACT_SIZE))
32180 panic("Hardware RNG duplicated output!\n");
32181 @@ -1008,7 +1036,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
32182
32183 extract_buf(r, tmp);
32184 i = min_t(int, nbytes, EXTRACT_SIZE);
32185 - if (copy_to_user(buf, tmp, i)) {
32186 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
32187 ret = -EFAULT;
32188 break;
32189 }
32190 @@ -1086,6 +1114,7 @@ static void init_std_data(struct entropy_store *r)
32191
32192 r->entropy_count = 0;
32193 r->entropy_total = 0;
32194 + r->last_data_init = false;
32195 mix_pool_bytes(r, &now, sizeof(now), NULL);
32196 for (i = r->poolinfo->POOLBYTES; i > 0; i -= sizeof(rv)) {
32197 if (!arch_get_random_long(&rv))
32198 @@ -1342,7 +1371,7 @@ EXPORT_SYMBOL(generate_random_uuid);
32199 #include <linux/sysctl.h>
32200
32201 static int min_read_thresh = 8, min_write_thresh;
32202 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
32203 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
32204 static int max_write_thresh = INPUT_POOL_WORDS * 32;
32205 static char sysctl_bootid[16];
32206
32207 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
32208 index 9b4f011..b7e0a1a 100644
32209 --- a/drivers/char/sonypi.c
32210 +++ b/drivers/char/sonypi.c
32211 @@ -54,6 +54,7 @@
32212
32213 #include <asm/uaccess.h>
32214 #include <asm/io.h>
32215 +#include <asm/local.h>
32216
32217 #include <linux/sonypi.h>
32218
32219 @@ -490,7 +491,7 @@ static struct sonypi_device {
32220 spinlock_t fifo_lock;
32221 wait_queue_head_t fifo_proc_list;
32222 struct fasync_struct *fifo_async;
32223 - int open_count;
32224 + local_t open_count;
32225 int model;
32226 struct input_dev *input_jog_dev;
32227 struct input_dev *input_key_dev;
32228 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
32229 static int sonypi_misc_release(struct inode *inode, struct file *file)
32230 {
32231 mutex_lock(&sonypi_device.lock);
32232 - sonypi_device.open_count--;
32233 + local_dec(&sonypi_device.open_count);
32234 mutex_unlock(&sonypi_device.lock);
32235 return 0;
32236 }
32237 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
32238 {
32239 mutex_lock(&sonypi_device.lock);
32240 /* Flush input queue on first open */
32241 - if (!sonypi_device.open_count)
32242 + if (!local_read(&sonypi_device.open_count))
32243 kfifo_reset(&sonypi_device.fifo);
32244 - sonypi_device.open_count++;
32245 + local_inc(&sonypi_device.open_count);
32246 mutex_unlock(&sonypi_device.lock);
32247
32248 return 0;
32249 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
32250 index 93211df..c7805f7 100644
32251 --- a/drivers/char/tpm/tpm.c
32252 +++ b/drivers/char/tpm/tpm.c
32253 @@ -410,7 +410,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
32254 chip->vendor.req_complete_val)
32255 goto out_recv;
32256
32257 - if ((status == chip->vendor.req_canceled)) {
32258 + if (status == chip->vendor.req_canceled) {
32259 dev_err(chip->dev, "Operation Canceled\n");
32260 rc = -ECANCELED;
32261 goto out;
32262 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
32263 index 56051d0..11cf3b7 100644
32264 --- a/drivers/char/tpm/tpm_acpi.c
32265 +++ b/drivers/char/tpm/tpm_acpi.c
32266 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
32267 virt = acpi_os_map_memory(start, len);
32268 if (!virt) {
32269 kfree(log->bios_event_log);
32270 + log->bios_event_log = NULL;
32271 printk("%s: ERROR - Unable to map memory\n", __func__);
32272 return -EIO;
32273 }
32274
32275 - memcpy_fromio(log->bios_event_log, virt, len);
32276 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
32277
32278 acpi_os_unmap_memory(virt, len);
32279 return 0;
32280 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
32281 index 84ddc55..1d32f1e 100644
32282 --- a/drivers/char/tpm/tpm_eventlog.c
32283 +++ b/drivers/char/tpm/tpm_eventlog.c
32284 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
32285 event = addr;
32286
32287 if ((event->event_type == 0 && event->event_size == 0) ||
32288 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
32289 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
32290 return NULL;
32291
32292 return addr;
32293 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
32294 return NULL;
32295
32296 if ((event->event_type == 0 && event->event_size == 0) ||
32297 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
32298 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
32299 return NULL;
32300
32301 (*pos)++;
32302 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
32303 int i;
32304
32305 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
32306 - seq_putc(m, data[i]);
32307 + if (!seq_putc(m, data[i]))
32308 + return -EFAULT;
32309
32310 return 0;
32311 }
32312 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
32313 index 8ab9c3d..c3e65d3 100644
32314 --- a/drivers/char/virtio_console.c
32315 +++ b/drivers/char/virtio_console.c
32316 @@ -622,7 +622,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
32317 if (to_user) {
32318 ssize_t ret;
32319
32320 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
32321 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
32322 if (ret)
32323 return -EFAULT;
32324 } else {
32325 @@ -721,7 +721,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
32326 if (!port_has_data(port) && !port->host_connected)
32327 return 0;
32328
32329 - return fill_readbuf(port, ubuf, count, true);
32330 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
32331 }
32332
32333 static int wait_port_writable(struct port *port, bool nonblock)
32334 diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c
32335 index 75c0a1a..96ba8f6 100644
32336 --- a/drivers/edac/edac_mc.c
32337 +++ b/drivers/edac/edac_mc.c
32338 @@ -340,7 +340,7 @@ struct mem_ctl_info *edac_mc_alloc(unsigned mc_num,
32339 /*
32340 * Alocate and fill the csrow/channels structs
32341 */
32342 - mci->csrows = kcalloc(sizeof(*mci->csrows), tot_csrows, GFP_KERNEL);
32343 + mci->csrows = kcalloc(tot_csrows, sizeof(*mci->csrows), GFP_KERNEL);
32344 if (!mci->csrows)
32345 goto error;
32346 for (row = 0; row < tot_csrows; row++) {
32347 @@ -351,7 +351,7 @@ struct mem_ctl_info *edac_mc_alloc(unsigned mc_num,
32348 csr->csrow_idx = row;
32349 csr->mci = mci;
32350 csr->nr_channels = tot_channels;
32351 - csr->channels = kcalloc(sizeof(*csr->channels), tot_channels,
32352 + csr->channels = kcalloc(tot_channels, sizeof(*csr->channels),
32353 GFP_KERNEL);
32354 if (!csr->channels)
32355 goto error;
32356 @@ -369,7 +369,7 @@ struct mem_ctl_info *edac_mc_alloc(unsigned mc_num,
32357 /*
32358 * Allocate and fill the dimm structs
32359 */
32360 - mci->dimms = kcalloc(sizeof(*mci->dimms), tot_dimms, GFP_KERNEL);
32361 + mci->dimms = kcalloc(tot_dimms, sizeof(*mci->dimms), GFP_KERNEL);
32362 if (!mci->dimms)
32363 goto error;
32364
32365 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
32366 index 1bfb207..0d059c2 100644
32367 --- a/drivers/edac/edac_pci_sysfs.c
32368 +++ b/drivers/edac/edac_pci_sysfs.c
32369 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
32370 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
32371 static int edac_pci_poll_msec = 1000; /* one second workq period */
32372
32373 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
32374 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
32375 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
32376 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
32377
32378 static struct kobject *edac_pci_top_main_kobj;
32379 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
32380 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32381 edac_printk(KERN_CRIT, EDAC_PCI,
32382 "Signaled System Error on %s\n",
32383 pci_name(dev));
32384 - atomic_inc(&pci_nonparity_count);
32385 + atomic_inc_unchecked(&pci_nonparity_count);
32386 }
32387
32388 if (status & (PCI_STATUS_PARITY)) {
32389 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32390 "Master Data Parity Error on %s\n",
32391 pci_name(dev));
32392
32393 - atomic_inc(&pci_parity_count);
32394 + atomic_inc_unchecked(&pci_parity_count);
32395 }
32396
32397 if (status & (PCI_STATUS_DETECTED_PARITY)) {
32398 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32399 "Detected Parity Error on %s\n",
32400 pci_name(dev));
32401
32402 - atomic_inc(&pci_parity_count);
32403 + atomic_inc_unchecked(&pci_parity_count);
32404 }
32405 }
32406
32407 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32408 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
32409 "Signaled System Error on %s\n",
32410 pci_name(dev));
32411 - atomic_inc(&pci_nonparity_count);
32412 + atomic_inc_unchecked(&pci_nonparity_count);
32413 }
32414
32415 if (status & (PCI_STATUS_PARITY)) {
32416 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32417 "Master Data Parity Error on "
32418 "%s\n", pci_name(dev));
32419
32420 - atomic_inc(&pci_parity_count);
32421 + atomic_inc_unchecked(&pci_parity_count);
32422 }
32423
32424 if (status & (PCI_STATUS_DETECTED_PARITY)) {
32425 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32426 "Detected Parity Error on %s\n",
32427 pci_name(dev));
32428
32429 - atomic_inc(&pci_parity_count);
32430 + atomic_inc_unchecked(&pci_parity_count);
32431 }
32432 }
32433 }
32434 @@ -676,7 +676,7 @@ void edac_pci_do_parity_check(void)
32435 if (!check_pci_errors)
32436 return;
32437
32438 - before_count = atomic_read(&pci_parity_count);
32439 + before_count = atomic_read_unchecked(&pci_parity_count);
32440
32441 /* scan all PCI devices looking for a Parity Error on devices and
32442 * bridges.
32443 @@ -688,7 +688,7 @@ void edac_pci_do_parity_check(void)
32444 /* Only if operator has selected panic on PCI Error */
32445 if (edac_pci_get_panic_on_pe()) {
32446 /* If the count is different 'after' from 'before' */
32447 - if (before_count != atomic_read(&pci_parity_count))
32448 + if (before_count != atomic_read_unchecked(&pci_parity_count))
32449 panic("EDAC: PCI Parity Error");
32450 }
32451 }
32452 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
32453 index 8c87a5e..a19cbd7 100644
32454 --- a/drivers/edac/mce_amd.h
32455 +++ b/drivers/edac/mce_amd.h
32456 @@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
32457 struct amd_decoder_ops {
32458 bool (*dc_mce)(u16, u8);
32459 bool (*ic_mce)(u16, u8);
32460 -};
32461 +} __no_const;
32462
32463 void amd_report_gart_errors(bool);
32464 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
32465 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
32466 index 57ea7f4..789e3c3 100644
32467 --- a/drivers/firewire/core-card.c
32468 +++ b/drivers/firewire/core-card.c
32469 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
32470
32471 void fw_core_remove_card(struct fw_card *card)
32472 {
32473 - struct fw_card_driver dummy_driver = dummy_driver_template;
32474 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
32475
32476 card->driver->update_phy_reg(card, 4,
32477 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
32478 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
32479 index f8d2287..5aaf4db 100644
32480 --- a/drivers/firewire/core-cdev.c
32481 +++ b/drivers/firewire/core-cdev.c
32482 @@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
32483 int ret;
32484
32485 if ((request->channels == 0 && request->bandwidth == 0) ||
32486 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
32487 - request->bandwidth < 0)
32488 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
32489 return -EINVAL;
32490
32491 r = kmalloc(sizeof(*r), GFP_KERNEL);
32492 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
32493 index 28a94c7..58da63a 100644
32494 --- a/drivers/firewire/core-transaction.c
32495 +++ b/drivers/firewire/core-transaction.c
32496 @@ -38,6 +38,7 @@
32497 #include <linux/timer.h>
32498 #include <linux/types.h>
32499 #include <linux/workqueue.h>
32500 +#include <linux/sched.h>
32501
32502 #include <asm/byteorder.h>
32503
32504 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
32505 index 515a42c..5ecf3ba 100644
32506 --- a/drivers/firewire/core.h
32507 +++ b/drivers/firewire/core.h
32508 @@ -111,6 +111,7 @@ struct fw_card_driver {
32509
32510 int (*stop_iso)(struct fw_iso_context *ctx);
32511 };
32512 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
32513
32514 void fw_card_initialize(struct fw_card *card,
32515 const struct fw_card_driver *driver, struct device *device);
32516 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
32517 index 982f1f5..d21e5da 100644
32518 --- a/drivers/firmware/dmi_scan.c
32519 +++ b/drivers/firmware/dmi_scan.c
32520 @@ -491,11 +491,6 @@ void __init dmi_scan_machine(void)
32521 }
32522 }
32523 else {
32524 - /*
32525 - * no iounmap() for that ioremap(); it would be a no-op, but
32526 - * it's so early in setup that sucker gets confused into doing
32527 - * what it shouldn't if we actually call it.
32528 - */
32529 p = dmi_ioremap(0xF0000, 0x10000);
32530 if (p == NULL)
32531 goto error;
32532 @@ -770,7 +765,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
32533 if (buf == NULL)
32534 return -1;
32535
32536 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
32537 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
32538
32539 iounmap(buf);
32540 return 0;
32541 diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
32542 index bfd8f43..133189c 100644
32543 --- a/drivers/firmware/efivars.c
32544 +++ b/drivers/firmware/efivars.c
32545 @@ -1234,9 +1234,9 @@ efivars_init(void)
32546 return -ENOMEM;
32547 }
32548
32549 - ops.get_variable = efi.get_variable;
32550 - ops.set_variable = efi.set_variable;
32551 - ops.get_next_variable = efi.get_next_variable;
32552 + *(void **)&ops.get_variable = efi.get_variable;
32553 + *(void **)&ops.set_variable = efi.set_variable;
32554 + *(void **)&ops.get_next_variable = efi.get_next_variable;
32555 error = register_efivars(&__efivars, &ops, efi_kobj);
32556 if (error)
32557 goto err_put;
32558 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
32559 index 82d5c20..44a7177 100644
32560 --- a/drivers/gpio/gpio-vr41xx.c
32561 +++ b/drivers/gpio/gpio-vr41xx.c
32562 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
32563 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
32564 maskl, pendl, maskh, pendh);
32565
32566 - atomic_inc(&irq_err_count);
32567 + atomic_inc_unchecked(&irq_err_count);
32568
32569 return -EINVAL;
32570 }
32571 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
32572 index 1227adf..f2301c2 100644
32573 --- a/drivers/gpu/drm/drm_crtc_helper.c
32574 +++ b/drivers/gpu/drm/drm_crtc_helper.c
32575 @@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
32576 struct drm_crtc *tmp;
32577 int crtc_mask = 1;
32578
32579 - WARN(!crtc, "checking null crtc?\n");
32580 + BUG_ON(!crtc);
32581
32582 dev = crtc->dev;
32583
32584 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
32585 index be174ca..0bcbb71 100644
32586 --- a/drivers/gpu/drm/drm_drv.c
32587 +++ b/drivers/gpu/drm/drm_drv.c
32588 @@ -307,7 +307,7 @@ module_exit(drm_core_exit);
32589 /**
32590 * Copy and IOCTL return string to user space
32591 */
32592 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
32593 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
32594 {
32595 int len;
32596
32597 @@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
32598 return -ENODEV;
32599
32600 atomic_inc(&dev->ioctl_count);
32601 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
32602 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
32603 ++file_priv->ioctl_count;
32604
32605 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
32606 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
32607 index 133b413..fd68225 100644
32608 --- a/drivers/gpu/drm/drm_fops.c
32609 +++ b/drivers/gpu/drm/drm_fops.c
32610 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
32611 }
32612
32613 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
32614 - atomic_set(&dev->counts[i], 0);
32615 + atomic_set_unchecked(&dev->counts[i], 0);
32616
32617 dev->sigdata.lock = NULL;
32618
32619 @@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
32620 if (drm_device_is_unplugged(dev))
32621 return -ENODEV;
32622
32623 - if (!dev->open_count++)
32624 + if (local_inc_return(&dev->open_count) == 1)
32625 need_setup = 1;
32626 mutex_lock(&dev->struct_mutex);
32627 old_mapping = dev->dev_mapping;
32628 @@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
32629 retcode = drm_open_helper(inode, filp, dev);
32630 if (retcode)
32631 goto err_undo;
32632 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
32633 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
32634 if (need_setup) {
32635 retcode = drm_setup(dev);
32636 if (retcode)
32637 @@ -164,7 +164,7 @@ err_undo:
32638 iput(container_of(dev->dev_mapping, struct inode, i_data));
32639 dev->dev_mapping = old_mapping;
32640 mutex_unlock(&dev->struct_mutex);
32641 - dev->open_count--;
32642 + local_dec(&dev->open_count);
32643 return retcode;
32644 }
32645 EXPORT_SYMBOL(drm_open);
32646 @@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
32647
32648 mutex_lock(&drm_global_mutex);
32649
32650 - DRM_DEBUG("open_count = %d\n", dev->open_count);
32651 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
32652
32653 if (dev->driver->preclose)
32654 dev->driver->preclose(dev, file_priv);
32655 @@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
32656 * Begin inline drm_release
32657 */
32658
32659 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
32660 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
32661 task_pid_nr(current),
32662 (long)old_encode_dev(file_priv->minor->device),
32663 - dev->open_count);
32664 + local_read(&dev->open_count));
32665
32666 /* Release any auth tokens that might point to this file_priv,
32667 (do that under the drm_global_mutex) */
32668 @@ -547,8 +547,8 @@ int drm_release(struct inode *inode, struct file *filp)
32669 * End inline drm_release
32670 */
32671
32672 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
32673 - if (!--dev->open_count) {
32674 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
32675 + if (local_dec_and_test(&dev->open_count)) {
32676 if (atomic_read(&dev->ioctl_count)) {
32677 DRM_ERROR("Device busy: %d\n",
32678 atomic_read(&dev->ioctl_count));
32679 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
32680 index f731116..629842c 100644
32681 --- a/drivers/gpu/drm/drm_global.c
32682 +++ b/drivers/gpu/drm/drm_global.c
32683 @@ -36,7 +36,7 @@
32684 struct drm_global_item {
32685 struct mutex mutex;
32686 void *object;
32687 - int refcount;
32688 + atomic_t refcount;
32689 };
32690
32691 static struct drm_global_item glob[DRM_GLOBAL_NUM];
32692 @@ -49,7 +49,7 @@ void drm_global_init(void)
32693 struct drm_global_item *item = &glob[i];
32694 mutex_init(&item->mutex);
32695 item->object = NULL;
32696 - item->refcount = 0;
32697 + atomic_set(&item->refcount, 0);
32698 }
32699 }
32700
32701 @@ -59,7 +59,7 @@ void drm_global_release(void)
32702 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
32703 struct drm_global_item *item = &glob[i];
32704 BUG_ON(item->object != NULL);
32705 - BUG_ON(item->refcount != 0);
32706 + BUG_ON(atomic_read(&item->refcount) != 0);
32707 }
32708 }
32709
32710 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
32711 void *object;
32712
32713 mutex_lock(&item->mutex);
32714 - if (item->refcount == 0) {
32715 + if (atomic_read(&item->refcount) == 0) {
32716 item->object = kzalloc(ref->size, GFP_KERNEL);
32717 if (unlikely(item->object == NULL)) {
32718 ret = -ENOMEM;
32719 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
32720 goto out_err;
32721
32722 }
32723 - ++item->refcount;
32724 + atomic_inc(&item->refcount);
32725 ref->object = item->object;
32726 object = item->object;
32727 mutex_unlock(&item->mutex);
32728 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
32729 struct drm_global_item *item = &glob[ref->global_type];
32730
32731 mutex_lock(&item->mutex);
32732 - BUG_ON(item->refcount == 0);
32733 + BUG_ON(atomic_read(&item->refcount) == 0);
32734 BUG_ON(ref->object != item->object);
32735 - if (--item->refcount == 0) {
32736 + if (atomic_dec_and_test(&item->refcount)) {
32737 ref->release(ref);
32738 item->object = NULL;
32739 }
32740 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
32741 index d4b20ce..77a8d41 100644
32742 --- a/drivers/gpu/drm/drm_info.c
32743 +++ b/drivers/gpu/drm/drm_info.c
32744 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
32745 struct drm_local_map *map;
32746 struct drm_map_list *r_list;
32747
32748 - /* Hardcoded from _DRM_FRAME_BUFFER,
32749 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
32750 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
32751 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
32752 + static const char * const types[] = {
32753 + [_DRM_FRAME_BUFFER] = "FB",
32754 + [_DRM_REGISTERS] = "REG",
32755 + [_DRM_SHM] = "SHM",
32756 + [_DRM_AGP] = "AGP",
32757 + [_DRM_SCATTER_GATHER] = "SG",
32758 + [_DRM_CONSISTENT] = "PCI",
32759 + [_DRM_GEM] = "GEM" };
32760 const char *type;
32761 int i;
32762
32763 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
32764 map = r_list->map;
32765 if (!map)
32766 continue;
32767 - if (map->type < 0 || map->type > 5)
32768 + if (map->type >= ARRAY_SIZE(types))
32769 type = "??";
32770 else
32771 type = types[map->type];
32772 @@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
32773 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
32774 vma->vm_flags & VM_LOCKED ? 'l' : '-',
32775 vma->vm_flags & VM_IO ? 'i' : '-',
32776 +#ifdef CONFIG_GRKERNSEC_HIDESYM
32777 + 0);
32778 +#else
32779 vma->vm_pgoff);
32780 +#endif
32781
32782 #if defined(__i386__)
32783 pgprot = pgprot_val(vma->vm_page_prot);
32784 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
32785 index 2f4c434..764794b 100644
32786 --- a/drivers/gpu/drm/drm_ioc32.c
32787 +++ b/drivers/gpu/drm/drm_ioc32.c
32788 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
32789 request = compat_alloc_user_space(nbytes);
32790 if (!access_ok(VERIFY_WRITE, request, nbytes))
32791 return -EFAULT;
32792 - list = (struct drm_buf_desc *) (request + 1);
32793 + list = (struct drm_buf_desc __user *) (request + 1);
32794
32795 if (__put_user(count, &request->count)
32796 || __put_user(list, &request->list))
32797 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
32798 request = compat_alloc_user_space(nbytes);
32799 if (!access_ok(VERIFY_WRITE, request, nbytes))
32800 return -EFAULT;
32801 - list = (struct drm_buf_pub *) (request + 1);
32802 + list = (struct drm_buf_pub __user *) (request + 1);
32803
32804 if (__put_user(count, &request->count)
32805 || __put_user(list, &request->list))
32806 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
32807 index 23dd975..63e9801 100644
32808 --- a/drivers/gpu/drm/drm_ioctl.c
32809 +++ b/drivers/gpu/drm/drm_ioctl.c
32810 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
32811 stats->data[i].value =
32812 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
32813 else
32814 - stats->data[i].value = atomic_read(&dev->counts[i]);
32815 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
32816 stats->data[i].type = dev->types[i];
32817 }
32818
32819 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
32820 index d752c96..fe08455 100644
32821 --- a/drivers/gpu/drm/drm_lock.c
32822 +++ b/drivers/gpu/drm/drm_lock.c
32823 @@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
32824 if (drm_lock_take(&master->lock, lock->context)) {
32825 master->lock.file_priv = file_priv;
32826 master->lock.lock_time = jiffies;
32827 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
32828 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
32829 break; /* Got lock */
32830 }
32831
32832 @@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
32833 return -EINVAL;
32834 }
32835
32836 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
32837 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
32838
32839 if (drm_lock_free(&master->lock, lock->context)) {
32840 /* FIXME: Should really bail out here. */
32841 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
32842 index c236fd2..6b5f2e7 100644
32843 --- a/drivers/gpu/drm/drm_stub.c
32844 +++ b/drivers/gpu/drm/drm_stub.c
32845 @@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
32846
32847 drm_device_set_unplugged(dev);
32848
32849 - if (dev->open_count == 0) {
32850 + if (local_read(&dev->open_count) == 0) {
32851 drm_put_dev(dev);
32852 }
32853 mutex_unlock(&drm_global_mutex);
32854 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
32855 index 004ecdf..db1f6e0 100644
32856 --- a/drivers/gpu/drm/i810/i810_dma.c
32857 +++ b/drivers/gpu/drm/i810/i810_dma.c
32858 @@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
32859 dma->buflist[vertex->idx],
32860 vertex->discard, vertex->used);
32861
32862 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
32863 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
32864 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
32865 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
32866 sarea_priv->last_enqueue = dev_priv->counter - 1;
32867 sarea_priv->last_dispatch = (int)hw_status[5];
32868
32869 @@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
32870 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
32871 mc->last_render);
32872
32873 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
32874 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
32875 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
32876 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
32877 sarea_priv->last_enqueue = dev_priv->counter - 1;
32878 sarea_priv->last_dispatch = (int)hw_status[5];
32879
32880 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
32881 index 6e0acad..93c8289 100644
32882 --- a/drivers/gpu/drm/i810/i810_drv.h
32883 +++ b/drivers/gpu/drm/i810/i810_drv.h
32884 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
32885 int page_flipping;
32886
32887 wait_queue_head_t irq_queue;
32888 - atomic_t irq_received;
32889 - atomic_t irq_emitted;
32890 + atomic_unchecked_t irq_received;
32891 + atomic_unchecked_t irq_emitted;
32892
32893 int front_offset;
32894 } drm_i810_private_t;
32895 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
32896 index 3a1a495..995c093 100644
32897 --- a/drivers/gpu/drm/i915/i915_debugfs.c
32898 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
32899 @@ -496,7 +496,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
32900 I915_READ(GTIMR));
32901 }
32902 seq_printf(m, "Interrupts received: %d\n",
32903 - atomic_read(&dev_priv->irq_received));
32904 + atomic_read_unchecked(&dev_priv->irq_received));
32905 for_each_ring(ring, dev_priv, i) {
32906 if (IS_GEN6(dev) || IS_GEN7(dev)) {
32907 seq_printf(m,
32908 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
32909 index 61ae104..f8a4bc1 100644
32910 --- a/drivers/gpu/drm/i915/i915_dma.c
32911 +++ b/drivers/gpu/drm/i915/i915_dma.c
32912 @@ -1274,7 +1274,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
32913 bool can_switch;
32914
32915 spin_lock(&dev->count_lock);
32916 - can_switch = (dev->open_count == 0);
32917 + can_switch = (local_read(&dev->open_count) == 0);
32918 spin_unlock(&dev->count_lock);
32919 return can_switch;
32920 }
32921 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
32922 index 92f1750..3beba74 100644
32923 --- a/drivers/gpu/drm/i915/i915_drv.h
32924 +++ b/drivers/gpu/drm/i915/i915_drv.h
32925 @@ -430,7 +430,7 @@ typedef struct drm_i915_private {
32926
32927 struct resource mch_res;
32928
32929 - atomic_t irq_received;
32930 + atomic_unchecked_t irq_received;
32931
32932 /* protects the irq masks */
32933 spinlock_t irq_lock;
32934 @@ -1055,7 +1055,7 @@ struct drm_i915_gem_object {
32935 * will be page flipped away on the next vblank. When it
32936 * reaches 0, dev_priv->pending_flip_queue will be woken up.
32937 */
32938 - atomic_t pending_flip;
32939 + atomic_unchecked_t pending_flip;
32940 };
32941
32942 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
32943 @@ -1558,7 +1558,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
32944 struct drm_i915_private *dev_priv, unsigned port);
32945 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
32946 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
32947 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
32948 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
32949 {
32950 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
32951 }
32952 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
32953 index 67036e9..b9f1357 100644
32954 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
32955 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
32956 @@ -681,7 +681,7 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
32957 i915_gem_clflush_object(obj);
32958
32959 if (obj->base.pending_write_domain)
32960 - flips |= atomic_read(&obj->pending_flip);
32961 + flips |= atomic_read_unchecked(&obj->pending_flip);
32962
32963 flush_domains |= obj->base.write_domain;
32964 }
32965 @@ -712,9 +712,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
32966
32967 static int
32968 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
32969 - int count)
32970 + unsigned int count)
32971 {
32972 - int i;
32973 + unsigned int i;
32974
32975 for (i = 0; i < count; i++) {
32976 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
32977 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
32978 index dc29ace..137d83a 100644
32979 --- a/drivers/gpu/drm/i915/i915_irq.c
32980 +++ b/drivers/gpu/drm/i915/i915_irq.c
32981 @@ -531,7 +531,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
32982 u32 pipe_stats[I915_MAX_PIPES];
32983 bool blc_event;
32984
32985 - atomic_inc(&dev_priv->irq_received);
32986 + atomic_inc_unchecked(&dev_priv->irq_received);
32987
32988 while (true) {
32989 iir = I915_READ(VLV_IIR);
32990 @@ -678,7 +678,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
32991 irqreturn_t ret = IRQ_NONE;
32992 int i;
32993
32994 - atomic_inc(&dev_priv->irq_received);
32995 + atomic_inc_unchecked(&dev_priv->irq_received);
32996
32997 /* disable master interrupt before clearing iir */
32998 de_ier = I915_READ(DEIER);
32999 @@ -753,7 +753,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
33000 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
33001 u32 hotplug_mask;
33002
33003 - atomic_inc(&dev_priv->irq_received);
33004 + atomic_inc_unchecked(&dev_priv->irq_received);
33005
33006 /* disable master interrupt before clearing iir */
33007 de_ier = I915_READ(DEIER);
33008 @@ -1762,7 +1762,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
33009 {
33010 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33011
33012 - atomic_set(&dev_priv->irq_received, 0);
33013 + atomic_set_unchecked(&dev_priv->irq_received, 0);
33014
33015 I915_WRITE(HWSTAM, 0xeffe);
33016
33017 @@ -1788,7 +1788,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
33018 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33019 int pipe;
33020
33021 - atomic_set(&dev_priv->irq_received, 0);
33022 + atomic_set_unchecked(&dev_priv->irq_received, 0);
33023
33024 /* VLV magic */
33025 I915_WRITE(VLV_IMR, 0);
33026 @@ -2093,7 +2093,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
33027 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33028 int pipe;
33029
33030 - atomic_set(&dev_priv->irq_received, 0);
33031 + atomic_set_unchecked(&dev_priv->irq_received, 0);
33032
33033 for_each_pipe(pipe)
33034 I915_WRITE(PIPESTAT(pipe), 0);
33035 @@ -2144,7 +2144,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
33036 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
33037 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
33038
33039 - atomic_inc(&dev_priv->irq_received);
33040 + atomic_inc_unchecked(&dev_priv->irq_received);
33041
33042 iir = I915_READ16(IIR);
33043 if (iir == 0)
33044 @@ -2229,7 +2229,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
33045 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33046 int pipe;
33047
33048 - atomic_set(&dev_priv->irq_received, 0);
33049 + atomic_set_unchecked(&dev_priv->irq_received, 0);
33050
33051 if (I915_HAS_HOTPLUG(dev)) {
33052 I915_WRITE(PORT_HOTPLUG_EN, 0);
33053 @@ -2324,7 +2324,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
33054 };
33055 int pipe, ret = IRQ_NONE;
33056
33057 - atomic_inc(&dev_priv->irq_received);
33058 + atomic_inc_unchecked(&dev_priv->irq_received);
33059
33060 iir = I915_READ(IIR);
33061 do {
33062 @@ -2450,7 +2450,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
33063 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33064 int pipe;
33065
33066 - atomic_set(&dev_priv->irq_received, 0);
33067 + atomic_set_unchecked(&dev_priv->irq_received, 0);
33068
33069 I915_WRITE(PORT_HOTPLUG_EN, 0);
33070 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
33071 @@ -2557,7 +2557,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
33072 int irq_received;
33073 int ret = IRQ_NONE, pipe;
33074
33075 - atomic_inc(&dev_priv->irq_received);
33076 + atomic_inc_unchecked(&dev_priv->irq_received);
33077
33078 iir = I915_READ(IIR);
33079
33080 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
33081 index 4d3c7c6..eaac87b 100644
33082 --- a/drivers/gpu/drm/i915/intel_display.c
33083 +++ b/drivers/gpu/drm/i915/intel_display.c
33084 @@ -2131,7 +2131,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
33085
33086 wait_event(dev_priv->pending_flip_queue,
33087 atomic_read(&dev_priv->mm.wedged) ||
33088 - atomic_read(&obj->pending_flip) == 0);
33089 + atomic_read_unchecked(&obj->pending_flip) == 0);
33090
33091 /* Big Hammer, we also need to ensure that any pending
33092 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
33093 @@ -6221,8 +6221,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
33094
33095 obj = work->old_fb_obj;
33096
33097 - atomic_clear_mask(1 << intel_crtc->plane,
33098 - &obj->pending_flip.counter);
33099 + atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
33100 wake_up(&dev_priv->pending_flip_queue);
33101
33102 queue_work(dev_priv->wq, &work->work);
33103 @@ -6589,7 +6588,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
33104 /* Block clients from rendering to the new back buffer until
33105 * the flip occurs and the object is no longer visible.
33106 */
33107 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33108 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33109 atomic_inc(&intel_crtc->unpin_work_count);
33110
33111 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
33112 @@ -6606,7 +6605,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
33113
33114 cleanup_pending:
33115 atomic_dec(&intel_crtc->unpin_work_count);
33116 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33117 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33118 drm_gem_object_unreference(&work->old_fb_obj->base);
33119 drm_gem_object_unreference(&obj->base);
33120 mutex_unlock(&dev->struct_mutex);
33121 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
33122 index 54558a0..2d97005 100644
33123 --- a/drivers/gpu/drm/mga/mga_drv.h
33124 +++ b/drivers/gpu/drm/mga/mga_drv.h
33125 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
33126 u32 clear_cmd;
33127 u32 maccess;
33128
33129 - atomic_t vbl_received; /**< Number of vblanks received. */
33130 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
33131 wait_queue_head_t fence_queue;
33132 - atomic_t last_fence_retired;
33133 + atomic_unchecked_t last_fence_retired;
33134 u32 next_fence_to_post;
33135
33136 unsigned int fb_cpp;
33137 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
33138 index 598c281..60d590e 100644
33139 --- a/drivers/gpu/drm/mga/mga_irq.c
33140 +++ b/drivers/gpu/drm/mga/mga_irq.c
33141 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
33142 if (crtc != 0)
33143 return 0;
33144
33145 - return atomic_read(&dev_priv->vbl_received);
33146 + return atomic_read_unchecked(&dev_priv->vbl_received);
33147 }
33148
33149
33150 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
33151 /* VBLANK interrupt */
33152 if (status & MGA_VLINEPEN) {
33153 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
33154 - atomic_inc(&dev_priv->vbl_received);
33155 + atomic_inc_unchecked(&dev_priv->vbl_received);
33156 drm_handle_vblank(dev, 0);
33157 handled = 1;
33158 }
33159 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
33160 if ((prim_start & ~0x03) != (prim_end & ~0x03))
33161 MGA_WRITE(MGA_PRIMEND, prim_end);
33162
33163 - atomic_inc(&dev_priv->last_fence_retired);
33164 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
33165 DRM_WAKEUP(&dev_priv->fence_queue);
33166 handled = 1;
33167 }
33168 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
33169 * using fences.
33170 */
33171 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
33172 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
33173 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
33174 - *sequence) <= (1 << 23)));
33175
33176 *sequence = cur_fence;
33177 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
33178 index 09fdef2..57f5c3b 100644
33179 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
33180 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
33181 @@ -1240,7 +1240,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
33182 struct bit_table {
33183 const char id;
33184 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
33185 -};
33186 +} __no_const;
33187
33188 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
33189
33190 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
33191 index a101699..a163f0a 100644
33192 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
33193 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
33194 @@ -80,7 +80,7 @@ struct nouveau_drm {
33195 struct drm_global_reference mem_global_ref;
33196 struct ttm_bo_global_ref bo_global_ref;
33197 struct ttm_bo_device bdev;
33198 - atomic_t validate_sequence;
33199 + atomic_unchecked_t validate_sequence;
33200 int (*move)(struct nouveau_channel *,
33201 struct ttm_buffer_object *,
33202 struct ttm_mem_reg *, struct ttm_mem_reg *);
33203 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
33204 index cdb83ac..27f0a16 100644
33205 --- a/drivers/gpu/drm/nouveau/nouveau_fence.h
33206 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
33207 @@ -43,7 +43,7 @@ struct nouveau_fence_priv {
33208 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
33209 struct nouveau_channel *);
33210 u32 (*read)(struct nouveau_channel *);
33211 -};
33212 +} __no_const;
33213
33214 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
33215
33216 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
33217 index 5e2f521..0d21436 100644
33218 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
33219 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
33220 @@ -321,7 +321,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
33221 int trycnt = 0;
33222 int ret, i;
33223
33224 - sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
33225 + sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
33226 retry:
33227 if (++trycnt > 100000) {
33228 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
33229 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
33230 index 6f0ac64..9c2dfb4 100644
33231 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
33232 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
33233 @@ -63,7 +63,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
33234 bool can_switch;
33235
33236 spin_lock(&dev->count_lock);
33237 - can_switch = (dev->open_count == 0);
33238 + can_switch = (local_read(&dev->open_count) == 0);
33239 spin_unlock(&dev->count_lock);
33240 return can_switch;
33241 }
33242 diff --git a/drivers/gpu/drm/nouveau/nv50_evo.c b/drivers/gpu/drm/nouveau/nv50_evo.c
33243 index 9f6f55c..30e3a29 100644
33244 --- a/drivers/gpu/drm/nouveau/nv50_evo.c
33245 +++ b/drivers/gpu/drm/nouveau/nv50_evo.c
33246 @@ -152,9 +152,9 @@ nv50_evo_channel_new(struct drm_device *dev, int chid,
33247 kzalloc(sizeof(*evo->object->oclass), GFP_KERNEL);
33248 evo->object->oclass->ofuncs =
33249 kzalloc(sizeof(*evo->object->oclass->ofuncs), GFP_KERNEL);
33250 - evo->object->oclass->ofuncs->rd32 = nv50_evo_rd32;
33251 - evo->object->oclass->ofuncs->wr32 = nv50_evo_wr32;
33252 - evo->object->oclass->ofuncs->rd08 =
33253 + *(void**)&evo->object->oclass->ofuncs->rd32 = nv50_evo_rd32;
33254 + *(void**)&evo->object->oclass->ofuncs->wr32 = nv50_evo_wr32;
33255 + *(void**)&evo->object->oclass->ofuncs->rd08 =
33256 ioremap(pci_resource_start(dev->pdev, 0) +
33257 NV50_PDISPLAY_USER(evo->handle), PAGE_SIZE);
33258 return 0;
33259 diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
33260 index b562b59..9d725a8 100644
33261 --- a/drivers/gpu/drm/nouveau/nv50_sor.c
33262 +++ b/drivers/gpu/drm/nouveau/nv50_sor.c
33263 @@ -317,7 +317,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
33264 }
33265
33266 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
33267 - struct dp_train_func func = {
33268 + static struct dp_train_func func = {
33269 .link_set = nv50_sor_dp_link_set,
33270 .train_set = nv50_sor_dp_train_set,
33271 .train_adj = nv50_sor_dp_train_adj
33272 diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
33273 index c402fca..f1d694b 100644
33274 --- a/drivers/gpu/drm/nouveau/nvd0_display.c
33275 +++ b/drivers/gpu/drm/nouveau/nvd0_display.c
33276 @@ -1389,7 +1389,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
33277 nv_wait(device, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
33278
33279 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
33280 - struct dp_train_func func = {
33281 + static struct dp_train_func func = {
33282 .link_set = nvd0_sor_dp_link_set,
33283 .train_set = nvd0_sor_dp_train_set,
33284 .train_adj = nvd0_sor_dp_train_adj
33285 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
33286 index d4660cf..70dbe65 100644
33287 --- a/drivers/gpu/drm/r128/r128_cce.c
33288 +++ b/drivers/gpu/drm/r128/r128_cce.c
33289 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
33290
33291 /* GH: Simple idle check.
33292 */
33293 - atomic_set(&dev_priv->idle_count, 0);
33294 + atomic_set_unchecked(&dev_priv->idle_count, 0);
33295
33296 /* We don't support anything other than bus-mastering ring mode,
33297 * but the ring can be in either AGP or PCI space for the ring
33298 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
33299 index 930c71b..499aded 100644
33300 --- a/drivers/gpu/drm/r128/r128_drv.h
33301 +++ b/drivers/gpu/drm/r128/r128_drv.h
33302 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
33303 int is_pci;
33304 unsigned long cce_buffers_offset;
33305
33306 - atomic_t idle_count;
33307 + atomic_unchecked_t idle_count;
33308
33309 int page_flipping;
33310 int current_page;
33311 u32 crtc_offset;
33312 u32 crtc_offset_cntl;
33313
33314 - atomic_t vbl_received;
33315 + atomic_unchecked_t vbl_received;
33316
33317 u32 color_fmt;
33318 unsigned int front_offset;
33319 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
33320 index 2ea4f09..d391371 100644
33321 --- a/drivers/gpu/drm/r128/r128_irq.c
33322 +++ b/drivers/gpu/drm/r128/r128_irq.c
33323 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
33324 if (crtc != 0)
33325 return 0;
33326
33327 - return atomic_read(&dev_priv->vbl_received);
33328 + return atomic_read_unchecked(&dev_priv->vbl_received);
33329 }
33330
33331 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
33332 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
33333 /* VBLANK interrupt */
33334 if (status & R128_CRTC_VBLANK_INT) {
33335 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
33336 - atomic_inc(&dev_priv->vbl_received);
33337 + atomic_inc_unchecked(&dev_priv->vbl_received);
33338 drm_handle_vblank(dev, 0);
33339 return IRQ_HANDLED;
33340 }
33341 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
33342 index 19bb7e6..de7e2a2 100644
33343 --- a/drivers/gpu/drm/r128/r128_state.c
33344 +++ b/drivers/gpu/drm/r128/r128_state.c
33345 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
33346
33347 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
33348 {
33349 - if (atomic_read(&dev_priv->idle_count) == 0)
33350 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
33351 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
33352 else
33353 - atomic_set(&dev_priv->idle_count, 0);
33354 + atomic_set_unchecked(&dev_priv->idle_count, 0);
33355 }
33356
33357 #endif
33358 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
33359 index 5a82b6b..9e69c73 100644
33360 --- a/drivers/gpu/drm/radeon/mkregtable.c
33361 +++ b/drivers/gpu/drm/radeon/mkregtable.c
33362 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
33363 regex_t mask_rex;
33364 regmatch_t match[4];
33365 char buf[1024];
33366 - size_t end;
33367 + long end;
33368 int len;
33369 int done = 0;
33370 int r;
33371 unsigned o;
33372 struct offset *offset;
33373 char last_reg_s[10];
33374 - int last_reg;
33375 + unsigned long last_reg;
33376
33377 if (regcomp
33378 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
33379 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
33380 index 008d645..de03849 100644
33381 --- a/drivers/gpu/drm/radeon/radeon_device.c
33382 +++ b/drivers/gpu/drm/radeon/radeon_device.c
33383 @@ -941,7 +941,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
33384 bool can_switch;
33385
33386 spin_lock(&dev->count_lock);
33387 - can_switch = (dev->open_count == 0);
33388 + can_switch = (local_read(&dev->open_count) == 0);
33389 spin_unlock(&dev->count_lock);
33390 return can_switch;
33391 }
33392 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
33393 index a1b59ca..86f2d44 100644
33394 --- a/drivers/gpu/drm/radeon/radeon_drv.h
33395 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
33396 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
33397
33398 /* SW interrupt */
33399 wait_queue_head_t swi_queue;
33400 - atomic_t swi_emitted;
33401 + atomic_unchecked_t swi_emitted;
33402 int vblank_crtc;
33403 uint32_t irq_enable_reg;
33404 uint32_t r500_disp_irq_reg;
33405 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
33406 index c180df8..cd80dd2d 100644
33407 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
33408 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
33409 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
33410 request = compat_alloc_user_space(sizeof(*request));
33411 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
33412 || __put_user(req32.param, &request->param)
33413 - || __put_user((void __user *)(unsigned long)req32.value,
33414 + || __put_user((unsigned long)req32.value,
33415 &request->value))
33416 return -EFAULT;
33417
33418 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
33419 index e771033..a0bc6b3 100644
33420 --- a/drivers/gpu/drm/radeon/radeon_irq.c
33421 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
33422 @@ -224,8 +224,8 @@ static int radeon_emit_irq(struct drm_device * dev)
33423 unsigned int ret;
33424 RING_LOCALS;
33425
33426 - atomic_inc(&dev_priv->swi_emitted);
33427 - ret = atomic_read(&dev_priv->swi_emitted);
33428 + atomic_inc_unchecked(&dev_priv->swi_emitted);
33429 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
33430
33431 BEGIN_RING(4);
33432 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
33433 @@ -351,7 +351,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
33434 drm_radeon_private_t *dev_priv =
33435 (drm_radeon_private_t *) dev->dev_private;
33436
33437 - atomic_set(&dev_priv->swi_emitted, 0);
33438 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
33439 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
33440
33441 dev->max_vblank_count = 0x001fffff;
33442 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
33443 index 8e9057b..af6dacb 100644
33444 --- a/drivers/gpu/drm/radeon/radeon_state.c
33445 +++ b/drivers/gpu/drm/radeon/radeon_state.c
33446 @@ -2166,7 +2166,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
33447 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
33448 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
33449
33450 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
33451 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
33452 sarea_priv->nbox * sizeof(depth_boxes[0])))
33453 return -EFAULT;
33454
33455 @@ -3029,7 +3029,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
33456 {
33457 drm_radeon_private_t *dev_priv = dev->dev_private;
33458 drm_radeon_getparam_t *param = data;
33459 - int value;
33460 + int value = 0;
33461
33462 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
33463
33464 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
33465 index 5ebe1b3..1ed9426 100644
33466 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
33467 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
33468 @@ -822,8 +822,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
33469 }
33470 if (unlikely(ttm_vm_ops == NULL)) {
33471 ttm_vm_ops = vma->vm_ops;
33472 - radeon_ttm_vm_ops = *ttm_vm_ops;
33473 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
33474 + pax_open_kernel();
33475 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
33476 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
33477 + pax_close_kernel();
33478 }
33479 vma->vm_ops = &radeon_ttm_vm_ops;
33480 return 0;
33481 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
33482 index 5706d2a..17aedaa 100644
33483 --- a/drivers/gpu/drm/radeon/rs690.c
33484 +++ b/drivers/gpu/drm/radeon/rs690.c
33485 @@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
33486 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
33487 rdev->pm.sideport_bandwidth.full)
33488 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
33489 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
33490 + read_delay_latency.full = dfixed_const(800 * 1000);
33491 read_delay_latency.full = dfixed_div(read_delay_latency,
33492 rdev->pm.igp_sideport_mclk);
33493 + a.full = dfixed_const(370);
33494 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
33495 } else {
33496 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
33497 rdev->pm.k8_bandwidth.full)
33498 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
33499 index bd2a3b4..122d9ad 100644
33500 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
33501 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
33502 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
33503 static int ttm_pool_mm_shrink(struct shrinker *shrink,
33504 struct shrink_control *sc)
33505 {
33506 - static atomic_t start_pool = ATOMIC_INIT(0);
33507 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
33508 unsigned i;
33509 - unsigned pool_offset = atomic_add_return(1, &start_pool);
33510 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
33511 struct ttm_page_pool *pool;
33512 int shrink_pages = sc->nr_to_scan;
33513
33514 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
33515 index 893a650..6190d3b 100644
33516 --- a/drivers/gpu/drm/via/via_drv.h
33517 +++ b/drivers/gpu/drm/via/via_drv.h
33518 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
33519 typedef uint32_t maskarray_t[5];
33520
33521 typedef struct drm_via_irq {
33522 - atomic_t irq_received;
33523 + atomic_unchecked_t irq_received;
33524 uint32_t pending_mask;
33525 uint32_t enable_mask;
33526 wait_queue_head_t irq_queue;
33527 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
33528 struct timeval last_vblank;
33529 int last_vblank_valid;
33530 unsigned usec_per_vblank;
33531 - atomic_t vbl_received;
33532 + atomic_unchecked_t vbl_received;
33533 drm_via_state_t hc_state;
33534 char pci_buf[VIA_PCI_BUF_SIZE];
33535 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
33536 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
33537 index ac98964..5dbf512 100644
33538 --- a/drivers/gpu/drm/via/via_irq.c
33539 +++ b/drivers/gpu/drm/via/via_irq.c
33540 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
33541 if (crtc != 0)
33542 return 0;
33543
33544 - return atomic_read(&dev_priv->vbl_received);
33545 + return atomic_read_unchecked(&dev_priv->vbl_received);
33546 }
33547
33548 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33549 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33550
33551 status = VIA_READ(VIA_REG_INTERRUPT);
33552 if (status & VIA_IRQ_VBLANK_PENDING) {
33553 - atomic_inc(&dev_priv->vbl_received);
33554 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
33555 + atomic_inc_unchecked(&dev_priv->vbl_received);
33556 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
33557 do_gettimeofday(&cur_vblank);
33558 if (dev_priv->last_vblank_valid) {
33559 dev_priv->usec_per_vblank =
33560 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33561 dev_priv->last_vblank = cur_vblank;
33562 dev_priv->last_vblank_valid = 1;
33563 }
33564 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
33565 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
33566 DRM_DEBUG("US per vblank is: %u\n",
33567 dev_priv->usec_per_vblank);
33568 }
33569 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33570
33571 for (i = 0; i < dev_priv->num_irqs; ++i) {
33572 if (status & cur_irq->pending_mask) {
33573 - atomic_inc(&cur_irq->irq_received);
33574 + atomic_inc_unchecked(&cur_irq->irq_received);
33575 DRM_WAKEUP(&cur_irq->irq_queue);
33576 handled = 1;
33577 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
33578 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
33579 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
33580 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
33581 masks[irq][4]));
33582 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
33583 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
33584 } else {
33585 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
33586 (((cur_irq_sequence =
33587 - atomic_read(&cur_irq->irq_received)) -
33588 + atomic_read_unchecked(&cur_irq->irq_received)) -
33589 *sequence) <= (1 << 23)));
33590 }
33591 *sequence = cur_irq_sequence;
33592 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
33593 }
33594
33595 for (i = 0; i < dev_priv->num_irqs; ++i) {
33596 - atomic_set(&cur_irq->irq_received, 0);
33597 + atomic_set_unchecked(&cur_irq->irq_received, 0);
33598 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
33599 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
33600 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
33601 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
33602 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
33603 case VIA_IRQ_RELATIVE:
33604 irqwait->request.sequence +=
33605 - atomic_read(&cur_irq->irq_received);
33606 + atomic_read_unchecked(&cur_irq->irq_received);
33607 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
33608 case VIA_IRQ_ABSOLUTE:
33609 break;
33610 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
33611 index 88a179e..57fe50481c 100644
33612 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
33613 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
33614 @@ -263,7 +263,7 @@ struct vmw_private {
33615 * Fencing and IRQs.
33616 */
33617
33618 - atomic_t marker_seq;
33619 + atomic_unchecked_t marker_seq;
33620 wait_queue_head_t fence_queue;
33621 wait_queue_head_t fifo_queue;
33622 int fence_queue_waiters; /* Protected by hw_mutex */
33623 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
33624 index 3eb1486..0a47ee9 100644
33625 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
33626 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
33627 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
33628 (unsigned int) min,
33629 (unsigned int) fifo->capabilities);
33630
33631 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
33632 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
33633 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
33634 vmw_marker_queue_init(&fifo->marker_queue);
33635 return vmw_fifo_send_fence(dev_priv, &dummy);
33636 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
33637 if (reserveable)
33638 iowrite32(bytes, fifo_mem +
33639 SVGA_FIFO_RESERVED);
33640 - return fifo_mem + (next_cmd >> 2);
33641 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
33642 } else {
33643 need_bounce = true;
33644 }
33645 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
33646
33647 fm = vmw_fifo_reserve(dev_priv, bytes);
33648 if (unlikely(fm == NULL)) {
33649 - *seqno = atomic_read(&dev_priv->marker_seq);
33650 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
33651 ret = -ENOMEM;
33652 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
33653 false, 3*HZ);
33654 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
33655 }
33656
33657 do {
33658 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
33659 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
33660 } while (*seqno == 0);
33661
33662 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
33663 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
33664 index 4640adb..e1384ed 100644
33665 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
33666 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
33667 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
33668 * emitted. Then the fence is stale and signaled.
33669 */
33670
33671 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
33672 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
33673 > VMW_FENCE_WRAP);
33674
33675 return ret;
33676 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
33677
33678 if (fifo_idle)
33679 down_read(&fifo_state->rwsem);
33680 - signal_seq = atomic_read(&dev_priv->marker_seq);
33681 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
33682 ret = 0;
33683
33684 for (;;) {
33685 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
33686 index 8a8725c..afed796 100644
33687 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
33688 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
33689 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
33690 while (!vmw_lag_lt(queue, us)) {
33691 spin_lock(&queue->lock);
33692 if (list_empty(&queue->head))
33693 - seqno = atomic_read(&dev_priv->marker_seq);
33694 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
33695 else {
33696 marker = list_first_entry(&queue->head,
33697 struct vmw_marker, head);
33698 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
33699 index 52146db..ae33762 100644
33700 --- a/drivers/hid/hid-core.c
33701 +++ b/drivers/hid/hid-core.c
33702 @@ -2201,7 +2201,7 @@ static bool hid_ignore(struct hid_device *hdev)
33703
33704 int hid_add_device(struct hid_device *hdev)
33705 {
33706 - static atomic_t id = ATOMIC_INIT(0);
33707 + static atomic_unchecked_t id = ATOMIC_INIT(0);
33708 int ret;
33709
33710 if (WARN_ON(hdev->status & HID_STAT_ADDED))
33711 @@ -2236,7 +2236,7 @@ int hid_add_device(struct hid_device *hdev)
33712 /* XXX hack, any other cleaner solution after the driver core
33713 * is converted to allow more than 20 bytes as the device name? */
33714 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
33715 - hdev->vendor, hdev->product, atomic_inc_return(&id));
33716 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
33717
33718 hid_debug_register(hdev, dev_name(&hdev->dev));
33719 ret = device_add(&hdev->dev);
33720 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
33721 index eec3291..8ed706b 100644
33722 --- a/drivers/hid/hid-wiimote-debug.c
33723 +++ b/drivers/hid/hid-wiimote-debug.c
33724 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
33725 else if (size == 0)
33726 return -EIO;
33727
33728 - if (copy_to_user(u, buf, size))
33729 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
33730 return -EFAULT;
33731
33732 *off += size;
33733 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
33734 index 14599e2..711c965 100644
33735 --- a/drivers/hid/usbhid/hiddev.c
33736 +++ b/drivers/hid/usbhid/hiddev.c
33737 @@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
33738 break;
33739
33740 case HIDIOCAPPLICATION:
33741 - if (arg < 0 || arg >= hid->maxapplication)
33742 + if (arg >= hid->maxapplication)
33743 break;
33744
33745 for (i = 0; i < hid->maxcollection; i++)
33746 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
33747 index f4c3d28..82f45a9 100644
33748 --- a/drivers/hv/channel.c
33749 +++ b/drivers/hv/channel.c
33750 @@ -402,8 +402,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
33751 int ret = 0;
33752 int t;
33753
33754 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
33755 - atomic_inc(&vmbus_connection.next_gpadl_handle);
33756 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
33757 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
33758
33759 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
33760 if (ret)
33761 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
33762 index 3648f8f..30ef30d 100644
33763 --- a/drivers/hv/hv.c
33764 +++ b/drivers/hv/hv.c
33765 @@ -111,7 +111,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
33766 u64 output_address = (output) ? virt_to_phys(output) : 0;
33767 u32 output_address_hi = output_address >> 32;
33768 u32 output_address_lo = output_address & 0xFFFFFFFF;
33769 - void *hypercall_page = hv_context.hypercall_page;
33770 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
33771
33772 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
33773 "=a"(hv_status_lo) : "d" (control_hi),
33774 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
33775 index d8d1fad..b91caf7 100644
33776 --- a/drivers/hv/hyperv_vmbus.h
33777 +++ b/drivers/hv/hyperv_vmbus.h
33778 @@ -594,7 +594,7 @@ enum vmbus_connect_state {
33779 struct vmbus_connection {
33780 enum vmbus_connect_state conn_state;
33781
33782 - atomic_t next_gpadl_handle;
33783 + atomic_unchecked_t next_gpadl_handle;
33784
33785 /*
33786 * Represents channel interrupts. Each bit position represents a
33787 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
33788 index 8e1a9ec..4687821 100644
33789 --- a/drivers/hv/vmbus_drv.c
33790 +++ b/drivers/hv/vmbus_drv.c
33791 @@ -629,10 +629,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
33792 {
33793 int ret = 0;
33794
33795 - static atomic_t device_num = ATOMIC_INIT(0);
33796 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
33797
33798 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
33799 - atomic_inc_return(&device_num));
33800 + atomic_inc_return_unchecked(&device_num));
33801
33802 child_device_obj->device.bus = &hv_bus;
33803 child_device_obj->device.parent = &hv_acpi_dev->dev;
33804 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
33805 index 07a0c1a..0cac334 100644
33806 --- a/drivers/hwmon/sht15.c
33807 +++ b/drivers/hwmon/sht15.c
33808 @@ -169,7 +169,7 @@ struct sht15_data {
33809 int supply_uV;
33810 bool supply_uV_valid;
33811 struct work_struct update_supply_work;
33812 - atomic_t interrupt_handled;
33813 + atomic_unchecked_t interrupt_handled;
33814 };
33815
33816 /**
33817 @@ -512,13 +512,13 @@ static int sht15_measurement(struct sht15_data *data,
33818 return ret;
33819
33820 gpio_direction_input(data->pdata->gpio_data);
33821 - atomic_set(&data->interrupt_handled, 0);
33822 + atomic_set_unchecked(&data->interrupt_handled, 0);
33823
33824 enable_irq(gpio_to_irq(data->pdata->gpio_data));
33825 if (gpio_get_value(data->pdata->gpio_data) == 0) {
33826 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
33827 /* Only relevant if the interrupt hasn't occurred. */
33828 - if (!atomic_read(&data->interrupt_handled))
33829 + if (!atomic_read_unchecked(&data->interrupt_handled))
33830 schedule_work(&data->read_work);
33831 }
33832 ret = wait_event_timeout(data->wait_queue,
33833 @@ -785,7 +785,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
33834
33835 /* First disable the interrupt */
33836 disable_irq_nosync(irq);
33837 - atomic_inc(&data->interrupt_handled);
33838 + atomic_inc_unchecked(&data->interrupt_handled);
33839 /* Then schedule a reading work struct */
33840 if (data->state != SHT15_READING_NOTHING)
33841 schedule_work(&data->read_work);
33842 @@ -807,11 +807,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
33843 * If not, then start the interrupt again - care here as could
33844 * have gone low in meantime so verify it hasn't!
33845 */
33846 - atomic_set(&data->interrupt_handled, 0);
33847 + atomic_set_unchecked(&data->interrupt_handled, 0);
33848 enable_irq(gpio_to_irq(data->pdata->gpio_data));
33849 /* If still not occurred or another handler was scheduled */
33850 if (gpio_get_value(data->pdata->gpio_data)
33851 - || atomic_read(&data->interrupt_handled))
33852 + || atomic_read_unchecked(&data->interrupt_handled))
33853 return;
33854 }
33855
33856 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
33857 index 378fcb5..5e91fa8 100644
33858 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
33859 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
33860 @@ -43,7 +43,7 @@
33861 extern struct i2c_adapter amd756_smbus;
33862
33863 static struct i2c_adapter *s4882_adapter;
33864 -static struct i2c_algorithm *s4882_algo;
33865 +static i2c_algorithm_no_const *s4882_algo;
33866
33867 /* Wrapper access functions for multiplexed SMBus */
33868 static DEFINE_MUTEX(amd756_lock);
33869 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
33870 index 29015eb..af2d8e9 100644
33871 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
33872 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
33873 @@ -41,7 +41,7 @@
33874 extern struct i2c_adapter *nforce2_smbus;
33875
33876 static struct i2c_adapter *s4985_adapter;
33877 -static struct i2c_algorithm *s4985_algo;
33878 +static i2c_algorithm_no_const *s4985_algo;
33879
33880 /* Wrapper access functions for multiplexed SMBus */
33881 static DEFINE_MUTEX(nforce2_lock);
33882 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
33883 index 8126824..55a2798 100644
33884 --- a/drivers/ide/ide-cd.c
33885 +++ b/drivers/ide/ide-cd.c
33886 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
33887 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
33888 if ((unsigned long)buf & alignment
33889 || blk_rq_bytes(rq) & q->dma_pad_mask
33890 - || object_is_on_stack(buf))
33891 + || object_starts_on_stack(buf))
33892 drive->dma = 0;
33893 }
33894 }
33895 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
33896 index 394fea2..c833880 100644
33897 --- a/drivers/infiniband/core/cm.c
33898 +++ b/drivers/infiniband/core/cm.c
33899 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
33900
33901 struct cm_counter_group {
33902 struct kobject obj;
33903 - atomic_long_t counter[CM_ATTR_COUNT];
33904 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
33905 };
33906
33907 struct cm_counter_attribute {
33908 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
33909 struct ib_mad_send_buf *msg = NULL;
33910 int ret;
33911
33912 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33913 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33914 counter[CM_REQ_COUNTER]);
33915
33916 /* Quick state check to discard duplicate REQs. */
33917 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
33918 if (!cm_id_priv)
33919 return;
33920
33921 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33922 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33923 counter[CM_REP_COUNTER]);
33924 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
33925 if (ret)
33926 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
33927 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
33928 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
33929 spin_unlock_irq(&cm_id_priv->lock);
33930 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33931 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33932 counter[CM_RTU_COUNTER]);
33933 goto out;
33934 }
33935 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
33936 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
33937 dreq_msg->local_comm_id);
33938 if (!cm_id_priv) {
33939 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33940 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33941 counter[CM_DREQ_COUNTER]);
33942 cm_issue_drep(work->port, work->mad_recv_wc);
33943 return -EINVAL;
33944 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
33945 case IB_CM_MRA_REP_RCVD:
33946 break;
33947 case IB_CM_TIMEWAIT:
33948 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33949 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33950 counter[CM_DREQ_COUNTER]);
33951 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
33952 goto unlock;
33953 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
33954 cm_free_msg(msg);
33955 goto deref;
33956 case IB_CM_DREQ_RCVD:
33957 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33958 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33959 counter[CM_DREQ_COUNTER]);
33960 goto unlock;
33961 default:
33962 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
33963 ib_modify_mad(cm_id_priv->av.port->mad_agent,
33964 cm_id_priv->msg, timeout)) {
33965 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
33966 - atomic_long_inc(&work->port->
33967 + atomic_long_inc_unchecked(&work->port->
33968 counter_group[CM_RECV_DUPLICATES].
33969 counter[CM_MRA_COUNTER]);
33970 goto out;
33971 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
33972 break;
33973 case IB_CM_MRA_REQ_RCVD:
33974 case IB_CM_MRA_REP_RCVD:
33975 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33976 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33977 counter[CM_MRA_COUNTER]);
33978 /* fall through */
33979 default:
33980 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
33981 case IB_CM_LAP_IDLE:
33982 break;
33983 case IB_CM_MRA_LAP_SENT:
33984 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33985 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33986 counter[CM_LAP_COUNTER]);
33987 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
33988 goto unlock;
33989 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
33990 cm_free_msg(msg);
33991 goto deref;
33992 case IB_CM_LAP_RCVD:
33993 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33994 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33995 counter[CM_LAP_COUNTER]);
33996 goto unlock;
33997 default:
33998 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
33999 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
34000 if (cur_cm_id_priv) {
34001 spin_unlock_irq(&cm.lock);
34002 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34003 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34004 counter[CM_SIDR_REQ_COUNTER]);
34005 goto out; /* Duplicate message. */
34006 }
34007 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
34008 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
34009 msg->retries = 1;
34010
34011 - atomic_long_add(1 + msg->retries,
34012 + atomic_long_add_unchecked(1 + msg->retries,
34013 &port->counter_group[CM_XMIT].counter[attr_index]);
34014 if (msg->retries)
34015 - atomic_long_add(msg->retries,
34016 + atomic_long_add_unchecked(msg->retries,
34017 &port->counter_group[CM_XMIT_RETRIES].
34018 counter[attr_index]);
34019
34020 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
34021 }
34022
34023 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
34024 - atomic_long_inc(&port->counter_group[CM_RECV].
34025 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
34026 counter[attr_id - CM_ATTR_ID_OFFSET]);
34027
34028 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
34029 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
34030 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
34031
34032 return sprintf(buf, "%ld\n",
34033 - atomic_long_read(&group->counter[cm_attr->index]));
34034 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
34035 }
34036
34037 static const struct sysfs_ops cm_counter_ops = {
34038 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
34039 index 176c8f9..2627b62 100644
34040 --- a/drivers/infiniband/core/fmr_pool.c
34041 +++ b/drivers/infiniband/core/fmr_pool.c
34042 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
34043
34044 struct task_struct *thread;
34045
34046 - atomic_t req_ser;
34047 - atomic_t flush_ser;
34048 + atomic_unchecked_t req_ser;
34049 + atomic_unchecked_t flush_ser;
34050
34051 wait_queue_head_t force_wait;
34052 };
34053 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
34054 struct ib_fmr_pool *pool = pool_ptr;
34055
34056 do {
34057 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
34058 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
34059 ib_fmr_batch_release(pool);
34060
34061 - atomic_inc(&pool->flush_ser);
34062 + atomic_inc_unchecked(&pool->flush_ser);
34063 wake_up_interruptible(&pool->force_wait);
34064
34065 if (pool->flush_function)
34066 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
34067 }
34068
34069 set_current_state(TASK_INTERRUPTIBLE);
34070 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
34071 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
34072 !kthread_should_stop())
34073 schedule();
34074 __set_current_state(TASK_RUNNING);
34075 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
34076 pool->dirty_watermark = params->dirty_watermark;
34077 pool->dirty_len = 0;
34078 spin_lock_init(&pool->pool_lock);
34079 - atomic_set(&pool->req_ser, 0);
34080 - atomic_set(&pool->flush_ser, 0);
34081 + atomic_set_unchecked(&pool->req_ser, 0);
34082 + atomic_set_unchecked(&pool->flush_ser, 0);
34083 init_waitqueue_head(&pool->force_wait);
34084
34085 pool->thread = kthread_run(ib_fmr_cleanup_thread,
34086 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
34087 }
34088 spin_unlock_irq(&pool->pool_lock);
34089
34090 - serial = atomic_inc_return(&pool->req_ser);
34091 + serial = atomic_inc_return_unchecked(&pool->req_ser);
34092 wake_up_process(pool->thread);
34093
34094 if (wait_event_interruptible(pool->force_wait,
34095 - atomic_read(&pool->flush_ser) - serial >= 0))
34096 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
34097 return -EINTR;
34098
34099 return 0;
34100 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
34101 } else {
34102 list_add_tail(&fmr->list, &pool->dirty_list);
34103 if (++pool->dirty_len >= pool->dirty_watermark) {
34104 - atomic_inc(&pool->req_ser);
34105 + atomic_inc_unchecked(&pool->req_ser);
34106 wake_up_process(pool->thread);
34107 }
34108 }
34109 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
34110 index afd8179..598063f 100644
34111 --- a/drivers/infiniband/hw/cxgb4/mem.c
34112 +++ b/drivers/infiniband/hw/cxgb4/mem.c
34113 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
34114 int err;
34115 struct fw_ri_tpte tpt;
34116 u32 stag_idx;
34117 - static atomic_t key;
34118 + static atomic_unchecked_t key;
34119
34120 if (c4iw_fatal_error(rdev))
34121 return -EIO;
34122 @@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
34123 if (rdev->stats.stag.cur > rdev->stats.stag.max)
34124 rdev->stats.stag.max = rdev->stats.stag.cur;
34125 mutex_unlock(&rdev->stats.lock);
34126 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
34127 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
34128 }
34129 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
34130 __func__, stag_state, type, pdid, stag_idx);
34131 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
34132 index 79b3dbc..96e5fcc 100644
34133 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
34134 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
34135 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
34136 struct ib_atomic_eth *ateth;
34137 struct ipath_ack_entry *e;
34138 u64 vaddr;
34139 - atomic64_t *maddr;
34140 + atomic64_unchecked_t *maddr;
34141 u64 sdata;
34142 u32 rkey;
34143 u8 next;
34144 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
34145 IB_ACCESS_REMOTE_ATOMIC)))
34146 goto nack_acc_unlck;
34147 /* Perform atomic OP and save result. */
34148 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
34149 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
34150 sdata = be64_to_cpu(ateth->swap_data);
34151 e = &qp->s_ack_queue[qp->r_head_ack_queue];
34152 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
34153 - (u64) atomic64_add_return(sdata, maddr) - sdata :
34154 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
34155 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
34156 be64_to_cpu(ateth->compare_data),
34157 sdata);
34158 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
34159 index 1f95bba..9530f87 100644
34160 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
34161 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
34162 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
34163 unsigned long flags;
34164 struct ib_wc wc;
34165 u64 sdata;
34166 - atomic64_t *maddr;
34167 + atomic64_unchecked_t *maddr;
34168 enum ib_wc_status send_status;
34169
34170 /*
34171 @@ -382,11 +382,11 @@ again:
34172 IB_ACCESS_REMOTE_ATOMIC)))
34173 goto acc_err;
34174 /* Perform atomic OP and save result. */
34175 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
34176 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
34177 sdata = wqe->wr.wr.atomic.compare_add;
34178 *(u64 *) sqp->s_sge.sge.vaddr =
34179 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
34180 - (u64) atomic64_add_return(sdata, maddr) - sdata :
34181 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
34182 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
34183 sdata, wqe->wr.wr.atomic.swap);
34184 goto send_comp;
34185 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
34186 index 748db2d..5f75cc3 100644
34187 --- a/drivers/infiniband/hw/nes/nes.c
34188 +++ b/drivers/infiniband/hw/nes/nes.c
34189 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
34190 LIST_HEAD(nes_adapter_list);
34191 static LIST_HEAD(nes_dev_list);
34192
34193 -atomic_t qps_destroyed;
34194 +atomic_unchecked_t qps_destroyed;
34195
34196 static unsigned int ee_flsh_adapter;
34197 static unsigned int sysfs_nonidx_addr;
34198 @@ -267,7 +267,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
34199 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
34200 struct nes_adapter *nesadapter = nesdev->nesadapter;
34201
34202 - atomic_inc(&qps_destroyed);
34203 + atomic_inc_unchecked(&qps_destroyed);
34204
34205 /* Free the control structures */
34206
34207 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
34208 index 33cc589..3bd6538 100644
34209 --- a/drivers/infiniband/hw/nes/nes.h
34210 +++ b/drivers/infiniband/hw/nes/nes.h
34211 @@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
34212 extern unsigned int wqm_quanta;
34213 extern struct list_head nes_adapter_list;
34214
34215 -extern atomic_t cm_connects;
34216 -extern atomic_t cm_accepts;
34217 -extern atomic_t cm_disconnects;
34218 -extern atomic_t cm_closes;
34219 -extern atomic_t cm_connecteds;
34220 -extern atomic_t cm_connect_reqs;
34221 -extern atomic_t cm_rejects;
34222 -extern atomic_t mod_qp_timouts;
34223 -extern atomic_t qps_created;
34224 -extern atomic_t qps_destroyed;
34225 -extern atomic_t sw_qps_destroyed;
34226 +extern atomic_unchecked_t cm_connects;
34227 +extern atomic_unchecked_t cm_accepts;
34228 +extern atomic_unchecked_t cm_disconnects;
34229 +extern atomic_unchecked_t cm_closes;
34230 +extern atomic_unchecked_t cm_connecteds;
34231 +extern atomic_unchecked_t cm_connect_reqs;
34232 +extern atomic_unchecked_t cm_rejects;
34233 +extern atomic_unchecked_t mod_qp_timouts;
34234 +extern atomic_unchecked_t qps_created;
34235 +extern atomic_unchecked_t qps_destroyed;
34236 +extern atomic_unchecked_t sw_qps_destroyed;
34237 extern u32 mh_detected;
34238 extern u32 mh_pauses_sent;
34239 extern u32 cm_packets_sent;
34240 @@ -196,16 +196,16 @@ extern u32 cm_packets_created;
34241 extern u32 cm_packets_received;
34242 extern u32 cm_packets_dropped;
34243 extern u32 cm_packets_retrans;
34244 -extern atomic_t cm_listens_created;
34245 -extern atomic_t cm_listens_destroyed;
34246 +extern atomic_unchecked_t cm_listens_created;
34247 +extern atomic_unchecked_t cm_listens_destroyed;
34248 extern u32 cm_backlog_drops;
34249 -extern atomic_t cm_loopbacks;
34250 -extern atomic_t cm_nodes_created;
34251 -extern atomic_t cm_nodes_destroyed;
34252 -extern atomic_t cm_accel_dropped_pkts;
34253 -extern atomic_t cm_resets_recvd;
34254 -extern atomic_t pau_qps_created;
34255 -extern atomic_t pau_qps_destroyed;
34256 +extern atomic_unchecked_t cm_loopbacks;
34257 +extern atomic_unchecked_t cm_nodes_created;
34258 +extern atomic_unchecked_t cm_nodes_destroyed;
34259 +extern atomic_unchecked_t cm_accel_dropped_pkts;
34260 +extern atomic_unchecked_t cm_resets_recvd;
34261 +extern atomic_unchecked_t pau_qps_created;
34262 +extern atomic_unchecked_t pau_qps_destroyed;
34263
34264 extern u32 int_mod_timer_init;
34265 extern u32 int_mod_cq_depth_256;
34266 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
34267 index cfaacaf..fa0722e 100644
34268 --- a/drivers/infiniband/hw/nes/nes_cm.c
34269 +++ b/drivers/infiniband/hw/nes/nes_cm.c
34270 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
34271 u32 cm_packets_retrans;
34272 u32 cm_packets_created;
34273 u32 cm_packets_received;
34274 -atomic_t cm_listens_created;
34275 -atomic_t cm_listens_destroyed;
34276 +atomic_unchecked_t cm_listens_created;
34277 +atomic_unchecked_t cm_listens_destroyed;
34278 u32 cm_backlog_drops;
34279 -atomic_t cm_loopbacks;
34280 -atomic_t cm_nodes_created;
34281 -atomic_t cm_nodes_destroyed;
34282 -atomic_t cm_accel_dropped_pkts;
34283 -atomic_t cm_resets_recvd;
34284 +atomic_unchecked_t cm_loopbacks;
34285 +atomic_unchecked_t cm_nodes_created;
34286 +atomic_unchecked_t cm_nodes_destroyed;
34287 +atomic_unchecked_t cm_accel_dropped_pkts;
34288 +atomic_unchecked_t cm_resets_recvd;
34289
34290 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
34291 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
34292 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
34293
34294 static struct nes_cm_core *g_cm_core;
34295
34296 -atomic_t cm_connects;
34297 -atomic_t cm_accepts;
34298 -atomic_t cm_disconnects;
34299 -atomic_t cm_closes;
34300 -atomic_t cm_connecteds;
34301 -atomic_t cm_connect_reqs;
34302 -atomic_t cm_rejects;
34303 +atomic_unchecked_t cm_connects;
34304 +atomic_unchecked_t cm_accepts;
34305 +atomic_unchecked_t cm_disconnects;
34306 +atomic_unchecked_t cm_closes;
34307 +atomic_unchecked_t cm_connecteds;
34308 +atomic_unchecked_t cm_connect_reqs;
34309 +atomic_unchecked_t cm_rejects;
34310
34311 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
34312 {
34313 @@ -1281,7 +1281,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
34314 kfree(listener);
34315 listener = NULL;
34316 ret = 0;
34317 - atomic_inc(&cm_listens_destroyed);
34318 + atomic_inc_unchecked(&cm_listens_destroyed);
34319 } else {
34320 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
34321 }
34322 @@ -1480,7 +1480,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
34323 cm_node->rem_mac);
34324
34325 add_hte_node(cm_core, cm_node);
34326 - atomic_inc(&cm_nodes_created);
34327 + atomic_inc_unchecked(&cm_nodes_created);
34328
34329 return cm_node;
34330 }
34331 @@ -1538,7 +1538,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
34332 }
34333
34334 atomic_dec(&cm_core->node_cnt);
34335 - atomic_inc(&cm_nodes_destroyed);
34336 + atomic_inc_unchecked(&cm_nodes_destroyed);
34337 nesqp = cm_node->nesqp;
34338 if (nesqp) {
34339 nesqp->cm_node = NULL;
34340 @@ -1602,7 +1602,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
34341
34342 static void drop_packet(struct sk_buff *skb)
34343 {
34344 - atomic_inc(&cm_accel_dropped_pkts);
34345 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
34346 dev_kfree_skb_any(skb);
34347 }
34348
34349 @@ -1665,7 +1665,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
34350 {
34351
34352 int reset = 0; /* whether to send reset in case of err.. */
34353 - atomic_inc(&cm_resets_recvd);
34354 + atomic_inc_unchecked(&cm_resets_recvd);
34355 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
34356 " refcnt=%d\n", cm_node, cm_node->state,
34357 atomic_read(&cm_node->ref_count));
34358 @@ -2306,7 +2306,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
34359 rem_ref_cm_node(cm_node->cm_core, cm_node);
34360 return NULL;
34361 }
34362 - atomic_inc(&cm_loopbacks);
34363 + atomic_inc_unchecked(&cm_loopbacks);
34364 loopbackremotenode->loopbackpartner = cm_node;
34365 loopbackremotenode->tcp_cntxt.rcv_wscale =
34366 NES_CM_DEFAULT_RCV_WND_SCALE;
34367 @@ -2581,7 +2581,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
34368 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
34369 else {
34370 rem_ref_cm_node(cm_core, cm_node);
34371 - atomic_inc(&cm_accel_dropped_pkts);
34372 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
34373 dev_kfree_skb_any(skb);
34374 }
34375 break;
34376 @@ -2889,7 +2889,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
34377
34378 if ((cm_id) && (cm_id->event_handler)) {
34379 if (issue_disconn) {
34380 - atomic_inc(&cm_disconnects);
34381 + atomic_inc_unchecked(&cm_disconnects);
34382 cm_event.event = IW_CM_EVENT_DISCONNECT;
34383 cm_event.status = disconn_status;
34384 cm_event.local_addr = cm_id->local_addr;
34385 @@ -2911,7 +2911,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
34386 }
34387
34388 if (issue_close) {
34389 - atomic_inc(&cm_closes);
34390 + atomic_inc_unchecked(&cm_closes);
34391 nes_disconnect(nesqp, 1);
34392
34393 cm_id->provider_data = nesqp;
34394 @@ -3047,7 +3047,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
34395
34396 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
34397 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
34398 - atomic_inc(&cm_accepts);
34399 + atomic_inc_unchecked(&cm_accepts);
34400
34401 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
34402 netdev_refcnt_read(nesvnic->netdev));
34403 @@ -3242,7 +3242,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
34404 struct nes_cm_core *cm_core;
34405 u8 *start_buff;
34406
34407 - atomic_inc(&cm_rejects);
34408 + atomic_inc_unchecked(&cm_rejects);
34409 cm_node = (struct nes_cm_node *)cm_id->provider_data;
34410 loopback = cm_node->loopbackpartner;
34411 cm_core = cm_node->cm_core;
34412 @@ -3302,7 +3302,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
34413 ntohl(cm_id->local_addr.sin_addr.s_addr),
34414 ntohs(cm_id->local_addr.sin_port));
34415
34416 - atomic_inc(&cm_connects);
34417 + atomic_inc_unchecked(&cm_connects);
34418 nesqp->active_conn = 1;
34419
34420 /* cache the cm_id in the qp */
34421 @@ -3412,7 +3412,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
34422 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
34423 return err;
34424 }
34425 - atomic_inc(&cm_listens_created);
34426 + atomic_inc_unchecked(&cm_listens_created);
34427 }
34428
34429 cm_id->add_ref(cm_id);
34430 @@ -3513,7 +3513,7 @@ static void cm_event_connected(struct nes_cm_event *event)
34431
34432 if (nesqp->destroyed)
34433 return;
34434 - atomic_inc(&cm_connecteds);
34435 + atomic_inc_unchecked(&cm_connecteds);
34436 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
34437 " local port 0x%04X. jiffies = %lu.\n",
34438 nesqp->hwqp.qp_id,
34439 @@ -3693,7 +3693,7 @@ static void cm_event_reset(struct nes_cm_event *event)
34440
34441 cm_id->add_ref(cm_id);
34442 ret = cm_id->event_handler(cm_id, &cm_event);
34443 - atomic_inc(&cm_closes);
34444 + atomic_inc_unchecked(&cm_closes);
34445 cm_event.event = IW_CM_EVENT_CLOSE;
34446 cm_event.status = 0;
34447 cm_event.provider_data = cm_id->provider_data;
34448 @@ -3729,7 +3729,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
34449 return;
34450 cm_id = cm_node->cm_id;
34451
34452 - atomic_inc(&cm_connect_reqs);
34453 + atomic_inc_unchecked(&cm_connect_reqs);
34454 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
34455 cm_node, cm_id, jiffies);
34456
34457 @@ -3769,7 +3769,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
34458 return;
34459 cm_id = cm_node->cm_id;
34460
34461 - atomic_inc(&cm_connect_reqs);
34462 + atomic_inc_unchecked(&cm_connect_reqs);
34463 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
34464 cm_node, cm_id, jiffies);
34465
34466 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
34467 index 3ba7be3..c81f6ff 100644
34468 --- a/drivers/infiniband/hw/nes/nes_mgt.c
34469 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
34470 @@ -40,8 +40,8 @@
34471 #include "nes.h"
34472 #include "nes_mgt.h"
34473
34474 -atomic_t pau_qps_created;
34475 -atomic_t pau_qps_destroyed;
34476 +atomic_unchecked_t pau_qps_created;
34477 +atomic_unchecked_t pau_qps_destroyed;
34478
34479 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
34480 {
34481 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
34482 {
34483 struct sk_buff *skb;
34484 unsigned long flags;
34485 - atomic_inc(&pau_qps_destroyed);
34486 + atomic_inc_unchecked(&pau_qps_destroyed);
34487
34488 /* Free packets that have not yet been forwarded */
34489 /* Lock is acquired by skb_dequeue when removing the skb */
34490 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
34491 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
34492 skb_queue_head_init(&nesqp->pau_list);
34493 spin_lock_init(&nesqp->pau_lock);
34494 - atomic_inc(&pau_qps_created);
34495 + atomic_inc_unchecked(&pau_qps_created);
34496 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
34497 }
34498
34499 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
34500 index 0564be7..f68b0f1 100644
34501 --- a/drivers/infiniband/hw/nes/nes_nic.c
34502 +++ b/drivers/infiniband/hw/nes/nes_nic.c
34503 @@ -1272,39 +1272,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
34504 target_stat_values[++index] = mh_detected;
34505 target_stat_values[++index] = mh_pauses_sent;
34506 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
34507 - target_stat_values[++index] = atomic_read(&cm_connects);
34508 - target_stat_values[++index] = atomic_read(&cm_accepts);
34509 - target_stat_values[++index] = atomic_read(&cm_disconnects);
34510 - target_stat_values[++index] = atomic_read(&cm_connecteds);
34511 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
34512 - target_stat_values[++index] = atomic_read(&cm_rejects);
34513 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
34514 - target_stat_values[++index] = atomic_read(&qps_created);
34515 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
34516 - target_stat_values[++index] = atomic_read(&qps_destroyed);
34517 - target_stat_values[++index] = atomic_read(&cm_closes);
34518 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
34519 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
34520 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
34521 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
34522 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
34523 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
34524 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
34525 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
34526 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
34527 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
34528 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
34529 target_stat_values[++index] = cm_packets_sent;
34530 target_stat_values[++index] = cm_packets_bounced;
34531 target_stat_values[++index] = cm_packets_created;
34532 target_stat_values[++index] = cm_packets_received;
34533 target_stat_values[++index] = cm_packets_dropped;
34534 target_stat_values[++index] = cm_packets_retrans;
34535 - target_stat_values[++index] = atomic_read(&cm_listens_created);
34536 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
34537 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
34538 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
34539 target_stat_values[++index] = cm_backlog_drops;
34540 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
34541 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
34542 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
34543 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
34544 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
34545 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
34546 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
34547 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
34548 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
34549 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
34550 target_stat_values[++index] = nesadapter->free_4kpbl;
34551 target_stat_values[++index] = nesadapter->free_256pbl;
34552 target_stat_values[++index] = int_mod_timer_init;
34553 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
34554 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
34555 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
34556 - target_stat_values[++index] = atomic_read(&pau_qps_created);
34557 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
34558 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
34559 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
34560 }
34561
34562 /**
34563 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
34564 index 07e4fba..685f041 100644
34565 --- a/drivers/infiniband/hw/nes/nes_verbs.c
34566 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
34567 @@ -46,9 +46,9 @@
34568
34569 #include <rdma/ib_umem.h>
34570
34571 -atomic_t mod_qp_timouts;
34572 -atomic_t qps_created;
34573 -atomic_t sw_qps_destroyed;
34574 +atomic_unchecked_t mod_qp_timouts;
34575 +atomic_unchecked_t qps_created;
34576 +atomic_unchecked_t sw_qps_destroyed;
34577
34578 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
34579
34580 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
34581 if (init_attr->create_flags)
34582 return ERR_PTR(-EINVAL);
34583
34584 - atomic_inc(&qps_created);
34585 + atomic_inc_unchecked(&qps_created);
34586 switch (init_attr->qp_type) {
34587 case IB_QPT_RC:
34588 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
34589 @@ -1462,7 +1462,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
34590 struct iw_cm_event cm_event;
34591 int ret = 0;
34592
34593 - atomic_inc(&sw_qps_destroyed);
34594 + atomic_inc_unchecked(&sw_qps_destroyed);
34595 nesqp->destroyed = 1;
34596
34597 /* Blow away the connection if it exists. */
34598 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
34599 index 4d11575..3e890e5 100644
34600 --- a/drivers/infiniband/hw/qib/qib.h
34601 +++ b/drivers/infiniband/hw/qib/qib.h
34602 @@ -51,6 +51,7 @@
34603 #include <linux/completion.h>
34604 #include <linux/kref.h>
34605 #include <linux/sched.h>
34606 +#include <linux/slab.h>
34607
34608 #include "qib_common.h"
34609 #include "qib_verbs.h"
34610 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
34611 index da739d9..da1c7f4 100644
34612 --- a/drivers/input/gameport/gameport.c
34613 +++ b/drivers/input/gameport/gameport.c
34614 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
34615 */
34616 static void gameport_init_port(struct gameport *gameport)
34617 {
34618 - static atomic_t gameport_no = ATOMIC_INIT(0);
34619 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
34620
34621 __module_get(THIS_MODULE);
34622
34623 mutex_init(&gameport->drv_mutex);
34624 device_initialize(&gameport->dev);
34625 dev_set_name(&gameport->dev, "gameport%lu",
34626 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
34627 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
34628 gameport->dev.bus = &gameport_bus;
34629 gameport->dev.release = gameport_release_port;
34630 if (gameport->parent)
34631 diff --git a/drivers/input/input.c b/drivers/input/input.c
34632 index 53a0dde..abffda7 100644
34633 --- a/drivers/input/input.c
34634 +++ b/drivers/input/input.c
34635 @@ -1902,7 +1902,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
34636 */
34637 int input_register_device(struct input_dev *dev)
34638 {
34639 - static atomic_t input_no = ATOMIC_INIT(0);
34640 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
34641 struct input_handler *handler;
34642 unsigned int packet_size;
34643 const char *path;
34644 @@ -1945,7 +1945,7 @@ int input_register_device(struct input_dev *dev)
34645 dev->setkeycode = input_default_setkeycode;
34646
34647 dev_set_name(&dev->dev, "input%ld",
34648 - (unsigned long) atomic_inc_return(&input_no) - 1);
34649 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
34650
34651 error = device_add(&dev->dev);
34652 if (error)
34653 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
34654 index 04c69af..5f92d00 100644
34655 --- a/drivers/input/joystick/sidewinder.c
34656 +++ b/drivers/input/joystick/sidewinder.c
34657 @@ -30,6 +30,7 @@
34658 #include <linux/kernel.h>
34659 #include <linux/module.h>
34660 #include <linux/slab.h>
34661 +#include <linux/sched.h>
34662 #include <linux/init.h>
34663 #include <linux/input.h>
34664 #include <linux/gameport.h>
34665 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
34666 index 83811e4..0822b90 100644
34667 --- a/drivers/input/joystick/xpad.c
34668 +++ b/drivers/input/joystick/xpad.c
34669 @@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
34670
34671 static int xpad_led_probe(struct usb_xpad *xpad)
34672 {
34673 - static atomic_t led_seq = ATOMIC_INIT(0);
34674 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
34675 long led_no;
34676 struct xpad_led *led;
34677 struct led_classdev *led_cdev;
34678 @@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
34679 if (!led)
34680 return -ENOMEM;
34681
34682 - led_no = (long)atomic_inc_return(&led_seq) - 1;
34683 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
34684
34685 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
34686 led->xpad = xpad;
34687 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
34688 index 4c842c3..590b0bf 100644
34689 --- a/drivers/input/mousedev.c
34690 +++ b/drivers/input/mousedev.c
34691 @@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
34692
34693 spin_unlock_irq(&client->packet_lock);
34694
34695 - if (copy_to_user(buffer, data, count))
34696 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
34697 return -EFAULT;
34698
34699 return count;
34700 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
34701 index d0f7533..fb8215b 100644
34702 --- a/drivers/input/serio/serio.c
34703 +++ b/drivers/input/serio/serio.c
34704 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
34705 */
34706 static void serio_init_port(struct serio *serio)
34707 {
34708 - static atomic_t serio_no = ATOMIC_INIT(0);
34709 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
34710
34711 __module_get(THIS_MODULE);
34712
34713 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
34714 mutex_init(&serio->drv_mutex);
34715 device_initialize(&serio->dev);
34716 dev_set_name(&serio->dev, "serio%ld",
34717 - (long)atomic_inc_return(&serio_no) - 1);
34718 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
34719 serio->dev.bus = &serio_bus;
34720 serio->dev.release = serio_release_port;
34721 serio->dev.groups = serio_device_attr_groups;
34722 diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
34723 index faf10ba..7cfaba9 100644
34724 --- a/drivers/iommu/amd_iommu_init.c
34725 +++ b/drivers/iommu/amd_iommu_init.c
34726 @@ -1922,7 +1922,7 @@ static int __init state_next(void)
34727 case IOMMU_ACPI_FINISHED:
34728 early_enable_iommus();
34729 register_syscore_ops(&amd_iommu_syscore_ops);
34730 - x86_platform.iommu_shutdown = disable_iommus;
34731 + *(void **)&x86_platform.iommu_shutdown = disable_iommus;
34732 init_state = IOMMU_ENABLED;
34733 break;
34734 case IOMMU_ENABLED:
34735 @@ -2064,7 +2064,7 @@ int __init amd_iommu_detect(void)
34736
34737 amd_iommu_detected = true;
34738 iommu_detected = 1;
34739 - x86_init.iommu.iommu_init = amd_iommu_init;
34740 + *(void **)&x86_init.iommu.iommu_init = amd_iommu_init;
34741
34742 return 0;
34743 }
34744 diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c
34745 index 86e2f4a..d1cec5d 100644
34746 --- a/drivers/iommu/dmar.c
34747 +++ b/drivers/iommu/dmar.c
34748 @@ -555,7 +555,7 @@ int __init detect_intel_iommu(void)
34749
34750 #ifdef CONFIG_X86
34751 if (ret)
34752 - x86_init.iommu.iommu_init = intel_iommu_init;
34753 + *(void **)&x86_init.iommu.iommu_init = intel_iommu_init;
34754 #endif
34755 }
34756 early_acpi_os_unmap_memory(dmar_tbl, dmar_tbl_size);
34757 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
34758 index c679867..6e2e34d 100644
34759 --- a/drivers/isdn/capi/capi.c
34760 +++ b/drivers/isdn/capi/capi.c
34761 @@ -83,8 +83,8 @@ struct capiminor {
34762
34763 struct capi20_appl *ap;
34764 u32 ncci;
34765 - atomic_t datahandle;
34766 - atomic_t msgid;
34767 + atomic_unchecked_t datahandle;
34768 + atomic_unchecked_t msgid;
34769
34770 struct tty_port port;
34771 int ttyinstop;
34772 @@ -393,7 +393,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
34773 capimsg_setu16(s, 2, mp->ap->applid);
34774 capimsg_setu8 (s, 4, CAPI_DATA_B3);
34775 capimsg_setu8 (s, 5, CAPI_RESP);
34776 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
34777 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
34778 capimsg_setu32(s, 8, mp->ncci);
34779 capimsg_setu16(s, 12, datahandle);
34780 }
34781 @@ -514,14 +514,14 @@ static void handle_minor_send(struct capiminor *mp)
34782 mp->outbytes -= len;
34783 spin_unlock_bh(&mp->outlock);
34784
34785 - datahandle = atomic_inc_return(&mp->datahandle);
34786 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
34787 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
34788 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
34789 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
34790 capimsg_setu16(skb->data, 2, mp->ap->applid);
34791 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
34792 capimsg_setu8 (skb->data, 5, CAPI_REQ);
34793 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
34794 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
34795 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
34796 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
34797 capimsg_setu16(skb->data, 16, len); /* Data length */
34798 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
34799 index 67abf3f..076b3a6 100644
34800 --- a/drivers/isdn/gigaset/interface.c
34801 +++ b/drivers/isdn/gigaset/interface.c
34802 @@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
34803 }
34804 tty->driver_data = cs;
34805
34806 - ++cs->port.count;
34807 + atomic_inc(&cs->port.count);
34808
34809 - if (cs->port.count == 1) {
34810 + if (atomic_read(&cs->port.count) == 1) {
34811 tty_port_tty_set(&cs->port, tty);
34812 tty->low_latency = 1;
34813 }
34814 @@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
34815
34816 if (!cs->connected)
34817 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
34818 - else if (!cs->port.count)
34819 + else if (!atomic_read(&cs->port.count))
34820 dev_warn(cs->dev, "%s: device not opened\n", __func__);
34821 - else if (!--cs->port.count)
34822 + else if (!atomic_dec_return(&cs->port.count))
34823 tty_port_tty_set(&cs->port, NULL);
34824
34825 mutex_unlock(&cs->mutex);
34826 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
34827 index 821f7ac..28d4030 100644
34828 --- a/drivers/isdn/hardware/avm/b1.c
34829 +++ b/drivers/isdn/hardware/avm/b1.c
34830 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
34831 }
34832 if (left) {
34833 if (t4file->user) {
34834 - if (copy_from_user(buf, dp, left))
34835 + if (left > sizeof buf || copy_from_user(buf, dp, left))
34836 return -EFAULT;
34837 } else {
34838 memcpy(buf, dp, left);
34839 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
34840 }
34841 if (left) {
34842 if (config->user) {
34843 - if (copy_from_user(buf, dp, left))
34844 + if (left > sizeof buf || copy_from_user(buf, dp, left))
34845 return -EFAULT;
34846 } else {
34847 memcpy(buf, dp, left);
34848 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
34849 index b817809..409caff 100644
34850 --- a/drivers/isdn/i4l/isdn_tty.c
34851 +++ b/drivers/isdn/i4l/isdn_tty.c
34852 @@ -1513,9 +1513,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
34853
34854 #ifdef ISDN_DEBUG_MODEM_OPEN
34855 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
34856 - port->count);
34857 + atomic_read(&port->count));
34858 #endif
34859 - port->count++;
34860 + atomic_inc(&port->count);
34861 port->tty = tty;
34862 /*
34863 * Start up serial port
34864 @@ -1559,7 +1559,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
34865 #endif
34866 return;
34867 }
34868 - if ((tty->count == 1) && (port->count != 1)) {
34869 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
34870 /*
34871 * Uh, oh. tty->count is 1, which means that the tty
34872 * structure will be freed. Info->count should always
34873 @@ -1568,15 +1568,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
34874 * serial port won't be shutdown.
34875 */
34876 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
34877 - "info->count is %d\n", port->count);
34878 - port->count = 1;
34879 + "info->count is %d\n", atomic_read(&port->count));
34880 + atomic_set(&port->count, 1);
34881 }
34882 - if (--port->count < 0) {
34883 + if (atomic_dec_return(&port->count) < 0) {
34884 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
34885 - info->line, port->count);
34886 - port->count = 0;
34887 + info->line, atomic_read(&port->count));
34888 + atomic_set(&port->count, 0);
34889 }
34890 - if (port->count) {
34891 + if (atomic_read(&port->count)) {
34892 #ifdef ISDN_DEBUG_MODEM_OPEN
34893 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
34894 #endif
34895 @@ -1630,7 +1630,7 @@ isdn_tty_hangup(struct tty_struct *tty)
34896 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
34897 return;
34898 isdn_tty_shutdown(info);
34899 - port->count = 0;
34900 + atomic_set(&port->count, 0);
34901 port->flags &= ~ASYNC_NORMAL_ACTIVE;
34902 port->tty = NULL;
34903 wake_up_interruptible(&port->open_wait);
34904 @@ -1971,7 +1971,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
34905 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
34906 modem_info *info = &dev->mdm.info[i];
34907
34908 - if (info->port.count == 0)
34909 + if (atomic_read(&info->port.count) == 0)
34910 continue;
34911 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
34912 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
34913 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
34914 index e74df7c..03a03ba 100644
34915 --- a/drivers/isdn/icn/icn.c
34916 +++ b/drivers/isdn/icn/icn.c
34917 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
34918 if (count > len)
34919 count = len;
34920 if (user) {
34921 - if (copy_from_user(msg, buf, count))
34922 + if (count > sizeof msg || copy_from_user(msg, buf, count))
34923 return -EFAULT;
34924 } else
34925 memcpy(msg, buf, count);
34926 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
34927 index b5fdcb7..5b6c59f 100644
34928 --- a/drivers/lguest/core.c
34929 +++ b/drivers/lguest/core.c
34930 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
34931 * it's worked so far. The end address needs +1 because __get_vm_area
34932 * allocates an extra guard page, so we need space for that.
34933 */
34934 +
34935 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
34936 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
34937 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
34938 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
34939 +#else
34940 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
34941 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
34942 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
34943 +#endif
34944 +
34945 if (!switcher_vma) {
34946 err = -ENOMEM;
34947 printk("lguest: could not map switcher pages high\n");
34948 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
34949 * Now the Switcher is mapped at the right address, we can't fail!
34950 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
34951 */
34952 - memcpy(switcher_vma->addr, start_switcher_text,
34953 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
34954 end_switcher_text - start_switcher_text);
34955
34956 printk(KERN_INFO "lguest: mapped switcher at %p\n",
34957 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
34958 index 4af12e1..0e89afe 100644
34959 --- a/drivers/lguest/x86/core.c
34960 +++ b/drivers/lguest/x86/core.c
34961 @@ -59,7 +59,7 @@ static struct {
34962 /* Offset from where switcher.S was compiled to where we've copied it */
34963 static unsigned long switcher_offset(void)
34964 {
34965 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
34966 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
34967 }
34968
34969 /* This cpu's struct lguest_pages. */
34970 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
34971 * These copies are pretty cheap, so we do them unconditionally: */
34972 /* Save the current Host top-level page directory.
34973 */
34974 +
34975 +#ifdef CONFIG_PAX_PER_CPU_PGD
34976 + pages->state.host_cr3 = read_cr3();
34977 +#else
34978 pages->state.host_cr3 = __pa(current->mm->pgd);
34979 +#endif
34980 +
34981 /*
34982 * Set up the Guest's page tables to see this CPU's pages (and no
34983 * other CPU's pages).
34984 @@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
34985 * compiled-in switcher code and the high-mapped copy we just made.
34986 */
34987 for (i = 0; i < IDT_ENTRIES; i++)
34988 - default_idt_entries[i] += switcher_offset();
34989 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
34990
34991 /*
34992 * Set up the Switcher's per-cpu areas.
34993 @@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
34994 * it will be undisturbed when we switch. To change %cs and jump we
34995 * need this structure to feed to Intel's "lcall" instruction.
34996 */
34997 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
34998 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
34999 lguest_entry.segment = LGUEST_CS;
35000
35001 /*
35002 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
35003 index 40634b0..4f5855e 100644
35004 --- a/drivers/lguest/x86/switcher_32.S
35005 +++ b/drivers/lguest/x86/switcher_32.S
35006 @@ -87,6 +87,7 @@
35007 #include <asm/page.h>
35008 #include <asm/segment.h>
35009 #include <asm/lguest.h>
35010 +#include <asm/processor-flags.h>
35011
35012 // We mark the start of the code to copy
35013 // It's placed in .text tho it's never run here
35014 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
35015 // Changes type when we load it: damn Intel!
35016 // For after we switch over our page tables
35017 // That entry will be read-only: we'd crash.
35018 +
35019 +#ifdef CONFIG_PAX_KERNEXEC
35020 + mov %cr0, %edx
35021 + xor $X86_CR0_WP, %edx
35022 + mov %edx, %cr0
35023 +#endif
35024 +
35025 movl $(GDT_ENTRY_TSS*8), %edx
35026 ltr %dx
35027
35028 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
35029 // Let's clear it again for our return.
35030 // The GDT descriptor of the Host
35031 // Points to the table after two "size" bytes
35032 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
35033 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
35034 // Clear "used" from type field (byte 5, bit 2)
35035 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
35036 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
35037 +
35038 +#ifdef CONFIG_PAX_KERNEXEC
35039 + mov %cr0, %eax
35040 + xor $X86_CR0_WP, %eax
35041 + mov %eax, %cr0
35042 +#endif
35043
35044 // Once our page table's switched, the Guest is live!
35045 // The Host fades as we run this final step.
35046 @@ -295,13 +309,12 @@ deliver_to_host:
35047 // I consulted gcc, and it gave
35048 // These instructions, which I gladly credit:
35049 leal (%edx,%ebx,8), %eax
35050 - movzwl (%eax),%edx
35051 - movl 4(%eax), %eax
35052 - xorw %ax, %ax
35053 - orl %eax, %edx
35054 + movl 4(%eax), %edx
35055 + movw (%eax), %dx
35056 // Now the address of the handler's in %edx
35057 // We call it now: its "iret" drops us home.
35058 - jmp *%edx
35059 + ljmp $__KERNEL_CS, $1f
35060 +1: jmp *%edx
35061
35062 // Every interrupt can come to us here
35063 // But we must truly tell each apart.
35064 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
35065 index 7155945..4bcc562 100644
35066 --- a/drivers/md/bitmap.c
35067 +++ b/drivers/md/bitmap.c
35068 @@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
35069 chunk_kb ? "KB" : "B");
35070 if (bitmap->storage.file) {
35071 seq_printf(seq, ", file: ");
35072 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
35073 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
35074 }
35075
35076 seq_printf(seq, "\n");
35077 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
35078 index a651d52..82f8a95 100644
35079 --- a/drivers/md/dm-ioctl.c
35080 +++ b/drivers/md/dm-ioctl.c
35081 @@ -1601,7 +1601,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
35082 cmd == DM_LIST_VERSIONS_CMD)
35083 return 0;
35084
35085 - if ((cmd == DM_DEV_CREATE_CMD)) {
35086 + if (cmd == DM_DEV_CREATE_CMD) {
35087 if (!*param->name) {
35088 DMWARN("name not supplied when creating device");
35089 return -EINVAL;
35090 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
35091 index fd61f98..8050783 100644
35092 --- a/drivers/md/dm-raid1.c
35093 +++ b/drivers/md/dm-raid1.c
35094 @@ -40,7 +40,7 @@ enum dm_raid1_error {
35095
35096 struct mirror {
35097 struct mirror_set *ms;
35098 - atomic_t error_count;
35099 + atomic_unchecked_t error_count;
35100 unsigned long error_type;
35101 struct dm_dev *dev;
35102 sector_t offset;
35103 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
35104 struct mirror *m;
35105
35106 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
35107 - if (!atomic_read(&m->error_count))
35108 + if (!atomic_read_unchecked(&m->error_count))
35109 return m;
35110
35111 return NULL;
35112 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
35113 * simple way to tell if a device has encountered
35114 * errors.
35115 */
35116 - atomic_inc(&m->error_count);
35117 + atomic_inc_unchecked(&m->error_count);
35118
35119 if (test_and_set_bit(error_type, &m->error_type))
35120 return;
35121 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
35122 struct mirror *m = get_default_mirror(ms);
35123
35124 do {
35125 - if (likely(!atomic_read(&m->error_count)))
35126 + if (likely(!atomic_read_unchecked(&m->error_count)))
35127 return m;
35128
35129 if (m-- == ms->mirror)
35130 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
35131 {
35132 struct mirror *default_mirror = get_default_mirror(m->ms);
35133
35134 - return !atomic_read(&default_mirror->error_count);
35135 + return !atomic_read_unchecked(&default_mirror->error_count);
35136 }
35137
35138 static int mirror_available(struct mirror_set *ms, struct bio *bio)
35139 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
35140 */
35141 if (likely(region_in_sync(ms, region, 1)))
35142 m = choose_mirror(ms, bio->bi_sector);
35143 - else if (m && atomic_read(&m->error_count))
35144 + else if (m && atomic_read_unchecked(&m->error_count))
35145 m = NULL;
35146
35147 if (likely(m))
35148 @@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
35149 }
35150
35151 ms->mirror[mirror].ms = ms;
35152 - atomic_set(&(ms->mirror[mirror].error_count), 0);
35153 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
35154 ms->mirror[mirror].error_type = 0;
35155 ms->mirror[mirror].offset = offset;
35156
35157 @@ -1356,7 +1356,7 @@ static void mirror_resume(struct dm_target *ti)
35158 */
35159 static char device_status_char(struct mirror *m)
35160 {
35161 - if (!atomic_read(&(m->error_count)))
35162 + if (!atomic_read_unchecked(&(m->error_count)))
35163 return 'A';
35164
35165 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
35166 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
35167 index e2f87653..f279abe 100644
35168 --- a/drivers/md/dm-stripe.c
35169 +++ b/drivers/md/dm-stripe.c
35170 @@ -20,7 +20,7 @@ struct stripe {
35171 struct dm_dev *dev;
35172 sector_t physical_start;
35173
35174 - atomic_t error_count;
35175 + atomic_unchecked_t error_count;
35176 };
35177
35178 struct stripe_c {
35179 @@ -183,7 +183,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
35180 kfree(sc);
35181 return r;
35182 }
35183 - atomic_set(&(sc->stripe[i].error_count), 0);
35184 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
35185 }
35186
35187 ti->private = sc;
35188 @@ -324,7 +324,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
35189 DMEMIT("%d ", sc->stripes);
35190 for (i = 0; i < sc->stripes; i++) {
35191 DMEMIT("%s ", sc->stripe[i].dev->name);
35192 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
35193 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
35194 'D' : 'A';
35195 }
35196 buffer[i] = '\0';
35197 @@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
35198 */
35199 for (i = 0; i < sc->stripes; i++)
35200 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
35201 - atomic_inc(&(sc->stripe[i].error_count));
35202 - if (atomic_read(&(sc->stripe[i].error_count)) <
35203 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
35204 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
35205 DM_IO_ERROR_THRESHOLD)
35206 schedule_work(&sc->trigger_event);
35207 }
35208 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
35209 index fa29557..d24a5b7 100644
35210 --- a/drivers/md/dm-table.c
35211 +++ b/drivers/md/dm-table.c
35212 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
35213 if (!dev_size)
35214 return 0;
35215
35216 - if ((start >= dev_size) || (start + len > dev_size)) {
35217 + if ((start >= dev_size) || (len > dev_size - start)) {
35218 DMWARN("%s: %s too small for target: "
35219 "start=%llu, len=%llu, dev_size=%llu",
35220 dm_device_name(ti->table->md), bdevname(bdev, b),
35221 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
35222 index 693e149..b7e0fde 100644
35223 --- a/drivers/md/dm-thin-metadata.c
35224 +++ b/drivers/md/dm-thin-metadata.c
35225 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
35226 {
35227 pmd->info.tm = pmd->tm;
35228 pmd->info.levels = 2;
35229 - pmd->info.value_type.context = pmd->data_sm;
35230 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
35231 pmd->info.value_type.size = sizeof(__le64);
35232 pmd->info.value_type.inc = data_block_inc;
35233 pmd->info.value_type.dec = data_block_dec;
35234 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
35235
35236 pmd->bl_info.tm = pmd->tm;
35237 pmd->bl_info.levels = 1;
35238 - pmd->bl_info.value_type.context = pmd->data_sm;
35239 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
35240 pmd->bl_info.value_type.size = sizeof(__le64);
35241 pmd->bl_info.value_type.inc = data_block_inc;
35242 pmd->bl_info.value_type.dec = data_block_dec;
35243 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
35244 index 77e6eff..913d695 100644
35245 --- a/drivers/md/dm.c
35246 +++ b/drivers/md/dm.c
35247 @@ -182,9 +182,9 @@ struct mapped_device {
35248 /*
35249 * Event handling.
35250 */
35251 - atomic_t event_nr;
35252 + atomic_unchecked_t event_nr;
35253 wait_queue_head_t eventq;
35254 - atomic_t uevent_seq;
35255 + atomic_unchecked_t uevent_seq;
35256 struct list_head uevent_list;
35257 spinlock_t uevent_lock; /* Protect access to uevent_list */
35258
35259 @@ -1847,8 +1847,8 @@ static struct mapped_device *alloc_dev(int minor)
35260 rwlock_init(&md->map_lock);
35261 atomic_set(&md->holders, 1);
35262 atomic_set(&md->open_count, 0);
35263 - atomic_set(&md->event_nr, 0);
35264 - atomic_set(&md->uevent_seq, 0);
35265 + atomic_set_unchecked(&md->event_nr, 0);
35266 + atomic_set_unchecked(&md->uevent_seq, 0);
35267 INIT_LIST_HEAD(&md->uevent_list);
35268 spin_lock_init(&md->uevent_lock);
35269
35270 @@ -1982,7 +1982,7 @@ static void event_callback(void *context)
35271
35272 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
35273
35274 - atomic_inc(&md->event_nr);
35275 + atomic_inc_unchecked(&md->event_nr);
35276 wake_up(&md->eventq);
35277 }
35278
35279 @@ -2637,18 +2637,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
35280
35281 uint32_t dm_next_uevent_seq(struct mapped_device *md)
35282 {
35283 - return atomic_add_return(1, &md->uevent_seq);
35284 + return atomic_add_return_unchecked(1, &md->uevent_seq);
35285 }
35286
35287 uint32_t dm_get_event_nr(struct mapped_device *md)
35288 {
35289 - return atomic_read(&md->event_nr);
35290 + return atomic_read_unchecked(&md->event_nr);
35291 }
35292
35293 int dm_wait_event(struct mapped_device *md, int event_nr)
35294 {
35295 return wait_event_interruptible(md->eventq,
35296 - (event_nr != atomic_read(&md->event_nr)));
35297 + (event_nr != atomic_read_unchecked(&md->event_nr)));
35298 }
35299
35300 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
35301 diff --git a/drivers/md/md.c b/drivers/md/md.c
35302 index 6120071..31d9be2 100644
35303 --- a/drivers/md/md.c
35304 +++ b/drivers/md/md.c
35305 @@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
35306 * start build, activate spare
35307 */
35308 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
35309 -static atomic_t md_event_count;
35310 +static atomic_unchecked_t md_event_count;
35311 void md_new_event(struct mddev *mddev)
35312 {
35313 - atomic_inc(&md_event_count);
35314 + atomic_inc_unchecked(&md_event_count);
35315 wake_up(&md_event_waiters);
35316 }
35317 EXPORT_SYMBOL_GPL(md_new_event);
35318 @@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
35319 */
35320 static void md_new_event_inintr(struct mddev *mddev)
35321 {
35322 - atomic_inc(&md_event_count);
35323 + atomic_inc_unchecked(&md_event_count);
35324 wake_up(&md_event_waiters);
35325 }
35326
35327 @@ -1504,7 +1504,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
35328 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
35329 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
35330 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
35331 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
35332 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
35333
35334 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
35335 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
35336 @@ -1748,7 +1748,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
35337 else
35338 sb->resync_offset = cpu_to_le64(0);
35339
35340 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
35341 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
35342
35343 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
35344 sb->size = cpu_to_le64(mddev->dev_sectors);
35345 @@ -2748,7 +2748,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
35346 static ssize_t
35347 errors_show(struct md_rdev *rdev, char *page)
35348 {
35349 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
35350 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
35351 }
35352
35353 static ssize_t
35354 @@ -2757,7 +2757,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
35355 char *e;
35356 unsigned long n = simple_strtoul(buf, &e, 10);
35357 if (*buf && (*e == 0 || *e == '\n')) {
35358 - atomic_set(&rdev->corrected_errors, n);
35359 + atomic_set_unchecked(&rdev->corrected_errors, n);
35360 return len;
35361 }
35362 return -EINVAL;
35363 @@ -3204,8 +3204,8 @@ int md_rdev_init(struct md_rdev *rdev)
35364 rdev->sb_loaded = 0;
35365 rdev->bb_page = NULL;
35366 atomic_set(&rdev->nr_pending, 0);
35367 - atomic_set(&rdev->read_errors, 0);
35368 - atomic_set(&rdev->corrected_errors, 0);
35369 + atomic_set_unchecked(&rdev->read_errors, 0);
35370 + atomic_set_unchecked(&rdev->corrected_errors, 0);
35371
35372 INIT_LIST_HEAD(&rdev->same_set);
35373 init_waitqueue_head(&rdev->blocked_wait);
35374 @@ -6984,7 +6984,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
35375
35376 spin_unlock(&pers_lock);
35377 seq_printf(seq, "\n");
35378 - seq->poll_event = atomic_read(&md_event_count);
35379 + seq->poll_event = atomic_read_unchecked(&md_event_count);
35380 return 0;
35381 }
35382 if (v == (void*)2) {
35383 @@ -7087,7 +7087,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
35384 return error;
35385
35386 seq = file->private_data;
35387 - seq->poll_event = atomic_read(&md_event_count);
35388 + seq->poll_event = atomic_read_unchecked(&md_event_count);
35389 return error;
35390 }
35391
35392 @@ -7101,7 +7101,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
35393 /* always allow read */
35394 mask = POLLIN | POLLRDNORM;
35395
35396 - if (seq->poll_event != atomic_read(&md_event_count))
35397 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
35398 mask |= POLLERR | POLLPRI;
35399 return mask;
35400 }
35401 @@ -7145,7 +7145,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
35402 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
35403 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
35404 (int)part_stat_read(&disk->part0, sectors[1]) -
35405 - atomic_read(&disk->sync_io);
35406 + atomic_read_unchecked(&disk->sync_io);
35407 /* sync IO will cause sync_io to increase before the disk_stats
35408 * as sync_io is counted when a request starts, and
35409 * disk_stats is counted when it completes.
35410 diff --git a/drivers/md/md.h b/drivers/md/md.h
35411 index af443ab..0f93be3 100644
35412 --- a/drivers/md/md.h
35413 +++ b/drivers/md/md.h
35414 @@ -94,13 +94,13 @@ struct md_rdev {
35415 * only maintained for arrays that
35416 * support hot removal
35417 */
35418 - atomic_t read_errors; /* number of consecutive read errors that
35419 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
35420 * we have tried to ignore.
35421 */
35422 struct timespec last_read_error; /* monotonic time since our
35423 * last read error
35424 */
35425 - atomic_t corrected_errors; /* number of corrected read errors,
35426 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
35427 * for reporting to userspace and storing
35428 * in superblock.
35429 */
35430 @@ -432,7 +432,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
35431
35432 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
35433 {
35434 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
35435 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
35436 }
35437
35438 struct md_personality
35439 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
35440 index 1cbfc6b..56e1dbb 100644
35441 --- a/drivers/md/persistent-data/dm-space-map.h
35442 +++ b/drivers/md/persistent-data/dm-space-map.h
35443 @@ -60,6 +60,7 @@ struct dm_space_map {
35444 int (*root_size)(struct dm_space_map *sm, size_t *result);
35445 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
35446 };
35447 +typedef struct dm_space_map __no_const dm_space_map_no_const;
35448
35449 /*----------------------------------------------------------------*/
35450
35451 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
35452 index a0f7309..5599dbc 100644
35453 --- a/drivers/md/raid1.c
35454 +++ b/drivers/md/raid1.c
35455 @@ -1819,7 +1819,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
35456 if (r1_sync_page_io(rdev, sect, s,
35457 bio->bi_io_vec[idx].bv_page,
35458 READ) != 0)
35459 - atomic_add(s, &rdev->corrected_errors);
35460 + atomic_add_unchecked(s, &rdev->corrected_errors);
35461 }
35462 sectors -= s;
35463 sect += s;
35464 @@ -2041,7 +2041,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
35465 test_bit(In_sync, &rdev->flags)) {
35466 if (r1_sync_page_io(rdev, sect, s,
35467 conf->tmppage, READ)) {
35468 - atomic_add(s, &rdev->corrected_errors);
35469 + atomic_add_unchecked(s, &rdev->corrected_errors);
35470 printk(KERN_INFO
35471 "md/raid1:%s: read error corrected "
35472 "(%d sectors at %llu on %s)\n",
35473 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
35474 index c9acbd7..386cd3e 100644
35475 --- a/drivers/md/raid10.c
35476 +++ b/drivers/md/raid10.c
35477 @@ -1878,7 +1878,7 @@ static void end_sync_read(struct bio *bio, int error)
35478 /* The write handler will notice the lack of
35479 * R10BIO_Uptodate and record any errors etc
35480 */
35481 - atomic_add(r10_bio->sectors,
35482 + atomic_add_unchecked(r10_bio->sectors,
35483 &conf->mirrors[d].rdev->corrected_errors);
35484
35485 /* for reconstruct, we always reschedule after a read.
35486 @@ -2227,7 +2227,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
35487 {
35488 struct timespec cur_time_mon;
35489 unsigned long hours_since_last;
35490 - unsigned int read_errors = atomic_read(&rdev->read_errors);
35491 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
35492
35493 ktime_get_ts(&cur_time_mon);
35494
35495 @@ -2249,9 +2249,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
35496 * overflowing the shift of read_errors by hours_since_last.
35497 */
35498 if (hours_since_last >= 8 * sizeof(read_errors))
35499 - atomic_set(&rdev->read_errors, 0);
35500 + atomic_set_unchecked(&rdev->read_errors, 0);
35501 else
35502 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
35503 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
35504 }
35505
35506 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
35507 @@ -2305,8 +2305,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
35508 return;
35509
35510 check_decay_read_errors(mddev, rdev);
35511 - atomic_inc(&rdev->read_errors);
35512 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
35513 + atomic_inc_unchecked(&rdev->read_errors);
35514 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
35515 char b[BDEVNAME_SIZE];
35516 bdevname(rdev->bdev, b);
35517
35518 @@ -2314,7 +2314,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
35519 "md/raid10:%s: %s: Raid device exceeded "
35520 "read_error threshold [cur %d:max %d]\n",
35521 mdname(mddev), b,
35522 - atomic_read(&rdev->read_errors), max_read_errors);
35523 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
35524 printk(KERN_NOTICE
35525 "md/raid10:%s: %s: Failing raid device\n",
35526 mdname(mddev), b);
35527 @@ -2469,7 +2469,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
35528 sect +
35529 choose_data_offset(r10_bio, rdev)),
35530 bdevname(rdev->bdev, b));
35531 - atomic_add(s, &rdev->corrected_errors);
35532 + atomic_add_unchecked(s, &rdev->corrected_errors);
35533 }
35534
35535 rdev_dec_pending(rdev, mddev);
35536 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
35537 index a450268..c4168a9 100644
35538 --- a/drivers/md/raid5.c
35539 +++ b/drivers/md/raid5.c
35540 @@ -1789,21 +1789,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
35541 mdname(conf->mddev), STRIPE_SECTORS,
35542 (unsigned long long)s,
35543 bdevname(rdev->bdev, b));
35544 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
35545 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
35546 clear_bit(R5_ReadError, &sh->dev[i].flags);
35547 clear_bit(R5_ReWrite, &sh->dev[i].flags);
35548 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
35549 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
35550
35551 - if (atomic_read(&rdev->read_errors))
35552 - atomic_set(&rdev->read_errors, 0);
35553 + if (atomic_read_unchecked(&rdev->read_errors))
35554 + atomic_set_unchecked(&rdev->read_errors, 0);
35555 } else {
35556 const char *bdn = bdevname(rdev->bdev, b);
35557 int retry = 0;
35558 int set_bad = 0;
35559
35560 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
35561 - atomic_inc(&rdev->read_errors);
35562 + atomic_inc_unchecked(&rdev->read_errors);
35563 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
35564 printk_ratelimited(
35565 KERN_WARNING
35566 @@ -1831,7 +1831,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
35567 mdname(conf->mddev),
35568 (unsigned long long)s,
35569 bdn);
35570 - } else if (atomic_read(&rdev->read_errors)
35571 + } else if (atomic_read_unchecked(&rdev->read_errors)
35572 > conf->max_nr_stripes)
35573 printk(KERN_WARNING
35574 "md/raid:%s: Too many read errors, failing device %s.\n",
35575 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
35576 index d33101a..6b13069 100644
35577 --- a/drivers/media/dvb-core/dvbdev.c
35578 +++ b/drivers/media/dvb-core/dvbdev.c
35579 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
35580 const struct dvb_device *template, void *priv, int type)
35581 {
35582 struct dvb_device *dvbdev;
35583 - struct file_operations *dvbdevfops;
35584 + file_operations_no_const *dvbdevfops;
35585 struct device *clsdev;
35586 int minor;
35587 int id;
35588 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
35589 index 404f63a..4796533 100644
35590 --- a/drivers/media/dvb-frontends/dib3000.h
35591 +++ b/drivers/media/dvb-frontends/dib3000.h
35592 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
35593 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
35594 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
35595 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
35596 -};
35597 +} __no_const;
35598
35599 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
35600 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
35601 diff --git a/drivers/media/pci/cx88/cx88-alsa.c b/drivers/media/pci/cx88/cx88-alsa.c
35602 index 3aa6856..435ad25 100644
35603 --- a/drivers/media/pci/cx88/cx88-alsa.c
35604 +++ b/drivers/media/pci/cx88/cx88-alsa.c
35605 @@ -749,7 +749,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
35606 * Only boards with eeprom and byte 1 at eeprom=1 have it
35607 */
35608
35609 -static const struct pci_device_id cx88_audio_pci_tbl[] __devinitdata = {
35610 +static const struct pci_device_id cx88_audio_pci_tbl[] __devinitconst = {
35611 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
35612 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
35613 {0, }
35614 diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c b/drivers/media/pci/ddbridge/ddbridge-core.c
35615 index feff57e..66a2c67 100644
35616 --- a/drivers/media/pci/ddbridge/ddbridge-core.c
35617 +++ b/drivers/media/pci/ddbridge/ddbridge-core.c
35618 @@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
35619 .subvendor = _subvend, .subdevice = _subdev, \
35620 .driver_data = (unsigned long)&_driverdata }
35621
35622 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
35623 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
35624 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
35625 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
35626 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
35627 diff --git a/drivers/media/pci/ngene/ngene-cards.c b/drivers/media/pci/ngene/ngene-cards.c
35628 index 96a13ed..6df45b4 100644
35629 --- a/drivers/media/pci/ngene/ngene-cards.c
35630 +++ b/drivers/media/pci/ngene/ngene-cards.c
35631 @@ -741,7 +741,7 @@ static struct ngene_info ngene_info_terratec = {
35632
35633 /****************************************************************************/
35634
35635 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
35636 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
35637 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
35638 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
35639 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
35640 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
35641 index a3b1a34..71ce0e3 100644
35642 --- a/drivers/media/platform/omap/omap_vout.c
35643 +++ b/drivers/media/platform/omap/omap_vout.c
35644 @@ -65,7 +65,6 @@ enum omap_vout_channels {
35645 OMAP_VIDEO2,
35646 };
35647
35648 -static struct videobuf_queue_ops video_vbq_ops;
35649 /* Variables configurable through module params*/
35650 static u32 video1_numbuffers = 3;
35651 static u32 video2_numbuffers = 3;
35652 @@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
35653 {
35654 struct videobuf_queue *q;
35655 struct omap_vout_device *vout = NULL;
35656 + static struct videobuf_queue_ops video_vbq_ops = {
35657 + .buf_setup = omap_vout_buffer_setup,
35658 + .buf_prepare = omap_vout_buffer_prepare,
35659 + .buf_release = omap_vout_buffer_release,
35660 + .buf_queue = omap_vout_buffer_queue,
35661 + };
35662
35663 vout = video_drvdata(file);
35664 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
35665 @@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
35666 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
35667
35668 q = &vout->vbq;
35669 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
35670 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
35671 - video_vbq_ops.buf_release = omap_vout_buffer_release;
35672 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
35673 spin_lock_init(&vout->vbq_lock);
35674
35675 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
35676 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
35677 index ddb422e..8cf008e 100644
35678 --- a/drivers/media/platform/s5p-tv/mixer.h
35679 +++ b/drivers/media/platform/s5p-tv/mixer.h
35680 @@ -155,7 +155,7 @@ struct mxr_layer {
35681 /** layer index (unique identifier) */
35682 int idx;
35683 /** callbacks for layer methods */
35684 - struct mxr_layer_ops ops;
35685 + struct mxr_layer_ops *ops;
35686 /** format array */
35687 const struct mxr_format **fmt_array;
35688 /** size of format array */
35689 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
35690 index b93a21f..2535195 100644
35691 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
35692 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
35693 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
35694 {
35695 struct mxr_layer *layer;
35696 int ret;
35697 - struct mxr_layer_ops ops = {
35698 + static struct mxr_layer_ops ops = {
35699 .release = mxr_graph_layer_release,
35700 .buffer_set = mxr_graph_buffer_set,
35701 .stream_set = mxr_graph_stream_set,
35702 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
35703 index 3b1670a..595c939 100644
35704 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
35705 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
35706 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
35707 layer->update_buf = next;
35708 }
35709
35710 - layer->ops.buffer_set(layer, layer->update_buf);
35711 + layer->ops->buffer_set(layer, layer->update_buf);
35712
35713 if (done && done != layer->shadow_buf)
35714 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
35715 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
35716 index 0c1cd89..6574647 100644
35717 --- a/drivers/media/platform/s5p-tv/mixer_video.c
35718 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
35719 @@ -209,7 +209,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
35720 layer->geo.src.height = layer->geo.src.full_height;
35721
35722 mxr_geometry_dump(mdev, &layer->geo);
35723 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
35724 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
35725 mxr_geometry_dump(mdev, &layer->geo);
35726 }
35727
35728 @@ -227,7 +227,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
35729 layer->geo.dst.full_width = mbus_fmt.width;
35730 layer->geo.dst.full_height = mbus_fmt.height;
35731 layer->geo.dst.field = mbus_fmt.field;
35732 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
35733 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
35734
35735 mxr_geometry_dump(mdev, &layer->geo);
35736 }
35737 @@ -333,7 +333,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
35738 /* set source size to highest accepted value */
35739 geo->src.full_width = max(geo->dst.full_width, pix->width);
35740 geo->src.full_height = max(geo->dst.full_height, pix->height);
35741 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
35742 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
35743 mxr_geometry_dump(mdev, &layer->geo);
35744 /* set cropping to total visible screen */
35745 geo->src.width = pix->width;
35746 @@ -341,12 +341,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
35747 geo->src.x_offset = 0;
35748 geo->src.y_offset = 0;
35749 /* assure consistency of geometry */
35750 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
35751 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
35752 mxr_geometry_dump(mdev, &layer->geo);
35753 /* set full size to lowest possible value */
35754 geo->src.full_width = 0;
35755 geo->src.full_height = 0;
35756 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
35757 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
35758 mxr_geometry_dump(mdev, &layer->geo);
35759
35760 /* returning results */
35761 @@ -473,7 +473,7 @@ static int mxr_s_selection(struct file *file, void *fh,
35762 target->width = s->r.width;
35763 target->height = s->r.height;
35764
35765 - layer->ops.fix_geometry(layer, stage, s->flags);
35766 + layer->ops->fix_geometry(layer, stage, s->flags);
35767
35768 /* retrieve update selection rectangle */
35769 res.left = target->x_offset;
35770 @@ -928,13 +928,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
35771 mxr_output_get(mdev);
35772
35773 mxr_layer_update_output(layer);
35774 - layer->ops.format_set(layer);
35775 + layer->ops->format_set(layer);
35776 /* enabling layer in hardware */
35777 spin_lock_irqsave(&layer->enq_slock, flags);
35778 layer->state = MXR_LAYER_STREAMING;
35779 spin_unlock_irqrestore(&layer->enq_slock, flags);
35780
35781 - layer->ops.stream_set(layer, MXR_ENABLE);
35782 + layer->ops->stream_set(layer, MXR_ENABLE);
35783 mxr_streamer_get(mdev);
35784
35785 return 0;
35786 @@ -1004,7 +1004,7 @@ static int stop_streaming(struct vb2_queue *vq)
35787 spin_unlock_irqrestore(&layer->enq_slock, flags);
35788
35789 /* disabling layer in hardware */
35790 - layer->ops.stream_set(layer, MXR_DISABLE);
35791 + layer->ops->stream_set(layer, MXR_DISABLE);
35792 /* remove one streamer */
35793 mxr_streamer_put(mdev);
35794 /* allow changes in output configuration */
35795 @@ -1043,8 +1043,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
35796
35797 void mxr_layer_release(struct mxr_layer *layer)
35798 {
35799 - if (layer->ops.release)
35800 - layer->ops.release(layer);
35801 + if (layer->ops->release)
35802 + layer->ops->release(layer);
35803 }
35804
35805 void mxr_base_layer_release(struct mxr_layer *layer)
35806 @@ -1070,7 +1070,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
35807
35808 layer->mdev = mdev;
35809 layer->idx = idx;
35810 - layer->ops = *ops;
35811 + layer->ops = ops;
35812
35813 spin_lock_init(&layer->enq_slock);
35814 INIT_LIST_HEAD(&layer->enq_list);
35815 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
35816 index 3d13a63..da31bf1 100644
35817 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
35818 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
35819 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
35820 {
35821 struct mxr_layer *layer;
35822 int ret;
35823 - struct mxr_layer_ops ops = {
35824 + static struct mxr_layer_ops ops = {
35825 .release = mxr_vp_layer_release,
35826 .buffer_set = mxr_vp_buffer_set,
35827 .stream_set = mxr_vp_stream_set,
35828 diff --git a/drivers/media/platform/timblogiw.c b/drivers/media/platform/timblogiw.c
35829 index 02194c0..36d69c1 100644
35830 --- a/drivers/media/platform/timblogiw.c
35831 +++ b/drivers/media/platform/timblogiw.c
35832 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
35833
35834 /* Platform device functions */
35835
35836 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
35837 +static struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
35838 .vidioc_querycap = timblogiw_querycap,
35839 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
35840 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
35841 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
35842 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
35843 };
35844
35845 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
35846 +static struct v4l2_file_operations timblogiw_fops = {
35847 .owner = THIS_MODULE,
35848 .open = timblogiw_open,
35849 .release = timblogiw_close,
35850 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
35851 index 697a421..16c5a5f 100644
35852 --- a/drivers/media/radio/radio-cadet.c
35853 +++ b/drivers/media/radio/radio-cadet.c
35854 @@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
35855 unsigned char readbuf[RDS_BUFFER];
35856 int i = 0;
35857
35858 + if (count > RDS_BUFFER)
35859 + return -EFAULT;
35860 mutex_lock(&dev->lock);
35861 if (dev->rdsstat == 0)
35862 cadet_start_rds(dev);
35863 @@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
35864 while (i < count && dev->rdsin != dev->rdsout)
35865 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
35866
35867 - if (i && copy_to_user(data, readbuf, i))
35868 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
35869 i = -EFAULT;
35870 unlock:
35871 mutex_unlock(&dev->lock);
35872 diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
35873 index 3940bb0..fb3952a 100644
35874 --- a/drivers/media/usb/dvb-usb/cxusb.c
35875 +++ b/drivers/media/usb/dvb-usb/cxusb.c
35876 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
35877
35878 struct dib0700_adapter_state {
35879 int (*set_param_save) (struct dvb_frontend *);
35880 -};
35881 +} __no_const;
35882
35883 static int dib7070_set_param_override(struct dvb_frontend *fe)
35884 {
35885 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
35886 index 9382895..ac8093c 100644
35887 --- a/drivers/media/usb/dvb-usb/dw2102.c
35888 +++ b/drivers/media/usb/dvb-usb/dw2102.c
35889 @@ -95,7 +95,7 @@ struct su3000_state {
35890
35891 struct s6x0_state {
35892 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
35893 -};
35894 +} __no_const;
35895
35896 /* debug */
35897 static int dvb_usb_dw2102_debug;
35898 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
35899 index fb69baa..cf7ad22 100644
35900 --- a/drivers/message/fusion/mptbase.c
35901 +++ b/drivers/message/fusion/mptbase.c
35902 @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
35903 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
35904 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
35905
35906 +#ifdef CONFIG_GRKERNSEC_HIDESYM
35907 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
35908 +#else
35909 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
35910 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
35911 +#endif
35912 +
35913 /*
35914 * Rounding UP to nearest 4-kB boundary here...
35915 */
35916 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
35917 index 551262e..7551198 100644
35918 --- a/drivers/message/fusion/mptsas.c
35919 +++ b/drivers/message/fusion/mptsas.c
35920 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
35921 return 0;
35922 }
35923
35924 +static inline void
35925 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
35926 +{
35927 + if (phy_info->port_details) {
35928 + phy_info->port_details->rphy = rphy;
35929 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
35930 + ioc->name, rphy));
35931 + }
35932 +
35933 + if (rphy) {
35934 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
35935 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
35936 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
35937 + ioc->name, rphy, rphy->dev.release));
35938 + }
35939 +}
35940 +
35941 /* no mutex */
35942 static void
35943 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
35944 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
35945 return NULL;
35946 }
35947
35948 -static inline void
35949 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
35950 -{
35951 - if (phy_info->port_details) {
35952 - phy_info->port_details->rphy = rphy;
35953 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
35954 - ioc->name, rphy));
35955 - }
35956 -
35957 - if (rphy) {
35958 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
35959 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
35960 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
35961 - ioc->name, rphy, rphy->dev.release));
35962 - }
35963 -}
35964 -
35965 static inline struct sas_port *
35966 mptsas_get_port(struct mptsas_phyinfo *phy_info)
35967 {
35968 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
35969 index 0c3ced7..1fe34ec 100644
35970 --- a/drivers/message/fusion/mptscsih.c
35971 +++ b/drivers/message/fusion/mptscsih.c
35972 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
35973
35974 h = shost_priv(SChost);
35975
35976 - if (h) {
35977 - if (h->info_kbuf == NULL)
35978 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
35979 - return h->info_kbuf;
35980 - h->info_kbuf[0] = '\0';
35981 + if (!h)
35982 + return NULL;
35983
35984 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
35985 - h->info_kbuf[size-1] = '\0';
35986 - }
35987 + if (h->info_kbuf == NULL)
35988 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
35989 + return h->info_kbuf;
35990 + h->info_kbuf[0] = '\0';
35991 +
35992 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
35993 + h->info_kbuf[size-1] = '\0';
35994
35995 return h->info_kbuf;
35996 }
35997 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
35998 index 8001aa6..b137580 100644
35999 --- a/drivers/message/i2o/i2o_proc.c
36000 +++ b/drivers/message/i2o/i2o_proc.c
36001 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
36002 "Array Controller Device"
36003 };
36004
36005 -static char *chtostr(char *tmp, u8 *chars, int n)
36006 -{
36007 - tmp[0] = 0;
36008 - return strncat(tmp, (char *)chars, n);
36009 -}
36010 -
36011 static int i2o_report_query_status(struct seq_file *seq, int block_status,
36012 char *group)
36013 {
36014 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
36015 } *result;
36016
36017 i2o_exec_execute_ddm_table ddm_table;
36018 - char tmp[28 + 1];
36019
36020 result = kmalloc(sizeof(*result), GFP_KERNEL);
36021 if (!result)
36022 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
36023
36024 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
36025 seq_printf(seq, "%-#8x", ddm_table.module_id);
36026 - seq_printf(seq, "%-29s",
36027 - chtostr(tmp, ddm_table.module_name_version, 28));
36028 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
36029 seq_printf(seq, "%9d ", ddm_table.data_size);
36030 seq_printf(seq, "%8d", ddm_table.code_size);
36031
36032 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
36033
36034 i2o_driver_result_table *result;
36035 i2o_driver_store_table *dst;
36036 - char tmp[28 + 1];
36037
36038 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
36039 if (result == NULL)
36040 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
36041
36042 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
36043 seq_printf(seq, "%-#8x", dst->module_id);
36044 - seq_printf(seq, "%-29s",
36045 - chtostr(tmp, dst->module_name_version, 28));
36046 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
36047 + seq_printf(seq, "%-.28s", dst->module_name_version);
36048 + seq_printf(seq, "%-.8s", dst->date);
36049 seq_printf(seq, "%8d ", dst->module_size);
36050 seq_printf(seq, "%8d ", dst->mpb_size);
36051 seq_printf(seq, "0x%04x", dst->module_flags);
36052 @@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
36053 // == (allow) 512d bytes (max)
36054 static u16 *work16 = (u16 *) work32;
36055 int token;
36056 - char tmp[16 + 1];
36057
36058 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
36059
36060 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
36061 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
36062 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
36063 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
36064 - seq_printf(seq, "Vendor info : %s\n",
36065 - chtostr(tmp, (u8 *) (work32 + 2), 16));
36066 - seq_printf(seq, "Product info : %s\n",
36067 - chtostr(tmp, (u8 *) (work32 + 6), 16));
36068 - seq_printf(seq, "Description : %s\n",
36069 - chtostr(tmp, (u8 *) (work32 + 10), 16));
36070 - seq_printf(seq, "Product rev. : %s\n",
36071 - chtostr(tmp, (u8 *) (work32 + 14), 8));
36072 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
36073 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
36074 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
36075 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
36076
36077 seq_printf(seq, "Serial number : ");
36078 print_serial_number(seq, (u8 *) (work32 + 16),
36079 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
36080 u8 pad[256]; // allow up to 256 byte (max) serial number
36081 } result;
36082
36083 - char tmp[24 + 1];
36084 -
36085 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
36086
36087 if (token < 0) {
36088 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
36089 }
36090
36091 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
36092 - seq_printf(seq, "Module name : %s\n",
36093 - chtostr(tmp, result.module_name, 24));
36094 - seq_printf(seq, "Module revision : %s\n",
36095 - chtostr(tmp, result.module_rev, 8));
36096 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
36097 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
36098
36099 seq_printf(seq, "Serial number : ");
36100 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
36101 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
36102 u8 instance_number[4];
36103 } result;
36104
36105 - char tmp[64 + 1];
36106 -
36107 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
36108
36109 if (token < 0) {
36110 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
36111 return 0;
36112 }
36113
36114 - seq_printf(seq, "Device name : %s\n",
36115 - chtostr(tmp, result.device_name, 64));
36116 - seq_printf(seq, "Service name : %s\n",
36117 - chtostr(tmp, result.service_name, 64));
36118 - seq_printf(seq, "Physical name : %s\n",
36119 - chtostr(tmp, result.physical_location, 64));
36120 - seq_printf(seq, "Instance number : %s\n",
36121 - chtostr(tmp, result.instance_number, 4));
36122 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
36123 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
36124 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
36125 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
36126
36127 return 0;
36128 }
36129 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
36130 index a8c08f3..155fe3d 100644
36131 --- a/drivers/message/i2o/iop.c
36132 +++ b/drivers/message/i2o/iop.c
36133 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
36134
36135 spin_lock_irqsave(&c->context_list_lock, flags);
36136
36137 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
36138 - atomic_inc(&c->context_list_counter);
36139 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
36140 + atomic_inc_unchecked(&c->context_list_counter);
36141
36142 - entry->context = atomic_read(&c->context_list_counter);
36143 + entry->context = atomic_read_unchecked(&c->context_list_counter);
36144
36145 list_add(&entry->list, &c->context_list);
36146
36147 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
36148
36149 #if BITS_PER_LONG == 64
36150 spin_lock_init(&c->context_list_lock);
36151 - atomic_set(&c->context_list_counter, 0);
36152 + atomic_set_unchecked(&c->context_list_counter, 0);
36153 INIT_LIST_HEAD(&c->context_list);
36154 #endif
36155
36156 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
36157 index 965c480..71f2db9 100644
36158 --- a/drivers/mfd/janz-cmodio.c
36159 +++ b/drivers/mfd/janz-cmodio.c
36160 @@ -13,6 +13,7 @@
36161
36162 #include <linux/kernel.h>
36163 #include <linux/module.h>
36164 +#include <linux/slab.h>
36165 #include <linux/init.h>
36166 #include <linux/pci.h>
36167 #include <linux/interrupt.h>
36168 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
36169 index 3aa9a96..59cf685 100644
36170 --- a/drivers/misc/kgdbts.c
36171 +++ b/drivers/misc/kgdbts.c
36172 @@ -832,7 +832,7 @@ static void run_plant_and_detach_test(int is_early)
36173 char before[BREAK_INSTR_SIZE];
36174 char after[BREAK_INSTR_SIZE];
36175
36176 - probe_kernel_read(before, (char *)kgdbts_break_test,
36177 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
36178 BREAK_INSTR_SIZE);
36179 init_simple_test();
36180 ts.tst = plant_and_detach_test;
36181 @@ -840,7 +840,7 @@ static void run_plant_and_detach_test(int is_early)
36182 /* Activate test with initial breakpoint */
36183 if (!is_early)
36184 kgdb_breakpoint();
36185 - probe_kernel_read(after, (char *)kgdbts_break_test,
36186 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
36187 BREAK_INSTR_SIZE);
36188 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
36189 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
36190 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
36191 index 4a87e5c..76bdf5c 100644
36192 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
36193 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
36194 @@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
36195 * the lid is closed. This leads to interrupts as soon as a little move
36196 * is done.
36197 */
36198 - atomic_inc(&lis3->count);
36199 + atomic_inc_unchecked(&lis3->count);
36200
36201 wake_up_interruptible(&lis3->misc_wait);
36202 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
36203 @@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
36204 if (lis3->pm_dev)
36205 pm_runtime_get_sync(lis3->pm_dev);
36206
36207 - atomic_set(&lis3->count, 0);
36208 + atomic_set_unchecked(&lis3->count, 0);
36209 return 0;
36210 }
36211
36212 @@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
36213 add_wait_queue(&lis3->misc_wait, &wait);
36214 while (true) {
36215 set_current_state(TASK_INTERRUPTIBLE);
36216 - data = atomic_xchg(&lis3->count, 0);
36217 + data = atomic_xchg_unchecked(&lis3->count, 0);
36218 if (data)
36219 break;
36220
36221 @@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
36222 struct lis3lv02d, miscdev);
36223
36224 poll_wait(file, &lis3->misc_wait, wait);
36225 - if (atomic_read(&lis3->count))
36226 + if (atomic_read_unchecked(&lis3->count))
36227 return POLLIN | POLLRDNORM;
36228 return 0;
36229 }
36230 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
36231 index c439c82..1f20f57 100644
36232 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
36233 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
36234 @@ -297,7 +297,7 @@ struct lis3lv02d {
36235 struct input_polled_dev *idev; /* input device */
36236 struct platform_device *pdev; /* platform device */
36237 struct regulator_bulk_data regulators[2];
36238 - atomic_t count; /* interrupt count after last read */
36239 + atomic_unchecked_t count; /* interrupt count after last read */
36240 union axis_conversion ac; /* hw -> logical axis */
36241 int mapped_btns[3];
36242
36243 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
36244 index 2f30bad..c4c13d0 100644
36245 --- a/drivers/misc/sgi-gru/gruhandles.c
36246 +++ b/drivers/misc/sgi-gru/gruhandles.c
36247 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
36248 unsigned long nsec;
36249
36250 nsec = CLKS2NSEC(clks);
36251 - atomic_long_inc(&mcs_op_statistics[op].count);
36252 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
36253 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
36254 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
36255 if (mcs_op_statistics[op].max < nsec)
36256 mcs_op_statistics[op].max = nsec;
36257 }
36258 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
36259 index 950dbe9..eeef0f8 100644
36260 --- a/drivers/misc/sgi-gru/gruprocfs.c
36261 +++ b/drivers/misc/sgi-gru/gruprocfs.c
36262 @@ -32,9 +32,9 @@
36263
36264 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
36265
36266 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
36267 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
36268 {
36269 - unsigned long val = atomic_long_read(v);
36270 + unsigned long val = atomic_long_read_unchecked(v);
36271
36272 seq_printf(s, "%16lu %s\n", val, id);
36273 }
36274 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
36275
36276 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
36277 for (op = 0; op < mcsop_last; op++) {
36278 - count = atomic_long_read(&mcs_op_statistics[op].count);
36279 - total = atomic_long_read(&mcs_op_statistics[op].total);
36280 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
36281 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
36282 max = mcs_op_statistics[op].max;
36283 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
36284 count ? total / count : 0, max);
36285 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
36286 index 5c3ce24..4915ccb 100644
36287 --- a/drivers/misc/sgi-gru/grutables.h
36288 +++ b/drivers/misc/sgi-gru/grutables.h
36289 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
36290 * GRU statistics.
36291 */
36292 struct gru_stats_s {
36293 - atomic_long_t vdata_alloc;
36294 - atomic_long_t vdata_free;
36295 - atomic_long_t gts_alloc;
36296 - atomic_long_t gts_free;
36297 - atomic_long_t gms_alloc;
36298 - atomic_long_t gms_free;
36299 - atomic_long_t gts_double_allocate;
36300 - atomic_long_t assign_context;
36301 - atomic_long_t assign_context_failed;
36302 - atomic_long_t free_context;
36303 - atomic_long_t load_user_context;
36304 - atomic_long_t load_kernel_context;
36305 - atomic_long_t lock_kernel_context;
36306 - atomic_long_t unlock_kernel_context;
36307 - atomic_long_t steal_user_context;
36308 - atomic_long_t steal_kernel_context;
36309 - atomic_long_t steal_context_failed;
36310 - atomic_long_t nopfn;
36311 - atomic_long_t asid_new;
36312 - atomic_long_t asid_next;
36313 - atomic_long_t asid_wrap;
36314 - atomic_long_t asid_reuse;
36315 - atomic_long_t intr;
36316 - atomic_long_t intr_cbr;
36317 - atomic_long_t intr_tfh;
36318 - atomic_long_t intr_spurious;
36319 - atomic_long_t intr_mm_lock_failed;
36320 - atomic_long_t call_os;
36321 - atomic_long_t call_os_wait_queue;
36322 - atomic_long_t user_flush_tlb;
36323 - atomic_long_t user_unload_context;
36324 - atomic_long_t user_exception;
36325 - atomic_long_t set_context_option;
36326 - atomic_long_t check_context_retarget_intr;
36327 - atomic_long_t check_context_unload;
36328 - atomic_long_t tlb_dropin;
36329 - atomic_long_t tlb_preload_page;
36330 - atomic_long_t tlb_dropin_fail_no_asid;
36331 - atomic_long_t tlb_dropin_fail_upm;
36332 - atomic_long_t tlb_dropin_fail_invalid;
36333 - atomic_long_t tlb_dropin_fail_range_active;
36334 - atomic_long_t tlb_dropin_fail_idle;
36335 - atomic_long_t tlb_dropin_fail_fmm;
36336 - atomic_long_t tlb_dropin_fail_no_exception;
36337 - atomic_long_t tfh_stale_on_fault;
36338 - atomic_long_t mmu_invalidate_range;
36339 - atomic_long_t mmu_invalidate_page;
36340 - atomic_long_t flush_tlb;
36341 - atomic_long_t flush_tlb_gru;
36342 - atomic_long_t flush_tlb_gru_tgh;
36343 - atomic_long_t flush_tlb_gru_zero_asid;
36344 + atomic_long_unchecked_t vdata_alloc;
36345 + atomic_long_unchecked_t vdata_free;
36346 + atomic_long_unchecked_t gts_alloc;
36347 + atomic_long_unchecked_t gts_free;
36348 + atomic_long_unchecked_t gms_alloc;
36349 + atomic_long_unchecked_t gms_free;
36350 + atomic_long_unchecked_t gts_double_allocate;
36351 + atomic_long_unchecked_t assign_context;
36352 + atomic_long_unchecked_t assign_context_failed;
36353 + atomic_long_unchecked_t free_context;
36354 + atomic_long_unchecked_t load_user_context;
36355 + atomic_long_unchecked_t load_kernel_context;
36356 + atomic_long_unchecked_t lock_kernel_context;
36357 + atomic_long_unchecked_t unlock_kernel_context;
36358 + atomic_long_unchecked_t steal_user_context;
36359 + atomic_long_unchecked_t steal_kernel_context;
36360 + atomic_long_unchecked_t steal_context_failed;
36361 + atomic_long_unchecked_t nopfn;
36362 + atomic_long_unchecked_t asid_new;
36363 + atomic_long_unchecked_t asid_next;
36364 + atomic_long_unchecked_t asid_wrap;
36365 + atomic_long_unchecked_t asid_reuse;
36366 + atomic_long_unchecked_t intr;
36367 + atomic_long_unchecked_t intr_cbr;
36368 + atomic_long_unchecked_t intr_tfh;
36369 + atomic_long_unchecked_t intr_spurious;
36370 + atomic_long_unchecked_t intr_mm_lock_failed;
36371 + atomic_long_unchecked_t call_os;
36372 + atomic_long_unchecked_t call_os_wait_queue;
36373 + atomic_long_unchecked_t user_flush_tlb;
36374 + atomic_long_unchecked_t user_unload_context;
36375 + atomic_long_unchecked_t user_exception;
36376 + atomic_long_unchecked_t set_context_option;
36377 + atomic_long_unchecked_t check_context_retarget_intr;
36378 + atomic_long_unchecked_t check_context_unload;
36379 + atomic_long_unchecked_t tlb_dropin;
36380 + atomic_long_unchecked_t tlb_preload_page;
36381 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
36382 + atomic_long_unchecked_t tlb_dropin_fail_upm;
36383 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
36384 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
36385 + atomic_long_unchecked_t tlb_dropin_fail_idle;
36386 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
36387 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
36388 + atomic_long_unchecked_t tfh_stale_on_fault;
36389 + atomic_long_unchecked_t mmu_invalidate_range;
36390 + atomic_long_unchecked_t mmu_invalidate_page;
36391 + atomic_long_unchecked_t flush_tlb;
36392 + atomic_long_unchecked_t flush_tlb_gru;
36393 + atomic_long_unchecked_t flush_tlb_gru_tgh;
36394 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
36395
36396 - atomic_long_t copy_gpa;
36397 - atomic_long_t read_gpa;
36398 + atomic_long_unchecked_t copy_gpa;
36399 + atomic_long_unchecked_t read_gpa;
36400
36401 - atomic_long_t mesq_receive;
36402 - atomic_long_t mesq_receive_none;
36403 - atomic_long_t mesq_send;
36404 - atomic_long_t mesq_send_failed;
36405 - atomic_long_t mesq_noop;
36406 - atomic_long_t mesq_send_unexpected_error;
36407 - atomic_long_t mesq_send_lb_overflow;
36408 - atomic_long_t mesq_send_qlimit_reached;
36409 - atomic_long_t mesq_send_amo_nacked;
36410 - atomic_long_t mesq_send_put_nacked;
36411 - atomic_long_t mesq_page_overflow;
36412 - atomic_long_t mesq_qf_locked;
36413 - atomic_long_t mesq_qf_noop_not_full;
36414 - atomic_long_t mesq_qf_switch_head_failed;
36415 - atomic_long_t mesq_qf_unexpected_error;
36416 - atomic_long_t mesq_noop_unexpected_error;
36417 - atomic_long_t mesq_noop_lb_overflow;
36418 - atomic_long_t mesq_noop_qlimit_reached;
36419 - atomic_long_t mesq_noop_amo_nacked;
36420 - atomic_long_t mesq_noop_put_nacked;
36421 - atomic_long_t mesq_noop_page_overflow;
36422 + atomic_long_unchecked_t mesq_receive;
36423 + atomic_long_unchecked_t mesq_receive_none;
36424 + atomic_long_unchecked_t mesq_send;
36425 + atomic_long_unchecked_t mesq_send_failed;
36426 + atomic_long_unchecked_t mesq_noop;
36427 + atomic_long_unchecked_t mesq_send_unexpected_error;
36428 + atomic_long_unchecked_t mesq_send_lb_overflow;
36429 + atomic_long_unchecked_t mesq_send_qlimit_reached;
36430 + atomic_long_unchecked_t mesq_send_amo_nacked;
36431 + atomic_long_unchecked_t mesq_send_put_nacked;
36432 + atomic_long_unchecked_t mesq_page_overflow;
36433 + atomic_long_unchecked_t mesq_qf_locked;
36434 + atomic_long_unchecked_t mesq_qf_noop_not_full;
36435 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
36436 + atomic_long_unchecked_t mesq_qf_unexpected_error;
36437 + atomic_long_unchecked_t mesq_noop_unexpected_error;
36438 + atomic_long_unchecked_t mesq_noop_lb_overflow;
36439 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
36440 + atomic_long_unchecked_t mesq_noop_amo_nacked;
36441 + atomic_long_unchecked_t mesq_noop_put_nacked;
36442 + atomic_long_unchecked_t mesq_noop_page_overflow;
36443
36444 };
36445
36446 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
36447 tghop_invalidate, mcsop_last};
36448
36449 struct mcs_op_statistic {
36450 - atomic_long_t count;
36451 - atomic_long_t total;
36452 + atomic_long_unchecked_t count;
36453 + atomic_long_unchecked_t total;
36454 unsigned long max;
36455 };
36456
36457 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
36458
36459 #define STAT(id) do { \
36460 if (gru_options & OPT_STATS) \
36461 - atomic_long_inc(&gru_stats.id); \
36462 + atomic_long_inc_unchecked(&gru_stats.id); \
36463 } while (0)
36464
36465 #ifdef CONFIG_SGI_GRU_DEBUG
36466 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
36467 index c862cd4..0d176fe 100644
36468 --- a/drivers/misc/sgi-xp/xp.h
36469 +++ b/drivers/misc/sgi-xp/xp.h
36470 @@ -288,7 +288,7 @@ struct xpc_interface {
36471 xpc_notify_func, void *);
36472 void (*received) (short, int, void *);
36473 enum xp_retval (*partid_to_nasids) (short, void *);
36474 -};
36475 +} __no_const;
36476
36477 extern struct xpc_interface xpc_interface;
36478
36479 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
36480 index b94d5f7..7f494c5 100644
36481 --- a/drivers/misc/sgi-xp/xpc.h
36482 +++ b/drivers/misc/sgi-xp/xpc.h
36483 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
36484 void (*received_payload) (struct xpc_channel *, void *);
36485 void (*notify_senders_of_disconnect) (struct xpc_channel *);
36486 };
36487 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
36488
36489 /* struct xpc_partition act_state values (for XPC HB) */
36490
36491 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
36492 /* found in xpc_main.c */
36493 extern struct device *xpc_part;
36494 extern struct device *xpc_chan;
36495 -extern struct xpc_arch_operations xpc_arch_ops;
36496 +extern xpc_arch_operations_no_const xpc_arch_ops;
36497 extern int xpc_disengage_timelimit;
36498 extern int xpc_disengage_timedout;
36499 extern int xpc_activate_IRQ_rcvd;
36500 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
36501 index d971817..33bdca5 100644
36502 --- a/drivers/misc/sgi-xp/xpc_main.c
36503 +++ b/drivers/misc/sgi-xp/xpc_main.c
36504 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
36505 .notifier_call = xpc_system_die,
36506 };
36507
36508 -struct xpc_arch_operations xpc_arch_ops;
36509 +xpc_arch_operations_no_const xpc_arch_ops;
36510
36511 /*
36512 * Timer function to enforce the timelimit on the partition disengage.
36513 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
36514
36515 if (((die_args->trapnr == X86_TRAP_MF) ||
36516 (die_args->trapnr == X86_TRAP_XF)) &&
36517 - !user_mode_vm(die_args->regs))
36518 + !user_mode(die_args->regs))
36519 xpc_die_deactivate();
36520
36521 break;
36522 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
36523 index a0e1720..ee63d0b 100644
36524 --- a/drivers/mmc/core/mmc_ops.c
36525 +++ b/drivers/mmc/core/mmc_ops.c
36526 @@ -245,7 +245,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
36527 void *data_buf;
36528 int is_on_stack;
36529
36530 - is_on_stack = object_is_on_stack(buf);
36531 + is_on_stack = object_starts_on_stack(buf);
36532 if (is_on_stack) {
36533 /*
36534 * dma onto stack is unsafe/nonportable, but callers to this
36535 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
36536 index 53b8fd9..615b462 100644
36537 --- a/drivers/mmc/host/dw_mmc.h
36538 +++ b/drivers/mmc/host/dw_mmc.h
36539 @@ -205,5 +205,5 @@ struct dw_mci_drv_data {
36540 int (*parse_dt)(struct dw_mci *host);
36541 int (*setup_bus)(struct dw_mci *host,
36542 struct device_node *slot_np, u8 bus_width);
36543 -};
36544 +} __do_const;
36545 #endif /* _DW_MMC_H_ */
36546 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
36547 index c9ec725..178e79a 100644
36548 --- a/drivers/mmc/host/sdhci-s3c.c
36549 +++ b/drivers/mmc/host/sdhci-s3c.c
36550 @@ -719,9 +719,11 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
36551 * we can use overriding functions instead of default.
36552 */
36553 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
36554 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
36555 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
36556 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
36557 + pax_open_kernel();
36558 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
36559 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
36560 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
36561 + pax_close_kernel();
36562 }
36563
36564 /* It supports additional host capabilities if needed */
36565 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
36566 index a4eb8b5..8c0628f 100644
36567 --- a/drivers/mtd/devices/doc2000.c
36568 +++ b/drivers/mtd/devices/doc2000.c
36569 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
36570
36571 /* The ECC will not be calculated correctly if less than 512 is written */
36572 /* DBB-
36573 - if (len != 0x200 && eccbuf)
36574 + if (len != 0x200)
36575 printk(KERN_WARNING
36576 "ECC needs a full sector write (adr: %lx size %lx)\n",
36577 (long) to, (long) len);
36578 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
36579 index e706a23..b3d262f 100644
36580 --- a/drivers/mtd/nand/denali.c
36581 +++ b/drivers/mtd/nand/denali.c
36582 @@ -26,6 +26,7 @@
36583 #include <linux/pci.h>
36584 #include <linux/mtd/mtd.h>
36585 #include <linux/module.h>
36586 +#include <linux/slab.h>
36587
36588 #include "denali.h"
36589
36590 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
36591 index 51b9d6a..52af9a7 100644
36592 --- a/drivers/mtd/nftlmount.c
36593 +++ b/drivers/mtd/nftlmount.c
36594 @@ -24,6 +24,7 @@
36595 #include <asm/errno.h>
36596 #include <linux/delay.h>
36597 #include <linux/slab.h>
36598 +#include <linux/sched.h>
36599 #include <linux/mtd/mtd.h>
36600 #include <linux/mtd/nand.h>
36601 #include <linux/mtd/nftl.h>
36602 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
36603 index 203ff9d..0968ca8 100644
36604 --- a/drivers/net/ethernet/8390/ax88796.c
36605 +++ b/drivers/net/ethernet/8390/ax88796.c
36606 @@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
36607 if (ax->plat->reg_offsets)
36608 ei_local->reg_offset = ax->plat->reg_offsets;
36609 else {
36610 + resource_size_t _mem_size = mem_size;
36611 + do_div(_mem_size, 0x18);
36612 ei_local->reg_offset = ax->reg_offsets;
36613 for (ret = 0; ret < 0x18; ret++)
36614 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
36615 + ax->reg_offsets[ret] = _mem_size * ret;
36616 }
36617
36618 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
36619 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
36620 index 9c5ea6c..eaad276 100644
36621 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
36622 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
36623 @@ -1046,7 +1046,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
36624 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
36625 {
36626 /* RX_MODE controlling object */
36627 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
36628 + bnx2x_init_rx_mode_obj(bp);
36629
36630 /* multicast configuration controlling object */
36631 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
36632 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
36633 index 614981c..11216c7 100644
36634 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
36635 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
36636 @@ -2375,15 +2375,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
36637 return rc;
36638 }
36639
36640 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
36641 - struct bnx2x_rx_mode_obj *o)
36642 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
36643 {
36644 if (CHIP_IS_E1x(bp)) {
36645 - o->wait_comp = bnx2x_empty_rx_mode_wait;
36646 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
36647 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
36648 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
36649 } else {
36650 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
36651 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
36652 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
36653 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
36654 }
36655 }
36656
36657 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
36658 index acf2fe4..efb96df 100644
36659 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
36660 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
36661 @@ -1281,8 +1281,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
36662
36663 /********************* RX MODE ****************/
36664
36665 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
36666 - struct bnx2x_rx_mode_obj *o);
36667 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
36668
36669 /**
36670 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
36671 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
36672 index d9308c32..d87b824 100644
36673 --- a/drivers/net/ethernet/broadcom/tg3.h
36674 +++ b/drivers/net/ethernet/broadcom/tg3.h
36675 @@ -140,6 +140,7 @@
36676 #define CHIPREV_ID_5750_A0 0x4000
36677 #define CHIPREV_ID_5750_A1 0x4001
36678 #define CHIPREV_ID_5750_A3 0x4003
36679 +#define CHIPREV_ID_5750_C1 0x4201
36680 #define CHIPREV_ID_5750_C2 0x4202
36681 #define CHIPREV_ID_5752_A0_HW 0x5000
36682 #define CHIPREV_ID_5752_A0 0x6000
36683 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
36684 index 8cffcdf..aadf043 100644
36685 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
36686 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
36687 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
36688 */
36689 struct l2t_skb_cb {
36690 arp_failure_handler_func arp_failure_handler;
36691 -};
36692 +} __no_const;
36693
36694 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
36695
36696 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
36697 index f879e92..726f20f 100644
36698 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
36699 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
36700 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
36701 for (i=0; i<ETH_ALEN; i++) {
36702 tmp.addr[i] = dev->dev_addr[i];
36703 }
36704 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
36705 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
36706 break;
36707
36708 case DE4X5_SET_HWADDR: /* Set the hardware address */
36709 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
36710 spin_lock_irqsave(&lp->lock, flags);
36711 memcpy(&statbuf, &lp->pktStats, ioc->len);
36712 spin_unlock_irqrestore(&lp->lock, flags);
36713 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
36714 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
36715 return -EFAULT;
36716 break;
36717 }
36718 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
36719 index d1b6cc5..cde0d97 100644
36720 --- a/drivers/net/ethernet/emulex/benet/be_main.c
36721 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
36722 @@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
36723
36724 if (wrapped)
36725 newacc += 65536;
36726 - ACCESS_ONCE(*acc) = newacc;
36727 + ACCESS_ONCE_RW(*acc) = newacc;
36728 }
36729
36730 void be_parse_stats(struct be_adapter *adapter)
36731 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
36732 index 74d749e..eefb1bd 100644
36733 --- a/drivers/net/ethernet/faraday/ftgmac100.c
36734 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
36735 @@ -31,6 +31,8 @@
36736 #include <linux/netdevice.h>
36737 #include <linux/phy.h>
36738 #include <linux/platform_device.h>
36739 +#include <linux/interrupt.h>
36740 +#include <linux/irqreturn.h>
36741 #include <net/ip.h>
36742
36743 #include "ftgmac100.h"
36744 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
36745 index b901a01..1ff32ee 100644
36746 --- a/drivers/net/ethernet/faraday/ftmac100.c
36747 +++ b/drivers/net/ethernet/faraday/ftmac100.c
36748 @@ -31,6 +31,8 @@
36749 #include <linux/module.h>
36750 #include <linux/netdevice.h>
36751 #include <linux/platform_device.h>
36752 +#include <linux/interrupt.h>
36753 +#include <linux/irqreturn.h>
36754
36755 #include "ftmac100.h"
36756
36757 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
36758 index d929131..aed108f 100644
36759 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
36760 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
36761 @@ -865,7 +865,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
36762 /* store the new cycle speed */
36763 adapter->cycle_speed = cycle_speed;
36764
36765 - ACCESS_ONCE(adapter->base_incval) = incval;
36766 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
36767 smp_mb();
36768
36769 /* grab the ptp lock */
36770 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
36771 index c2e420a..26a75e0 100644
36772 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
36773 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
36774 @@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
36775 struct __vxge_hw_fifo *fifo;
36776 struct vxge_hw_fifo_config *config;
36777 u32 txdl_size, txdl_per_memblock;
36778 - struct vxge_hw_mempool_cbs fifo_mp_callback;
36779 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
36780 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
36781 + };
36782 +
36783 struct __vxge_hw_virtualpath *vpath;
36784
36785 if ((vp == NULL) || (attr == NULL)) {
36786 @@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
36787 goto exit;
36788 }
36789
36790 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
36791 -
36792 fifo->mempool =
36793 __vxge_hw_mempool_create(vpath->hldev,
36794 fifo->config->memblock_size,
36795 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
36796 index 927aa33..a6c2518 100644
36797 --- a/drivers/net/ethernet/realtek/r8169.c
36798 +++ b/drivers/net/ethernet/realtek/r8169.c
36799 @@ -747,22 +747,22 @@ struct rtl8169_private {
36800 struct mdio_ops {
36801 void (*write)(struct rtl8169_private *, int, int);
36802 int (*read)(struct rtl8169_private *, int);
36803 - } mdio_ops;
36804 + } __no_const mdio_ops;
36805
36806 struct pll_power_ops {
36807 void (*down)(struct rtl8169_private *);
36808 void (*up)(struct rtl8169_private *);
36809 - } pll_power_ops;
36810 + } __no_const pll_power_ops;
36811
36812 struct jumbo_ops {
36813 void (*enable)(struct rtl8169_private *);
36814 void (*disable)(struct rtl8169_private *);
36815 - } jumbo_ops;
36816 + } __no_const jumbo_ops;
36817
36818 struct csi_ops {
36819 void (*write)(struct rtl8169_private *, int, int);
36820 u32 (*read)(struct rtl8169_private *, int);
36821 - } csi_ops;
36822 + } __no_const csi_ops;
36823
36824 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
36825 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
36826 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
36827 index 0767043f..08c2553 100644
36828 --- a/drivers/net/ethernet/sfc/ptp.c
36829 +++ b/drivers/net/ethernet/sfc/ptp.c
36830 @@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
36831 (u32)((u64)ptp->start.dma_addr >> 32));
36832
36833 /* Clear flag that signals MC ready */
36834 - ACCESS_ONCE(*start) = 0;
36835 + ACCESS_ONCE_RW(*start) = 0;
36836 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
36837 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
36838
36839 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36840 index 0c74a70..3bc6f68 100644
36841 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36842 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36843 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
36844
36845 writel(value, ioaddr + MMC_CNTRL);
36846
36847 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
36848 - MMC_CNTRL, value);
36849 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
36850 +// MMC_CNTRL, value);
36851 }
36852
36853 /* To mask all all interrupts.*/
36854 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
36855 index 5fd6f46..ee1f265 100644
36856 --- a/drivers/net/hyperv/hyperv_net.h
36857 +++ b/drivers/net/hyperv/hyperv_net.h
36858 @@ -101,7 +101,7 @@ struct rndis_device {
36859
36860 enum rndis_device_state state;
36861 bool link_state;
36862 - atomic_t new_req_id;
36863 + atomic_unchecked_t new_req_id;
36864
36865 spinlock_t request_lock;
36866 struct list_head req_list;
36867 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
36868 index 928148c..d83298e 100644
36869 --- a/drivers/net/hyperv/rndis_filter.c
36870 +++ b/drivers/net/hyperv/rndis_filter.c
36871 @@ -107,7 +107,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
36872 * template
36873 */
36874 set = &rndis_msg->msg.set_req;
36875 - set->req_id = atomic_inc_return(&dev->new_req_id);
36876 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
36877
36878 /* Add to the request list */
36879 spin_lock_irqsave(&dev->request_lock, flags);
36880 @@ -760,7 +760,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
36881
36882 /* Setup the rndis set */
36883 halt = &request->request_msg.msg.halt_req;
36884 - halt->req_id = atomic_inc_return(&dev->new_req_id);
36885 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
36886
36887 /* Ignore return since this msg is optional. */
36888 rndis_filter_send_request(dev, request);
36889 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
36890 index 7d39add..037e1da 100644
36891 --- a/drivers/net/ieee802154/fakehard.c
36892 +++ b/drivers/net/ieee802154/fakehard.c
36893 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
36894 phy->transmit_power = 0xbf;
36895
36896 dev->netdev_ops = &fake_ops;
36897 - dev->ml_priv = &fake_mlme;
36898 + dev->ml_priv = (void *)&fake_mlme;
36899
36900 priv = netdev_priv(dev);
36901 priv->phy = phy;
36902 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
36903 index 0f0f9ce..0ca5819 100644
36904 --- a/drivers/net/macvtap.c
36905 +++ b/drivers/net/macvtap.c
36906 @@ -1100,7 +1100,7 @@ static int macvtap_device_event(struct notifier_block *unused,
36907 return NOTIFY_DONE;
36908 }
36909
36910 -static struct notifier_block macvtap_notifier_block __read_mostly = {
36911 +static struct notifier_block macvtap_notifier_block = {
36912 .notifier_call = macvtap_device_event,
36913 };
36914
36915 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
36916 index daec9b0..6428fcb 100644
36917 --- a/drivers/net/phy/mdio-bitbang.c
36918 +++ b/drivers/net/phy/mdio-bitbang.c
36919 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
36920 struct mdiobb_ctrl *ctrl = bus->priv;
36921
36922 module_put(ctrl->ops->owner);
36923 + mdiobus_unregister(bus);
36924 mdiobus_free(bus);
36925 }
36926 EXPORT_SYMBOL(free_mdio_bitbang);
36927 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
36928 index eb3f5ce..d773730 100644
36929 --- a/drivers/net/ppp/ppp_generic.c
36930 +++ b/drivers/net/ppp/ppp_generic.c
36931 @@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36932 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
36933 struct ppp_stats stats;
36934 struct ppp_comp_stats cstats;
36935 - char *vers;
36936
36937 switch (cmd) {
36938 case SIOCGPPPSTATS:
36939 @@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36940 break;
36941
36942 case SIOCGPPPVER:
36943 - vers = PPP_VERSION;
36944 - if (copy_to_user(addr, vers, strlen(vers) + 1))
36945 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
36946 break;
36947 err = 0;
36948 break;
36949 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
36950 index ad86660..9fd0884 100644
36951 --- a/drivers/net/team/team.c
36952 +++ b/drivers/net/team/team.c
36953 @@ -2601,7 +2601,7 @@ static int team_device_event(struct notifier_block *unused,
36954 return NOTIFY_DONE;
36955 }
36956
36957 -static struct notifier_block team_notifier_block __read_mostly = {
36958 +static struct notifier_block team_notifier_block = {
36959 .notifier_call = team_device_event,
36960 };
36961
36962 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
36963 index 0873cdc..ddb178e 100644
36964 --- a/drivers/net/tun.c
36965 +++ b/drivers/net/tun.c
36966 @@ -1374,7 +1374,7 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
36967 }
36968
36969 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
36970 - unsigned long arg, int ifreq_len)
36971 + unsigned long arg, size_t ifreq_len)
36972 {
36973 struct tun_file *tfile = file->private_data;
36974 struct tun_struct *tun;
36975 @@ -1387,6 +1387,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
36976 int vnet_hdr_sz;
36977 int ret;
36978
36979 + if (ifreq_len > sizeof ifr)
36980 + return -EFAULT;
36981 +
36982 if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
36983 if (copy_from_user(&ifr, argp, ifreq_len))
36984 return -EFAULT;
36985 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
36986 index 605a4ba..a883dd1 100644
36987 --- a/drivers/net/usb/hso.c
36988 +++ b/drivers/net/usb/hso.c
36989 @@ -71,7 +71,7 @@
36990 #include <asm/byteorder.h>
36991 #include <linux/serial_core.h>
36992 #include <linux/serial.h>
36993 -
36994 +#include <asm/local.h>
36995
36996 #define MOD_AUTHOR "Option Wireless"
36997 #define MOD_DESCRIPTION "USB High Speed Option driver"
36998 @@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
36999 struct urb *urb;
37000
37001 urb = serial->rx_urb[0];
37002 - if (serial->port.count > 0) {
37003 + if (atomic_read(&serial->port.count) > 0) {
37004 count = put_rxbuf_data(urb, serial);
37005 if (count == -1)
37006 return;
37007 @@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
37008 DUMP1(urb->transfer_buffer, urb->actual_length);
37009
37010 /* Anyone listening? */
37011 - if (serial->port.count == 0)
37012 + if (atomic_read(&serial->port.count) == 0)
37013 return;
37014
37015 if (status == 0) {
37016 @@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
37017 tty_port_tty_set(&serial->port, tty);
37018
37019 /* check for port already opened, if not set the termios */
37020 - serial->port.count++;
37021 - if (serial->port.count == 1) {
37022 + if (atomic_inc_return(&serial->port.count) == 1) {
37023 serial->rx_state = RX_IDLE;
37024 /* Force default termio settings */
37025 _hso_serial_set_termios(tty, NULL);
37026 @@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
37027 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
37028 if (result) {
37029 hso_stop_serial_device(serial->parent);
37030 - serial->port.count--;
37031 + atomic_dec(&serial->port.count);
37032 kref_put(&serial->parent->ref, hso_serial_ref_free);
37033 }
37034 } else {
37035 @@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
37036
37037 /* reset the rts and dtr */
37038 /* do the actual close */
37039 - serial->port.count--;
37040 + atomic_dec(&serial->port.count);
37041
37042 - if (serial->port.count <= 0) {
37043 - serial->port.count = 0;
37044 + if (atomic_read(&serial->port.count) <= 0) {
37045 + atomic_set(&serial->port.count, 0);
37046 tty_port_tty_set(&serial->port, NULL);
37047 if (!usb_gone)
37048 hso_stop_serial_device(serial->parent);
37049 @@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
37050
37051 /* the actual setup */
37052 spin_lock_irqsave(&serial->serial_lock, flags);
37053 - if (serial->port.count)
37054 + if (atomic_read(&serial->port.count))
37055 _hso_serial_set_termios(tty, old);
37056 else
37057 tty->termios = *old;
37058 @@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
37059 D1("Pending read interrupt on port %d\n", i);
37060 spin_lock(&serial->serial_lock);
37061 if (serial->rx_state == RX_IDLE &&
37062 - serial->port.count > 0) {
37063 + atomic_read(&serial->port.count) > 0) {
37064 /* Setup and send a ctrl req read on
37065 * port i */
37066 if (!serial->rx_urb_filled[0]) {
37067 @@ -3078,7 +3077,7 @@ static int hso_resume(struct usb_interface *iface)
37068 /* Start all serial ports */
37069 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
37070 if (serial_table[i] && (serial_table[i]->interface == iface)) {
37071 - if (dev2ser(serial_table[i])->port.count) {
37072 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
37073 result =
37074 hso_start_serial_device(serial_table[i], GFP_NOIO);
37075 hso_kick_transmit(dev2ser(serial_table[i]));
37076 diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
37077 index edb81ed..ab8931c 100644
37078 --- a/drivers/net/usb/usbnet.c
37079 +++ b/drivers/net/usb/usbnet.c
37080 @@ -380,6 +380,12 @@ static int rx_submit (struct usbnet *dev, struct urb *urb, gfp_t flags)
37081 unsigned long lockflags;
37082 size_t size = dev->rx_urb_size;
37083
37084 + /* prevent rx skb allocation when error ratio is high */
37085 + if (test_bit(EVENT_RX_KILL, &dev->flags)) {
37086 + usb_free_urb(urb);
37087 + return -ENOLINK;
37088 + }
37089 +
37090 skb = __netdev_alloc_skb_ip_align(dev->net, size, flags);
37091 if (!skb) {
37092 netif_dbg(dev, rx_err, dev->net, "no rx skb\n");
37093 @@ -539,6 +545,17 @@ block:
37094 break;
37095 }
37096
37097 + /* stop rx if packet error rate is high */
37098 + if (++dev->pkt_cnt > 30) {
37099 + dev->pkt_cnt = 0;
37100 + dev->pkt_err = 0;
37101 + } else {
37102 + if (state == rx_cleanup)
37103 + dev->pkt_err++;
37104 + if (dev->pkt_err > 20)
37105 + set_bit(EVENT_RX_KILL, &dev->flags);
37106 + }
37107 +
37108 state = defer_bh(dev, skb, &dev->rxq, state);
37109
37110 if (urb) {
37111 @@ -790,6 +807,11 @@ int usbnet_open (struct net_device *net)
37112 (dev->driver_info->flags & FLAG_FRAMING_AX) ? "ASIX" :
37113 "simple");
37114
37115 + /* reset rx error state */
37116 + dev->pkt_cnt = 0;
37117 + dev->pkt_err = 0;
37118 + clear_bit(EVENT_RX_KILL, &dev->flags);
37119 +
37120 // delay posting reads until we're fully open
37121 tasklet_schedule (&dev->bh);
37122 if (info->manage_power) {
37123 @@ -1253,6 +1275,9 @@ static void usbnet_bh (unsigned long param)
37124 }
37125 }
37126
37127 + /* restart RX again after disabling due to high error rate */
37128 + clear_bit(EVENT_RX_KILL, &dev->flags);
37129 +
37130 // waiting for all pending urbs to complete?
37131 if (dev->wait) {
37132 if ((dev->txq.qlen + dev->rxq.qlen + dev->done.qlen) == 0) {
37133 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
37134 index 8d78253..bebbb68 100644
37135 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
37136 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
37137 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37138 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
37139 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
37140
37141 - ACCESS_ONCE(ads->ds_link) = i->link;
37142 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
37143 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
37144 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
37145
37146 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
37147 ctl6 = SM(i->keytype, AR_EncrType);
37148 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37149
37150 if ((i->is_first || i->is_last) &&
37151 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
37152 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
37153 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
37154 | set11nTries(i->rates, 1)
37155 | set11nTries(i->rates, 2)
37156 | set11nTries(i->rates, 3)
37157 | (i->dur_update ? AR_DurUpdateEna : 0)
37158 | SM(0, AR_BurstDur);
37159
37160 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
37161 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
37162 | set11nRate(i->rates, 1)
37163 | set11nRate(i->rates, 2)
37164 | set11nRate(i->rates, 3);
37165 } else {
37166 - ACCESS_ONCE(ads->ds_ctl2) = 0;
37167 - ACCESS_ONCE(ads->ds_ctl3) = 0;
37168 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
37169 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
37170 }
37171
37172 if (!i->is_first) {
37173 - ACCESS_ONCE(ads->ds_ctl0) = 0;
37174 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
37175 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
37176 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
37177 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
37178 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
37179 return;
37180 }
37181
37182 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37183 break;
37184 }
37185
37186 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
37187 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
37188 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
37189 | SM(i->txpower, AR_XmitPower)
37190 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
37191 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37192 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
37193 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
37194
37195 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
37196 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
37197 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
37198 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
37199
37200 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
37201 return;
37202
37203 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
37204 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
37205 | set11nPktDurRTSCTS(i->rates, 1);
37206
37207 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
37208 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
37209 | set11nPktDurRTSCTS(i->rates, 3);
37210
37211 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
37212 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
37213 | set11nRateFlags(i->rates, 1)
37214 | set11nRateFlags(i->rates, 2)
37215 | set11nRateFlags(i->rates, 3)
37216 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
37217 index 301bf72..3f5654f 100644
37218 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
37219 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
37220 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37221 (i->qcu << AR_TxQcuNum_S) | desc_len;
37222
37223 checksum += val;
37224 - ACCESS_ONCE(ads->info) = val;
37225 + ACCESS_ONCE_RW(ads->info) = val;
37226
37227 checksum += i->link;
37228 - ACCESS_ONCE(ads->link) = i->link;
37229 + ACCESS_ONCE_RW(ads->link) = i->link;
37230
37231 checksum += i->buf_addr[0];
37232 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
37233 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
37234 checksum += i->buf_addr[1];
37235 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
37236 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
37237 checksum += i->buf_addr[2];
37238 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
37239 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
37240 checksum += i->buf_addr[3];
37241 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
37242 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
37243
37244 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
37245 - ACCESS_ONCE(ads->ctl3) = val;
37246 + ACCESS_ONCE_RW(ads->ctl3) = val;
37247 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
37248 - ACCESS_ONCE(ads->ctl5) = val;
37249 + ACCESS_ONCE_RW(ads->ctl5) = val;
37250 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
37251 - ACCESS_ONCE(ads->ctl7) = val;
37252 + ACCESS_ONCE_RW(ads->ctl7) = val;
37253 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
37254 - ACCESS_ONCE(ads->ctl9) = val;
37255 + ACCESS_ONCE_RW(ads->ctl9) = val;
37256
37257 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
37258 - ACCESS_ONCE(ads->ctl10) = checksum;
37259 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
37260
37261 if (i->is_first || i->is_last) {
37262 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
37263 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
37264 | set11nTries(i->rates, 1)
37265 | set11nTries(i->rates, 2)
37266 | set11nTries(i->rates, 3)
37267 | (i->dur_update ? AR_DurUpdateEna : 0)
37268 | SM(0, AR_BurstDur);
37269
37270 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
37271 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
37272 | set11nRate(i->rates, 1)
37273 | set11nRate(i->rates, 2)
37274 | set11nRate(i->rates, 3);
37275 } else {
37276 - ACCESS_ONCE(ads->ctl13) = 0;
37277 - ACCESS_ONCE(ads->ctl14) = 0;
37278 + ACCESS_ONCE_RW(ads->ctl13) = 0;
37279 + ACCESS_ONCE_RW(ads->ctl14) = 0;
37280 }
37281
37282 ads->ctl20 = 0;
37283 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37284
37285 ctl17 = SM(i->keytype, AR_EncrType);
37286 if (!i->is_first) {
37287 - ACCESS_ONCE(ads->ctl11) = 0;
37288 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
37289 - ACCESS_ONCE(ads->ctl15) = 0;
37290 - ACCESS_ONCE(ads->ctl16) = 0;
37291 - ACCESS_ONCE(ads->ctl17) = ctl17;
37292 - ACCESS_ONCE(ads->ctl18) = 0;
37293 - ACCESS_ONCE(ads->ctl19) = 0;
37294 + ACCESS_ONCE_RW(ads->ctl11) = 0;
37295 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
37296 + ACCESS_ONCE_RW(ads->ctl15) = 0;
37297 + ACCESS_ONCE_RW(ads->ctl16) = 0;
37298 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
37299 + ACCESS_ONCE_RW(ads->ctl18) = 0;
37300 + ACCESS_ONCE_RW(ads->ctl19) = 0;
37301 return;
37302 }
37303
37304 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
37305 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
37306 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
37307 | SM(i->txpower, AR_XmitPower)
37308 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
37309 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37310 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
37311 ctl12 |= SM(val, AR_PAPRDChainMask);
37312
37313 - ACCESS_ONCE(ads->ctl12) = ctl12;
37314 - ACCESS_ONCE(ads->ctl17) = ctl17;
37315 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
37316 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
37317
37318 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
37319 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
37320 | set11nPktDurRTSCTS(i->rates, 1);
37321
37322 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
37323 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
37324 | set11nPktDurRTSCTS(i->rates, 3);
37325
37326 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
37327 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
37328 | set11nRateFlags(i->rates, 1)
37329 | set11nRateFlags(i->rates, 2)
37330 | set11nRateFlags(i->rates, 3)
37331 | SM(i->rtscts_rate, AR_RTSCTSRate);
37332
37333 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
37334 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
37335 }
37336
37337 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
37338 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
37339 index dbc1b7a..67e2ca2 100644
37340 --- a/drivers/net/wireless/ath/ath9k/hw.h
37341 +++ b/drivers/net/wireless/ath/ath9k/hw.h
37342 @@ -657,7 +657,7 @@ struct ath_hw_private_ops {
37343
37344 /* ANI */
37345 void (*ani_cache_ini_regs)(struct ath_hw *ah);
37346 -};
37347 +} __no_const;
37348
37349 /**
37350 * struct ath_hw_ops - callbacks used by hardware code and driver code
37351 @@ -687,7 +687,7 @@ struct ath_hw_ops {
37352 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
37353 struct ath_hw_antcomb_conf *antconf);
37354 void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
37355 -};
37356 +} __no_const;
37357
37358 struct ath_nf_limits {
37359 s16 max;
37360 diff --git a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h
37361 index 71ced17..cd82b12 100644
37362 --- a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h
37363 +++ b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h
37364 @@ -184,7 +184,7 @@ struct brcmf_cfg80211_event_loop {
37365 struct net_device *ndev,
37366 const struct brcmf_event_msg *e,
37367 void *data);
37368 -};
37369 +} __no_const;
37370
37371 /* basic structure of scan request */
37372 struct brcmf_cfg80211_scan_req {
37373 @@ -239,7 +239,7 @@ struct brcmf_cfg80211_profile {
37374 struct brcmf_cfg80211_iscan_eloop {
37375 s32 (*handler[WL_SCAN_ERSULTS_LAST])
37376 (struct brcmf_cfg80211_info *cfg);
37377 -};
37378 +} __no_const;
37379
37380 /* dongle iscan controller */
37381 struct brcmf_cfg80211_iscan_ctrl {
37382 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
37383 index e252acb..6ad1e65 100644
37384 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
37385 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
37386 @@ -3615,7 +3615,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
37387 */
37388 if (il3945_mod_params.disable_hw_scan) {
37389 D_INFO("Disabling hw_scan\n");
37390 - il3945_mac_ops.hw_scan = NULL;
37391 + pax_open_kernel();
37392 + *(void **)&il3945_mac_ops.hw_scan = NULL;
37393 + pax_close_kernel();
37394 }
37395
37396 D_INFO("*** LOAD DRIVER ***\n");
37397 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
37398 index 1a98fa3..51e6661 100644
37399 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
37400 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
37401 @@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
37402 {
37403 struct iwl_priv *priv = file->private_data;
37404 char buf[64];
37405 - int buf_size;
37406 + size_t buf_size;
37407 u32 offset, len;
37408
37409 memset(buf, 0, sizeof(buf));
37410 @@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
37411 struct iwl_priv *priv = file->private_data;
37412
37413 char buf[8];
37414 - int buf_size;
37415 + size_t buf_size;
37416 u32 reset_flag;
37417
37418 memset(buf, 0, sizeof(buf));
37419 @@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
37420 {
37421 struct iwl_priv *priv = file->private_data;
37422 char buf[8];
37423 - int buf_size;
37424 + size_t buf_size;
37425 int ht40;
37426
37427 memset(buf, 0, sizeof(buf));
37428 @@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
37429 {
37430 struct iwl_priv *priv = file->private_data;
37431 char buf[8];
37432 - int buf_size;
37433 + size_t buf_size;
37434 int value;
37435
37436 memset(buf, 0, sizeof(buf));
37437 @@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
37438 {
37439 struct iwl_priv *priv = file->private_data;
37440 char buf[8];
37441 - int buf_size;
37442 + size_t buf_size;
37443 int clear;
37444
37445 memset(buf, 0, sizeof(buf));
37446 @@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
37447 {
37448 struct iwl_priv *priv = file->private_data;
37449 char buf[8];
37450 - int buf_size;
37451 + size_t buf_size;
37452 int trace;
37453
37454 memset(buf, 0, sizeof(buf));
37455 @@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
37456 {
37457 struct iwl_priv *priv = file->private_data;
37458 char buf[8];
37459 - int buf_size;
37460 + size_t buf_size;
37461 int missed;
37462
37463 memset(buf, 0, sizeof(buf));
37464 @@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
37465
37466 struct iwl_priv *priv = file->private_data;
37467 char buf[8];
37468 - int buf_size;
37469 + size_t buf_size;
37470 int plcp;
37471
37472 memset(buf, 0, sizeof(buf));
37473 @@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
37474
37475 struct iwl_priv *priv = file->private_data;
37476 char buf[8];
37477 - int buf_size;
37478 + size_t buf_size;
37479 int flush;
37480
37481 memset(buf, 0, sizeof(buf));
37482 @@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
37483
37484 struct iwl_priv *priv = file->private_data;
37485 char buf[8];
37486 - int buf_size;
37487 + size_t buf_size;
37488 int rts;
37489
37490 if (!priv->cfg->ht_params)
37491 @@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
37492 {
37493 struct iwl_priv *priv = file->private_data;
37494 char buf[8];
37495 - int buf_size;
37496 + size_t buf_size;
37497
37498 memset(buf, 0, sizeof(buf));
37499 buf_size = min(count, sizeof(buf) - 1);
37500 @@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
37501 struct iwl_priv *priv = file->private_data;
37502 u32 event_log_flag;
37503 char buf[8];
37504 - int buf_size;
37505 + size_t buf_size;
37506
37507 /* check that the interface is up */
37508 if (!iwl_is_ready(priv))
37509 @@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
37510 struct iwl_priv *priv = file->private_data;
37511 char buf[8];
37512 u32 calib_disabled;
37513 - int buf_size;
37514 + size_t buf_size;
37515
37516 memset(buf, 0, sizeof(buf));
37517 buf_size = min(count, sizeof(buf) - 1);
37518 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
37519 index fe0fffd..b4c5724 100644
37520 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
37521 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
37522 @@ -1967,7 +1967,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
37523 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
37524
37525 char buf[8];
37526 - int buf_size;
37527 + size_t buf_size;
37528 u32 reset_flag;
37529
37530 memset(buf, 0, sizeof(buf));
37531 @@ -1988,7 +1988,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
37532 {
37533 struct iwl_trans *trans = file->private_data;
37534 char buf[8];
37535 - int buf_size;
37536 + size_t buf_size;
37537 int csr;
37538
37539 memset(buf, 0, sizeof(buf));
37540 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
37541 index 429ca32..f86236b 100644
37542 --- a/drivers/net/wireless/mac80211_hwsim.c
37543 +++ b/drivers/net/wireless/mac80211_hwsim.c
37544 @@ -1751,9 +1751,11 @@ static int __init init_mac80211_hwsim(void)
37545 return -EINVAL;
37546
37547 if (fake_hw_scan) {
37548 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
37549 - mac80211_hwsim_ops.sw_scan_start = NULL;
37550 - mac80211_hwsim_ops.sw_scan_complete = NULL;
37551 + pax_open_kernel();
37552 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
37553 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
37554 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
37555 + pax_close_kernel();
37556 }
37557
37558 spin_lock_init(&hwsim_radio_lock);
37559 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
37560 index bd1f0cb..db85ab0 100644
37561 --- a/drivers/net/wireless/rndis_wlan.c
37562 +++ b/drivers/net/wireless/rndis_wlan.c
37563 @@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
37564
37565 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
37566
37567 - if (rts_threshold < 0 || rts_threshold > 2347)
37568 + if (rts_threshold > 2347)
37569 rts_threshold = 2347;
37570
37571 tmp = cpu_to_le32(rts_threshold);
37572 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
37573 index 0751b35..246ba3e 100644
37574 --- a/drivers/net/wireless/rt2x00/rt2x00.h
37575 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
37576 @@ -398,7 +398,7 @@ struct rt2x00_intf {
37577 * for hardware which doesn't support hardware
37578 * sequence counting.
37579 */
37580 - atomic_t seqno;
37581 + atomic_unchecked_t seqno;
37582 };
37583
37584 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
37585 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
37586 index e488b94..14b6a0c 100644
37587 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
37588 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
37589 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
37590 * sequence counter given by mac80211.
37591 */
37592 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
37593 - seqno = atomic_add_return(0x10, &intf->seqno);
37594 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
37595 else
37596 - seqno = atomic_read(&intf->seqno);
37597 + seqno = atomic_read_unchecked(&intf->seqno);
37598
37599 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
37600 hdr->seq_ctrl |= cpu_to_le16(seqno);
37601 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
37602 index e2750a1..797e179 100644
37603 --- a/drivers/net/wireless/ti/wl1251/sdio.c
37604 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
37605 @@ -269,13 +269,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
37606
37607 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
37608
37609 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
37610 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
37611 + pax_open_kernel();
37612 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
37613 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
37614 + pax_close_kernel();
37615
37616 wl1251_info("using dedicated interrupt line");
37617 } else {
37618 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
37619 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
37620 + pax_open_kernel();
37621 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
37622 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
37623 + pax_close_kernel();
37624
37625 wl1251_info("using SDIO interrupt");
37626 }
37627 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
37628 index dadf1db..d9db7a7 100644
37629 --- a/drivers/net/wireless/ti/wl12xx/main.c
37630 +++ b/drivers/net/wireless/ti/wl12xx/main.c
37631 @@ -644,7 +644,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
37632 sizeof(wl->conf.mem));
37633
37634 /* read data preparation is only needed by wl127x */
37635 - wl->ops->prepare_read = wl127x_prepare_read;
37636 + pax_open_kernel();
37637 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
37638 + pax_close_kernel();
37639
37640 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
37641 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
37642 @@ -665,7 +667,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
37643 sizeof(wl->conf.mem));
37644
37645 /* read data preparation is only needed by wl127x */
37646 - wl->ops->prepare_read = wl127x_prepare_read;
37647 + pax_open_kernel();
37648 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
37649 + pax_close_kernel();
37650
37651 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
37652 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
37653 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
37654 index a39682a..1e8220c 100644
37655 --- a/drivers/net/wireless/ti/wl18xx/main.c
37656 +++ b/drivers/net/wireless/ti/wl18xx/main.c
37657 @@ -1489,8 +1489,10 @@ static int wl18xx_setup(struct wl1271 *wl)
37658 }
37659
37660 if (!checksum_param) {
37661 - wl18xx_ops.set_rx_csum = NULL;
37662 - wl18xx_ops.init_vif = NULL;
37663 + pax_open_kernel();
37664 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
37665 + *(void **)&wl18xx_ops.init_vif = NULL;
37666 + pax_close_kernel();
37667 }
37668
37669 /* Enable 11a Band only if we have 5G antennas */
37670 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
37671 index d93b2b6..ae50401 100644
37672 --- a/drivers/oprofile/buffer_sync.c
37673 +++ b/drivers/oprofile/buffer_sync.c
37674 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
37675 if (cookie == NO_COOKIE)
37676 offset = pc;
37677 if (cookie == INVALID_COOKIE) {
37678 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
37679 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
37680 offset = pc;
37681 }
37682 if (cookie != last_cookie) {
37683 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
37684 /* add userspace sample */
37685
37686 if (!mm) {
37687 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
37688 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
37689 return 0;
37690 }
37691
37692 cookie = lookup_dcookie(mm, s->eip, &offset);
37693
37694 if (cookie == INVALID_COOKIE) {
37695 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
37696 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
37697 return 0;
37698 }
37699
37700 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
37701 /* ignore backtraces if failed to add a sample */
37702 if (state == sb_bt_start) {
37703 state = sb_bt_ignore;
37704 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
37705 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
37706 }
37707 }
37708 release_mm(mm);
37709 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
37710 index c0cc4e7..44d4e54 100644
37711 --- a/drivers/oprofile/event_buffer.c
37712 +++ b/drivers/oprofile/event_buffer.c
37713 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
37714 }
37715
37716 if (buffer_pos == buffer_size) {
37717 - atomic_inc(&oprofile_stats.event_lost_overflow);
37718 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
37719 return;
37720 }
37721
37722 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
37723 index ed2c3ec..deda85a 100644
37724 --- a/drivers/oprofile/oprof.c
37725 +++ b/drivers/oprofile/oprof.c
37726 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
37727 if (oprofile_ops.switch_events())
37728 return;
37729
37730 - atomic_inc(&oprofile_stats.multiplex_counter);
37731 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
37732 start_switch_worker();
37733 }
37734
37735 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
37736 index 917d28e..d62d981 100644
37737 --- a/drivers/oprofile/oprofile_stats.c
37738 +++ b/drivers/oprofile/oprofile_stats.c
37739 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
37740 cpu_buf->sample_invalid_eip = 0;
37741 }
37742
37743 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
37744 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
37745 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
37746 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
37747 - atomic_set(&oprofile_stats.multiplex_counter, 0);
37748 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
37749 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
37750 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
37751 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
37752 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
37753 }
37754
37755
37756 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
37757 index 38b6fc0..b5cbfce 100644
37758 --- a/drivers/oprofile/oprofile_stats.h
37759 +++ b/drivers/oprofile/oprofile_stats.h
37760 @@ -13,11 +13,11 @@
37761 #include <linux/atomic.h>
37762
37763 struct oprofile_stat_struct {
37764 - atomic_t sample_lost_no_mm;
37765 - atomic_t sample_lost_no_mapping;
37766 - atomic_t bt_lost_no_mapping;
37767 - atomic_t event_lost_overflow;
37768 - atomic_t multiplex_counter;
37769 + atomic_unchecked_t sample_lost_no_mm;
37770 + atomic_unchecked_t sample_lost_no_mapping;
37771 + atomic_unchecked_t bt_lost_no_mapping;
37772 + atomic_unchecked_t event_lost_overflow;
37773 + atomic_unchecked_t multiplex_counter;
37774 };
37775
37776 extern struct oprofile_stat_struct oprofile_stats;
37777 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
37778 index 849357c..b83c1e0 100644
37779 --- a/drivers/oprofile/oprofilefs.c
37780 +++ b/drivers/oprofile/oprofilefs.c
37781 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
37782
37783
37784 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
37785 - char const *name, atomic_t *val)
37786 + char const *name, atomic_unchecked_t *val)
37787 {
37788 return __oprofilefs_create_file(sb, root, name,
37789 &atomic_ro_fops, 0444, val);
37790 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
37791 index 3f56bc0..707d642 100644
37792 --- a/drivers/parport/procfs.c
37793 +++ b/drivers/parport/procfs.c
37794 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
37795
37796 *ppos += len;
37797
37798 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
37799 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
37800 }
37801
37802 #ifdef CONFIG_PARPORT_1284
37803 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
37804
37805 *ppos += len;
37806
37807 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
37808 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
37809 }
37810 #endif /* IEEE1284.3 support. */
37811
37812 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
37813 index a6a71c4..c91097b 100644
37814 --- a/drivers/pci/hotplug/cpcihp_generic.c
37815 +++ b/drivers/pci/hotplug/cpcihp_generic.c
37816 @@ -73,7 +73,6 @@ static u16 port;
37817 static unsigned int enum_bit;
37818 static u8 enum_mask;
37819
37820 -static struct cpci_hp_controller_ops generic_hpc_ops;
37821 static struct cpci_hp_controller generic_hpc;
37822
37823 static int __init validate_parameters(void)
37824 @@ -139,6 +138,10 @@ static int query_enum(void)
37825 return ((value & enum_mask) == enum_mask);
37826 }
37827
37828 +static struct cpci_hp_controller_ops generic_hpc_ops = {
37829 + .query_enum = query_enum,
37830 +};
37831 +
37832 static int __init cpcihp_generic_init(void)
37833 {
37834 int status;
37835 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
37836 pci_dev_put(dev);
37837
37838 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
37839 - generic_hpc_ops.query_enum = query_enum;
37840 generic_hpc.ops = &generic_hpc_ops;
37841
37842 status = cpci_hp_register_controller(&generic_hpc);
37843 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
37844 index 6bf8d2a..9711ce0 100644
37845 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
37846 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
37847 @@ -59,7 +59,6 @@
37848 /* local variables */
37849 static bool debug;
37850 static bool poll;
37851 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
37852 static struct cpci_hp_controller zt5550_hpc;
37853
37854 /* Primary cPCI bus bridge device */
37855 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
37856 return 0;
37857 }
37858
37859 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
37860 + .query_enum = zt5550_hc_query_enum,
37861 +};
37862 +
37863 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
37864 {
37865 int status;
37866 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
37867 dbg("returned from zt5550_hc_config");
37868
37869 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
37870 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
37871 zt5550_hpc.ops = &zt5550_hpc_ops;
37872 if(!poll) {
37873 zt5550_hpc.irq = hc_dev->irq;
37874 zt5550_hpc.irq_flags = IRQF_SHARED;
37875 zt5550_hpc.dev_id = hc_dev;
37876
37877 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
37878 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
37879 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
37880 + pax_open_kernel();
37881 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
37882 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
37883 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
37884 + pax_open_kernel();
37885 } else {
37886 info("using ENUM# polling mode");
37887 }
37888 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
37889 index 76ba8a1..20ca857 100644
37890 --- a/drivers/pci/hotplug/cpqphp_nvram.c
37891 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
37892 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
37893
37894 void compaq_nvram_init (void __iomem *rom_start)
37895 {
37896 +
37897 +#ifndef CONFIG_PAX_KERNEXEC
37898 if (rom_start) {
37899 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
37900 }
37901 +#endif
37902 +
37903 dbg("int15 entry = %p\n", compaq_int15_entry_point);
37904
37905 /* initialize our int15 lock */
37906 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
37907 index 449f257..0731e96 100644
37908 --- a/drivers/pci/pcie/aspm.c
37909 +++ b/drivers/pci/pcie/aspm.c
37910 @@ -27,9 +27,9 @@
37911 #define MODULE_PARAM_PREFIX "pcie_aspm."
37912
37913 /* Note: those are not register definitions */
37914 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
37915 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
37916 -#define ASPM_STATE_L1 (4) /* L1 state */
37917 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
37918 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
37919 +#define ASPM_STATE_L1 (4U) /* L1 state */
37920 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
37921 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
37922
37923 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
37924 index ec909af..e7517f3 100644
37925 --- a/drivers/pci/probe.c
37926 +++ b/drivers/pci/probe.c
37927 @@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
37928 struct pci_bus_region region;
37929 bool bar_too_big = false, bar_disabled = false;
37930
37931 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
37932 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
37933
37934 /* No printks while decoding is disabled! */
37935 if (!dev->mmio_always_on) {
37936 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
37937 index 9b8505c..f00870a 100644
37938 --- a/drivers/pci/proc.c
37939 +++ b/drivers/pci/proc.c
37940 @@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
37941 static int __init pci_proc_init(void)
37942 {
37943 struct pci_dev *dev = NULL;
37944 +
37945 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
37946 +#ifdef CONFIG_GRKERNSEC_PROC_USER
37947 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
37948 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
37949 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
37950 +#endif
37951 +#else
37952 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
37953 +#endif
37954 proc_create("devices", 0, proc_bus_pci_dir,
37955 &proc_bus_pci_dev_operations);
37956 proc_initialized = 1;
37957 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
37958 index 75dd651..2af4c9a 100644
37959 --- a/drivers/platform/x86/thinkpad_acpi.c
37960 +++ b/drivers/platform/x86/thinkpad_acpi.c
37961 @@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
37962 return 0;
37963 }
37964
37965 -void static hotkey_mask_warn_incomplete_mask(void)
37966 +static void hotkey_mask_warn_incomplete_mask(void)
37967 {
37968 /* log only what the user can fix... */
37969 const u32 wantedmask = hotkey_driver_mask &
37970 @@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
37971 }
37972 }
37973
37974 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37975 - struct tp_nvram_state *newn,
37976 - const u32 event_mask)
37977 -{
37978 -
37979 #define TPACPI_COMPARE_KEY(__scancode, __member) \
37980 do { \
37981 if ((event_mask & (1 << __scancode)) && \
37982 @@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37983 tpacpi_hotkey_send_key(__scancode); \
37984 } while (0)
37985
37986 - void issue_volchange(const unsigned int oldvol,
37987 - const unsigned int newvol)
37988 - {
37989 - unsigned int i = oldvol;
37990 +static void issue_volchange(const unsigned int oldvol,
37991 + const unsigned int newvol,
37992 + const u32 event_mask)
37993 +{
37994 + unsigned int i = oldvol;
37995
37996 - while (i > newvol) {
37997 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
37998 - i--;
37999 - }
38000 - while (i < newvol) {
38001 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
38002 - i++;
38003 - }
38004 + while (i > newvol) {
38005 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
38006 + i--;
38007 }
38008 + while (i < newvol) {
38009 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
38010 + i++;
38011 + }
38012 +}
38013
38014 - void issue_brightnesschange(const unsigned int oldbrt,
38015 - const unsigned int newbrt)
38016 - {
38017 - unsigned int i = oldbrt;
38018 +static void issue_brightnesschange(const unsigned int oldbrt,
38019 + const unsigned int newbrt,
38020 + const u32 event_mask)
38021 +{
38022 + unsigned int i = oldbrt;
38023
38024 - while (i > newbrt) {
38025 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
38026 - i--;
38027 - }
38028 - while (i < newbrt) {
38029 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
38030 - i++;
38031 - }
38032 + while (i > newbrt) {
38033 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
38034 + i--;
38035 + }
38036 + while (i < newbrt) {
38037 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
38038 + i++;
38039 }
38040 +}
38041
38042 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38043 + struct tp_nvram_state *newn,
38044 + const u32 event_mask)
38045 +{
38046 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
38047 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
38048 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
38049 @@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38050 oldn->volume_level != newn->volume_level) {
38051 /* recently muted, or repeated mute keypress, or
38052 * multiple presses ending in mute */
38053 - issue_volchange(oldn->volume_level, newn->volume_level);
38054 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
38055 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
38056 }
38057 } else {
38058 @@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38059 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
38060 }
38061 if (oldn->volume_level != newn->volume_level) {
38062 - issue_volchange(oldn->volume_level, newn->volume_level);
38063 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
38064 } else if (oldn->volume_toggle != newn->volume_toggle) {
38065 /* repeated vol up/down keypress at end of scale ? */
38066 if (newn->volume_level == 0)
38067 @@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38068 /* handle brightness */
38069 if (oldn->brightness_level != newn->brightness_level) {
38070 issue_brightnesschange(oldn->brightness_level,
38071 - newn->brightness_level);
38072 + newn->brightness_level,
38073 + event_mask);
38074 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
38075 /* repeated key presses that didn't change state */
38076 if (newn->brightness_level == 0)
38077 @@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38078 && !tp_features.bright_unkfw)
38079 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
38080 }
38081 +}
38082
38083 #undef TPACPI_COMPARE_KEY
38084 #undef TPACPI_MAY_SEND_KEY
38085 -}
38086
38087 /*
38088 * Polling driver
38089 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
38090 index 769d265..a3a05ca 100644
38091 --- a/drivers/pnp/pnpbios/bioscalls.c
38092 +++ b/drivers/pnp/pnpbios/bioscalls.c
38093 @@ -58,7 +58,7 @@ do { \
38094 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
38095 } while(0)
38096
38097 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
38098 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
38099 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
38100
38101 /*
38102 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
38103
38104 cpu = get_cpu();
38105 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
38106 +
38107 + pax_open_kernel();
38108 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
38109 + pax_close_kernel();
38110
38111 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
38112 spin_lock_irqsave(&pnp_bios_lock, flags);
38113 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
38114 :"memory");
38115 spin_unlock_irqrestore(&pnp_bios_lock, flags);
38116
38117 + pax_open_kernel();
38118 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
38119 + pax_close_kernel();
38120 +
38121 put_cpu();
38122
38123 /* If we get here and this is set then the PnP BIOS faulted on us. */
38124 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
38125 return status;
38126 }
38127
38128 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
38129 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
38130 {
38131 int i;
38132
38133 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
38134 pnp_bios_callpoint.offset = header->fields.pm16offset;
38135 pnp_bios_callpoint.segment = PNP_CS16;
38136
38137 + pax_open_kernel();
38138 +
38139 for_each_possible_cpu(i) {
38140 struct desc_struct *gdt = get_cpu_gdt_table(i);
38141 if (!gdt)
38142 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
38143 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
38144 (unsigned long)__va(header->fields.pm16dseg));
38145 }
38146 +
38147 + pax_close_kernel();
38148 }
38149 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
38150 index b0ecacb..7c9da2e 100644
38151 --- a/drivers/pnp/resource.c
38152 +++ b/drivers/pnp/resource.c
38153 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
38154 return 1;
38155
38156 /* check if the resource is valid */
38157 - if (*irq < 0 || *irq > 15)
38158 + if (*irq > 15)
38159 return 0;
38160
38161 /* check if the resource is reserved */
38162 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
38163 return 1;
38164
38165 /* check if the resource is valid */
38166 - if (*dma < 0 || *dma == 4 || *dma > 7)
38167 + if (*dma == 4 || *dma > 7)
38168 return 0;
38169
38170 /* check if the resource is reserved */
38171 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
38172 index 7df7c5f..bd48c47 100644
38173 --- a/drivers/power/pda_power.c
38174 +++ b/drivers/power/pda_power.c
38175 @@ -37,7 +37,11 @@ static int polling;
38176
38177 #ifdef CONFIG_USB_OTG_UTILS
38178 static struct usb_phy *transceiver;
38179 -static struct notifier_block otg_nb;
38180 +static int otg_handle_notification(struct notifier_block *nb,
38181 + unsigned long event, void *unused);
38182 +static struct notifier_block otg_nb = {
38183 + .notifier_call = otg_handle_notification
38184 +};
38185 #endif
38186
38187 static struct regulator *ac_draw;
38188 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
38189
38190 #ifdef CONFIG_USB_OTG_UTILS
38191 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
38192 - otg_nb.notifier_call = otg_handle_notification;
38193 ret = usb_register_notifier(transceiver, &otg_nb);
38194 if (ret) {
38195 dev_err(dev, "failure to register otg notifier\n");
38196 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
38197 index 8d53174..04c65de 100644
38198 --- a/drivers/regulator/max8660.c
38199 +++ b/drivers/regulator/max8660.c
38200 @@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
38201 max8660->shadow_regs[MAX8660_OVER1] = 5;
38202 } else {
38203 /* Otherwise devices can be toggled via software */
38204 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
38205 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
38206 + pax_open_kernel();
38207 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
38208 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
38209 + pax_close_kernel();
38210 }
38211
38212 /*
38213 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
38214 index 1fa6381..f58834e 100644
38215 --- a/drivers/regulator/mc13892-regulator.c
38216 +++ b/drivers/regulator/mc13892-regulator.c
38217 @@ -540,10 +540,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
38218 }
38219 mc13xxx_unlock(mc13892);
38220
38221 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
38222 + pax_open_kernel();
38223 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
38224 = mc13892_vcam_set_mode;
38225 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
38226 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
38227 = mc13892_vcam_get_mode;
38228 + pax_close_kernel();
38229
38230 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
38231 ARRAY_SIZE(mc13892_regulators));
38232 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
38233 index cace6d3..f623fda 100644
38234 --- a/drivers/rtc/rtc-dev.c
38235 +++ b/drivers/rtc/rtc-dev.c
38236 @@ -14,6 +14,7 @@
38237 #include <linux/module.h>
38238 #include <linux/rtc.h>
38239 #include <linux/sched.h>
38240 +#include <linux/grsecurity.h>
38241 #include "rtc-core.h"
38242
38243 static dev_t rtc_devt;
38244 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
38245 if (copy_from_user(&tm, uarg, sizeof(tm)))
38246 return -EFAULT;
38247
38248 + gr_log_timechange();
38249 +
38250 return rtc_set_time(rtc, &tm);
38251
38252 case RTC_PIE_ON:
38253 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
38254 index 4ad7e36..d004679 100644
38255 --- a/drivers/scsi/bfa/bfa.h
38256 +++ b/drivers/scsi/bfa/bfa.h
38257 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
38258 u32 *end);
38259 int cpe_vec_q0;
38260 int rme_vec_q0;
38261 -};
38262 +} __no_const;
38263 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
38264
38265 struct bfa_faa_cbfn_s {
38266 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
38267 index e693af6..2e525b6 100644
38268 --- a/drivers/scsi/bfa/bfa_fcpim.h
38269 +++ b/drivers/scsi/bfa/bfa_fcpim.h
38270 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
38271
38272 struct bfa_itn_s {
38273 bfa_isr_func_t isr;
38274 -};
38275 +} __no_const;
38276
38277 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
38278 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
38279 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
38280 index 23a90e7..9cf04ee 100644
38281 --- a/drivers/scsi/bfa/bfa_ioc.h
38282 +++ b/drivers/scsi/bfa/bfa_ioc.h
38283 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
38284 bfa_ioc_disable_cbfn_t disable_cbfn;
38285 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
38286 bfa_ioc_reset_cbfn_t reset_cbfn;
38287 -};
38288 +} __no_const;
38289
38290 /*
38291 * IOC event notification mechanism.
38292 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
38293 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
38294 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
38295 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
38296 -};
38297 +} __no_const;
38298
38299 /*
38300 * Queue element to wait for room in request queue. FIFO order is
38301 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
38302 index 593085a..47aa999 100644
38303 --- a/drivers/scsi/hosts.c
38304 +++ b/drivers/scsi/hosts.c
38305 @@ -42,7 +42,7 @@
38306 #include "scsi_logging.h"
38307
38308
38309 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
38310 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
38311
38312
38313 static void scsi_host_cls_release(struct device *dev)
38314 @@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
38315 * subtract one because we increment first then return, but we need to
38316 * know what the next host number was before increment
38317 */
38318 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
38319 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
38320 shost->dma_channel = 0xff;
38321
38322 /* These three are default values which can be overridden */
38323 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
38324 index 4217e49..9c77e3e 100644
38325 --- a/drivers/scsi/hpsa.c
38326 +++ b/drivers/scsi/hpsa.c
38327 @@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
38328 unsigned long flags;
38329
38330 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
38331 - return h->access.command_completed(h, q);
38332 + return h->access->command_completed(h, q);
38333
38334 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
38335 a = rq->head[rq->current_entry];
38336 @@ -3374,7 +3374,7 @@ static void start_io(struct ctlr_info *h)
38337 while (!list_empty(&h->reqQ)) {
38338 c = list_entry(h->reqQ.next, struct CommandList, list);
38339 /* can't do anything if fifo is full */
38340 - if ((h->access.fifo_full(h))) {
38341 + if ((h->access->fifo_full(h))) {
38342 dev_warn(&h->pdev->dev, "fifo full\n");
38343 break;
38344 }
38345 @@ -3396,7 +3396,7 @@ static void start_io(struct ctlr_info *h)
38346
38347 /* Tell the controller execute command */
38348 spin_unlock_irqrestore(&h->lock, flags);
38349 - h->access.submit_command(h, c);
38350 + h->access->submit_command(h, c);
38351 spin_lock_irqsave(&h->lock, flags);
38352 }
38353 spin_unlock_irqrestore(&h->lock, flags);
38354 @@ -3404,17 +3404,17 @@ static void start_io(struct ctlr_info *h)
38355
38356 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
38357 {
38358 - return h->access.command_completed(h, q);
38359 + return h->access->command_completed(h, q);
38360 }
38361
38362 static inline bool interrupt_pending(struct ctlr_info *h)
38363 {
38364 - return h->access.intr_pending(h);
38365 + return h->access->intr_pending(h);
38366 }
38367
38368 static inline long interrupt_not_for_us(struct ctlr_info *h)
38369 {
38370 - return (h->access.intr_pending(h) == 0) ||
38371 + return (h->access->intr_pending(h) == 0) ||
38372 (h->interrupts_enabled == 0);
38373 }
38374
38375 @@ -4318,7 +4318,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
38376 if (prod_index < 0)
38377 return -ENODEV;
38378 h->product_name = products[prod_index].product_name;
38379 - h->access = *(products[prod_index].access);
38380 + h->access = products[prod_index].access;
38381
38382 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
38383 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
38384 @@ -4600,7 +4600,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
38385
38386 assert_spin_locked(&lockup_detector_lock);
38387 remove_ctlr_from_lockup_detector_list(h);
38388 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
38389 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
38390 spin_lock_irqsave(&h->lock, flags);
38391 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
38392 spin_unlock_irqrestore(&h->lock, flags);
38393 @@ -4778,7 +4778,7 @@ reinit_after_soft_reset:
38394 }
38395
38396 /* make sure the board interrupts are off */
38397 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
38398 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
38399
38400 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
38401 goto clean2;
38402 @@ -4812,7 +4812,7 @@ reinit_after_soft_reset:
38403 * fake ones to scoop up any residual completions.
38404 */
38405 spin_lock_irqsave(&h->lock, flags);
38406 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
38407 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
38408 spin_unlock_irqrestore(&h->lock, flags);
38409 free_irqs(h);
38410 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
38411 @@ -4831,9 +4831,9 @@ reinit_after_soft_reset:
38412 dev_info(&h->pdev->dev, "Board READY.\n");
38413 dev_info(&h->pdev->dev,
38414 "Waiting for stale completions to drain.\n");
38415 - h->access.set_intr_mask(h, HPSA_INTR_ON);
38416 + h->access->set_intr_mask(h, HPSA_INTR_ON);
38417 msleep(10000);
38418 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
38419 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
38420
38421 rc = controller_reset_failed(h->cfgtable);
38422 if (rc)
38423 @@ -4854,7 +4854,7 @@ reinit_after_soft_reset:
38424 }
38425
38426 /* Turn the interrupts on so we can service requests */
38427 - h->access.set_intr_mask(h, HPSA_INTR_ON);
38428 + h->access->set_intr_mask(h, HPSA_INTR_ON);
38429
38430 hpsa_hba_inquiry(h);
38431 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
38432 @@ -4906,7 +4906,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
38433 * To write all data in the battery backed cache to disks
38434 */
38435 hpsa_flush_cache(h);
38436 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
38437 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
38438 hpsa_free_irqs_and_disable_msix(h);
38439 }
38440
38441 @@ -5075,7 +5075,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
38442 return;
38443 }
38444 /* Change the access methods to the performant access methods */
38445 - h->access = SA5_performant_access;
38446 + h->access = &SA5_performant_access;
38447 h->transMethod = CFGTBL_Trans_Performant;
38448 }
38449
38450 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
38451 index 9816479..c5d4e97 100644
38452 --- a/drivers/scsi/hpsa.h
38453 +++ b/drivers/scsi/hpsa.h
38454 @@ -79,7 +79,7 @@ struct ctlr_info {
38455 unsigned int msix_vector;
38456 unsigned int msi_vector;
38457 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
38458 - struct access_method access;
38459 + struct access_method *access;
38460
38461 /* queue and queue Info */
38462 struct list_head reqQ;
38463 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
38464 index c772d8d..35c362c 100644
38465 --- a/drivers/scsi/libfc/fc_exch.c
38466 +++ b/drivers/scsi/libfc/fc_exch.c
38467 @@ -100,12 +100,12 @@ struct fc_exch_mgr {
38468 u16 pool_max_index;
38469
38470 struct {
38471 - atomic_t no_free_exch;
38472 - atomic_t no_free_exch_xid;
38473 - atomic_t xid_not_found;
38474 - atomic_t xid_busy;
38475 - atomic_t seq_not_found;
38476 - atomic_t non_bls_resp;
38477 + atomic_unchecked_t no_free_exch;
38478 + atomic_unchecked_t no_free_exch_xid;
38479 + atomic_unchecked_t xid_not_found;
38480 + atomic_unchecked_t xid_busy;
38481 + atomic_unchecked_t seq_not_found;
38482 + atomic_unchecked_t non_bls_resp;
38483 } stats;
38484 };
38485
38486 @@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
38487 /* allocate memory for exchange */
38488 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
38489 if (!ep) {
38490 - atomic_inc(&mp->stats.no_free_exch);
38491 + atomic_inc_unchecked(&mp->stats.no_free_exch);
38492 goto out;
38493 }
38494 memset(ep, 0, sizeof(*ep));
38495 @@ -786,7 +786,7 @@ out:
38496 return ep;
38497 err:
38498 spin_unlock_bh(&pool->lock);
38499 - atomic_inc(&mp->stats.no_free_exch_xid);
38500 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
38501 mempool_free(ep, mp->ep_pool);
38502 return NULL;
38503 }
38504 @@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38505 xid = ntohs(fh->fh_ox_id); /* we originated exch */
38506 ep = fc_exch_find(mp, xid);
38507 if (!ep) {
38508 - atomic_inc(&mp->stats.xid_not_found);
38509 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38510 reject = FC_RJT_OX_ID;
38511 goto out;
38512 }
38513 @@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38514 ep = fc_exch_find(mp, xid);
38515 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
38516 if (ep) {
38517 - atomic_inc(&mp->stats.xid_busy);
38518 + atomic_inc_unchecked(&mp->stats.xid_busy);
38519 reject = FC_RJT_RX_ID;
38520 goto rel;
38521 }
38522 @@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38523 }
38524 xid = ep->xid; /* get our XID */
38525 } else if (!ep) {
38526 - atomic_inc(&mp->stats.xid_not_found);
38527 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38528 reject = FC_RJT_RX_ID; /* XID not found */
38529 goto out;
38530 }
38531 @@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38532 } else {
38533 sp = &ep->seq;
38534 if (sp->id != fh->fh_seq_id) {
38535 - atomic_inc(&mp->stats.seq_not_found);
38536 + atomic_inc_unchecked(&mp->stats.seq_not_found);
38537 if (f_ctl & FC_FC_END_SEQ) {
38538 /*
38539 * Update sequence_id based on incoming last
38540 @@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
38541
38542 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
38543 if (!ep) {
38544 - atomic_inc(&mp->stats.xid_not_found);
38545 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38546 goto out;
38547 }
38548 if (ep->esb_stat & ESB_ST_COMPLETE) {
38549 - atomic_inc(&mp->stats.xid_not_found);
38550 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38551 goto rel;
38552 }
38553 if (ep->rxid == FC_XID_UNKNOWN)
38554 ep->rxid = ntohs(fh->fh_rx_id);
38555 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
38556 - atomic_inc(&mp->stats.xid_not_found);
38557 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38558 goto rel;
38559 }
38560 if (ep->did != ntoh24(fh->fh_s_id) &&
38561 ep->did != FC_FID_FLOGI) {
38562 - atomic_inc(&mp->stats.xid_not_found);
38563 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38564 goto rel;
38565 }
38566 sof = fr_sof(fp);
38567 @@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
38568 sp->ssb_stat |= SSB_ST_RESP;
38569 sp->id = fh->fh_seq_id;
38570 } else if (sp->id != fh->fh_seq_id) {
38571 - atomic_inc(&mp->stats.seq_not_found);
38572 + atomic_inc_unchecked(&mp->stats.seq_not_found);
38573 goto rel;
38574 }
38575
38576 @@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
38577 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
38578
38579 if (!sp)
38580 - atomic_inc(&mp->stats.xid_not_found);
38581 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38582 else
38583 - atomic_inc(&mp->stats.non_bls_resp);
38584 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
38585
38586 fc_frame_free(fp);
38587 }
38588 @@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
38589
38590 list_for_each_entry(ema, &lport->ema_list, ema_list) {
38591 mp = ema->mp;
38592 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
38593 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
38594 st->fc_no_free_exch_xid +=
38595 - atomic_read(&mp->stats.no_free_exch_xid);
38596 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
38597 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
38598 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
38599 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
38600 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
38601 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
38602 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
38603 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
38604 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
38605 }
38606 }
38607 EXPORT_SYMBOL(fc_exch_update_stats);
38608 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
38609 index bdb81cd..d3c7c2c 100644
38610 --- a/drivers/scsi/libsas/sas_ata.c
38611 +++ b/drivers/scsi/libsas/sas_ata.c
38612 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
38613 .postreset = ata_std_postreset,
38614 .error_handler = ata_std_error_handler,
38615 .post_internal_cmd = sas_ata_post_internal,
38616 - .qc_defer = ata_std_qc_defer,
38617 + .qc_defer = ata_std_qc_defer,
38618 .qc_prep = ata_noop_qc_prep,
38619 .qc_issue = sas_ata_qc_issue,
38620 .qc_fill_rtf = sas_ata_qc_fill_rtf,
38621 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
38622 index 69b5993..1ac9dce 100644
38623 --- a/drivers/scsi/lpfc/lpfc.h
38624 +++ b/drivers/scsi/lpfc/lpfc.h
38625 @@ -424,7 +424,7 @@ struct lpfc_vport {
38626 struct dentry *debug_nodelist;
38627 struct dentry *vport_debugfs_root;
38628 struct lpfc_debugfs_trc *disc_trc;
38629 - atomic_t disc_trc_cnt;
38630 + atomic_unchecked_t disc_trc_cnt;
38631 #endif
38632 uint8_t stat_data_enabled;
38633 uint8_t stat_data_blocked;
38634 @@ -840,8 +840,8 @@ struct lpfc_hba {
38635 struct timer_list fabric_block_timer;
38636 unsigned long bit_flags;
38637 #define FABRIC_COMANDS_BLOCKED 0
38638 - atomic_t num_rsrc_err;
38639 - atomic_t num_cmd_success;
38640 + atomic_unchecked_t num_rsrc_err;
38641 + atomic_unchecked_t num_cmd_success;
38642 unsigned long last_rsrc_error_time;
38643 unsigned long last_ramp_down_time;
38644 unsigned long last_ramp_up_time;
38645 @@ -877,7 +877,7 @@ struct lpfc_hba {
38646
38647 struct dentry *debug_slow_ring_trc;
38648 struct lpfc_debugfs_trc *slow_ring_trc;
38649 - atomic_t slow_ring_trc_cnt;
38650 + atomic_unchecked_t slow_ring_trc_cnt;
38651 /* iDiag debugfs sub-directory */
38652 struct dentry *idiag_root;
38653 struct dentry *idiag_pci_cfg;
38654 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
38655 index f63f5ff..de29189 100644
38656 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
38657 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
38658 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
38659
38660 #include <linux/debugfs.h>
38661
38662 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
38663 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
38664 static unsigned long lpfc_debugfs_start_time = 0L;
38665
38666 /* iDiag */
38667 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
38668 lpfc_debugfs_enable = 0;
38669
38670 len = 0;
38671 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
38672 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
38673 (lpfc_debugfs_max_disc_trc - 1);
38674 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
38675 dtp = vport->disc_trc + i;
38676 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
38677 lpfc_debugfs_enable = 0;
38678
38679 len = 0;
38680 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
38681 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
38682 (lpfc_debugfs_max_slow_ring_trc - 1);
38683 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
38684 dtp = phba->slow_ring_trc + i;
38685 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
38686 !vport || !vport->disc_trc)
38687 return;
38688
38689 - index = atomic_inc_return(&vport->disc_trc_cnt) &
38690 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
38691 (lpfc_debugfs_max_disc_trc - 1);
38692 dtp = vport->disc_trc + index;
38693 dtp->fmt = fmt;
38694 dtp->data1 = data1;
38695 dtp->data2 = data2;
38696 dtp->data3 = data3;
38697 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
38698 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
38699 dtp->jif = jiffies;
38700 #endif
38701 return;
38702 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
38703 !phba || !phba->slow_ring_trc)
38704 return;
38705
38706 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
38707 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
38708 (lpfc_debugfs_max_slow_ring_trc - 1);
38709 dtp = phba->slow_ring_trc + index;
38710 dtp->fmt = fmt;
38711 dtp->data1 = data1;
38712 dtp->data2 = data2;
38713 dtp->data3 = data3;
38714 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
38715 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
38716 dtp->jif = jiffies;
38717 #endif
38718 return;
38719 @@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
38720 "slow_ring buffer\n");
38721 goto debug_failed;
38722 }
38723 - atomic_set(&phba->slow_ring_trc_cnt, 0);
38724 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
38725 memset(phba->slow_ring_trc, 0,
38726 (sizeof(struct lpfc_debugfs_trc) *
38727 lpfc_debugfs_max_slow_ring_trc));
38728 @@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
38729 "buffer\n");
38730 goto debug_failed;
38731 }
38732 - atomic_set(&vport->disc_trc_cnt, 0);
38733 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
38734
38735 snprintf(name, sizeof(name), "discovery_trace");
38736 vport->debug_disc_trc =
38737 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
38738 index 7dc4218..3436f08 100644
38739 --- a/drivers/scsi/lpfc/lpfc_init.c
38740 +++ b/drivers/scsi/lpfc/lpfc_init.c
38741 @@ -10589,8 +10589,10 @@ lpfc_init(void)
38742 "misc_register returned with status %d", error);
38743
38744 if (lpfc_enable_npiv) {
38745 - lpfc_transport_functions.vport_create = lpfc_vport_create;
38746 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
38747 + pax_open_kernel();
38748 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
38749 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
38750 + pax_close_kernel();
38751 }
38752 lpfc_transport_template =
38753 fc_attach_transport(&lpfc_transport_functions);
38754 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
38755 index 7f45ac9..cf62eda 100644
38756 --- a/drivers/scsi/lpfc/lpfc_scsi.c
38757 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
38758 @@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
38759 uint32_t evt_posted;
38760
38761 spin_lock_irqsave(&phba->hbalock, flags);
38762 - atomic_inc(&phba->num_rsrc_err);
38763 + atomic_inc_unchecked(&phba->num_rsrc_err);
38764 phba->last_rsrc_error_time = jiffies;
38765
38766 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
38767 @@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
38768 unsigned long flags;
38769 struct lpfc_hba *phba = vport->phba;
38770 uint32_t evt_posted;
38771 - atomic_inc(&phba->num_cmd_success);
38772 + atomic_inc_unchecked(&phba->num_cmd_success);
38773
38774 if (vport->cfg_lun_queue_depth <= queue_depth)
38775 return;
38776 @@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
38777 unsigned long num_rsrc_err, num_cmd_success;
38778 int i;
38779
38780 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
38781 - num_cmd_success = atomic_read(&phba->num_cmd_success);
38782 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
38783 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
38784
38785 /*
38786 * The error and success command counters are global per
38787 @@ -419,8 +419,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
38788 }
38789 }
38790 lpfc_destroy_vport_work_array(phba, vports);
38791 - atomic_set(&phba->num_rsrc_err, 0);
38792 - atomic_set(&phba->num_cmd_success, 0);
38793 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
38794 + atomic_set_unchecked(&phba->num_cmd_success, 0);
38795 }
38796
38797 /**
38798 @@ -454,8 +454,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
38799 }
38800 }
38801 lpfc_destroy_vport_work_array(phba, vports);
38802 - atomic_set(&phba->num_rsrc_err, 0);
38803 - atomic_set(&phba->num_cmd_success, 0);
38804 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
38805 + atomic_set_unchecked(&phba->num_cmd_success, 0);
38806 }
38807
38808 /**
38809 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
38810 index af763ea..41904f7 100644
38811 --- a/drivers/scsi/pmcraid.c
38812 +++ b/drivers/scsi/pmcraid.c
38813 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
38814 res->scsi_dev = scsi_dev;
38815 scsi_dev->hostdata = res;
38816 res->change_detected = 0;
38817 - atomic_set(&res->read_failures, 0);
38818 - atomic_set(&res->write_failures, 0);
38819 + atomic_set_unchecked(&res->read_failures, 0);
38820 + atomic_set_unchecked(&res->write_failures, 0);
38821 rc = 0;
38822 }
38823 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
38824 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
38825
38826 /* If this was a SCSI read/write command keep count of errors */
38827 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
38828 - atomic_inc(&res->read_failures);
38829 + atomic_inc_unchecked(&res->read_failures);
38830 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
38831 - atomic_inc(&res->write_failures);
38832 + atomic_inc_unchecked(&res->write_failures);
38833
38834 if (!RES_IS_GSCSI(res->cfg_entry) &&
38835 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
38836 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
38837 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
38838 * hrrq_id assigned here in queuecommand
38839 */
38840 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
38841 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
38842 pinstance->num_hrrq;
38843 cmd->cmd_done = pmcraid_io_done;
38844
38845 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
38846 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
38847 * hrrq_id assigned here in queuecommand
38848 */
38849 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
38850 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
38851 pinstance->num_hrrq;
38852
38853 if (request_size) {
38854 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
38855
38856 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
38857 /* add resources only after host is added into system */
38858 - if (!atomic_read(&pinstance->expose_resources))
38859 + if (!atomic_read_unchecked(&pinstance->expose_resources))
38860 return;
38861
38862 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
38863 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
38864 init_waitqueue_head(&pinstance->reset_wait_q);
38865
38866 atomic_set(&pinstance->outstanding_cmds, 0);
38867 - atomic_set(&pinstance->last_message_id, 0);
38868 - atomic_set(&pinstance->expose_resources, 0);
38869 + atomic_set_unchecked(&pinstance->last_message_id, 0);
38870 + atomic_set_unchecked(&pinstance->expose_resources, 0);
38871
38872 INIT_LIST_HEAD(&pinstance->free_res_q);
38873 INIT_LIST_HEAD(&pinstance->used_res_q);
38874 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
38875 /* Schedule worker thread to handle CCN and take care of adding and
38876 * removing devices to OS
38877 */
38878 - atomic_set(&pinstance->expose_resources, 1);
38879 + atomic_set_unchecked(&pinstance->expose_resources, 1);
38880 schedule_work(&pinstance->worker_q);
38881 return rc;
38882
38883 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
38884 index e1d150f..6c6df44 100644
38885 --- a/drivers/scsi/pmcraid.h
38886 +++ b/drivers/scsi/pmcraid.h
38887 @@ -748,7 +748,7 @@ struct pmcraid_instance {
38888 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
38889
38890 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
38891 - atomic_t last_message_id;
38892 + atomic_unchecked_t last_message_id;
38893
38894 /* configuration table */
38895 struct pmcraid_config_table *cfg_table;
38896 @@ -777,7 +777,7 @@ struct pmcraid_instance {
38897 atomic_t outstanding_cmds;
38898
38899 /* should add/delete resources to mid-layer now ?*/
38900 - atomic_t expose_resources;
38901 + atomic_unchecked_t expose_resources;
38902
38903
38904
38905 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
38906 struct pmcraid_config_table_entry_ext cfg_entry_ext;
38907 };
38908 struct scsi_device *scsi_dev; /* Link scsi_device structure */
38909 - atomic_t read_failures; /* count of failed READ commands */
38910 - atomic_t write_failures; /* count of failed WRITE commands */
38911 + atomic_unchecked_t read_failures; /* count of failed READ commands */
38912 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
38913
38914 /* To indicate add/delete/modify during CCN */
38915 u8 change_detected;
38916 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
38917 index 83d7984..a27d947 100644
38918 --- a/drivers/scsi/qla2xxx/qla_attr.c
38919 +++ b/drivers/scsi/qla2xxx/qla_attr.c
38920 @@ -1969,7 +1969,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
38921 return 0;
38922 }
38923
38924 -struct fc_function_template qla2xxx_transport_functions = {
38925 +fc_function_template_no_const qla2xxx_transport_functions = {
38926
38927 .show_host_node_name = 1,
38928 .show_host_port_name = 1,
38929 @@ -2016,7 +2016,7 @@ struct fc_function_template qla2xxx_transport_functions = {
38930 .bsg_timeout = qla24xx_bsg_timeout,
38931 };
38932
38933 -struct fc_function_template qla2xxx_transport_vport_functions = {
38934 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
38935
38936 .show_host_node_name = 1,
38937 .show_host_port_name = 1,
38938 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
38939 index 6acb397..d86e3e0 100644
38940 --- a/drivers/scsi/qla2xxx/qla_gbl.h
38941 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
38942 @@ -515,8 +515,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
38943 struct device_attribute;
38944 extern struct device_attribute *qla2x00_host_attrs[];
38945 struct fc_function_template;
38946 -extern struct fc_function_template qla2xxx_transport_functions;
38947 -extern struct fc_function_template qla2xxx_transport_vport_functions;
38948 +extern fc_function_template_no_const qla2xxx_transport_functions;
38949 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
38950 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
38951 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
38952 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
38953 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
38954 index f4b1fc8..a1ce4dd 100644
38955 --- a/drivers/scsi/qla2xxx/qla_os.c
38956 +++ b/drivers/scsi/qla2xxx/qla_os.c
38957 @@ -1462,8 +1462,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
38958 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
38959 /* Ok, a 64bit DMA mask is applicable. */
38960 ha->flags.enable_64bit_addressing = 1;
38961 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
38962 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
38963 + pax_open_kernel();
38964 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
38965 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
38966 + pax_close_kernel();
38967 return;
38968 }
38969 }
38970 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
38971 index 329d553..f20d31d 100644
38972 --- a/drivers/scsi/qla4xxx/ql4_def.h
38973 +++ b/drivers/scsi/qla4xxx/ql4_def.h
38974 @@ -273,7 +273,7 @@ struct ddb_entry {
38975 * (4000 only) */
38976 atomic_t relogin_timer; /* Max Time to wait for
38977 * relogin to complete */
38978 - atomic_t relogin_retry_count; /* Num of times relogin has been
38979 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
38980 * retried */
38981 uint32_t default_time2wait; /* Default Min time between
38982 * relogins (+aens) */
38983 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
38984 index fbc546e..c7d1b48 100644
38985 --- a/drivers/scsi/qla4xxx/ql4_os.c
38986 +++ b/drivers/scsi/qla4xxx/ql4_os.c
38987 @@ -2621,12 +2621,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
38988 */
38989 if (!iscsi_is_session_online(cls_sess)) {
38990 /* Reset retry relogin timer */
38991 - atomic_inc(&ddb_entry->relogin_retry_count);
38992 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
38993 DEBUG2(ql4_printk(KERN_INFO, ha,
38994 "%s: index[%d] relogin timed out-retrying"
38995 " relogin (%d), retry (%d)\n", __func__,
38996 ddb_entry->fw_ddb_index,
38997 - atomic_read(&ddb_entry->relogin_retry_count),
38998 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
38999 ddb_entry->default_time2wait + 4));
39000 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
39001 atomic_set(&ddb_entry->retry_relogin_timer,
39002 @@ -4738,7 +4738,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
39003
39004 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
39005 atomic_set(&ddb_entry->relogin_timer, 0);
39006 - atomic_set(&ddb_entry->relogin_retry_count, 0);
39007 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
39008 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
39009 ddb_entry->default_relogin_timeout =
39010 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
39011 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
39012 index 2c0d0ec..4e8681a 100644
39013 --- a/drivers/scsi/scsi.c
39014 +++ b/drivers/scsi/scsi.c
39015 @@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
39016 unsigned long timeout;
39017 int rtn = 0;
39018
39019 - atomic_inc(&cmd->device->iorequest_cnt);
39020 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
39021
39022 /* check if the device is still usable */
39023 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
39024 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
39025 index 9032e91..7a805d0 100644
39026 --- a/drivers/scsi/scsi_lib.c
39027 +++ b/drivers/scsi/scsi_lib.c
39028 @@ -1454,7 +1454,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
39029 shost = sdev->host;
39030 scsi_init_cmd_errh(cmd);
39031 cmd->result = DID_NO_CONNECT << 16;
39032 - atomic_inc(&cmd->device->iorequest_cnt);
39033 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
39034
39035 /*
39036 * SCSI request completion path will do scsi_device_unbusy(),
39037 @@ -1480,9 +1480,9 @@ static void scsi_softirq_done(struct request *rq)
39038
39039 INIT_LIST_HEAD(&cmd->eh_entry);
39040
39041 - atomic_inc(&cmd->device->iodone_cnt);
39042 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
39043 if (cmd->result)
39044 - atomic_inc(&cmd->device->ioerr_cnt);
39045 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
39046
39047 disposition = scsi_decide_disposition(cmd);
39048 if (disposition != SUCCESS &&
39049 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
39050 index 931a7d9..0c2a754 100644
39051 --- a/drivers/scsi/scsi_sysfs.c
39052 +++ b/drivers/scsi/scsi_sysfs.c
39053 @@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
39054 char *buf) \
39055 { \
39056 struct scsi_device *sdev = to_scsi_device(dev); \
39057 - unsigned long long count = atomic_read(&sdev->field); \
39058 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
39059 return snprintf(buf, 20, "0x%llx\n", count); \
39060 } \
39061 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
39062 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
39063 index 84a1fdf..693b0d6 100644
39064 --- a/drivers/scsi/scsi_tgt_lib.c
39065 +++ b/drivers/scsi/scsi_tgt_lib.c
39066 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
39067 int err;
39068
39069 dprintk("%lx %u\n", uaddr, len);
39070 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
39071 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
39072 if (err) {
39073 /*
39074 * TODO: need to fixup sg_tablesize, max_segment_size,
39075 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
39076 index e894ca7..de9d7660 100644
39077 --- a/drivers/scsi/scsi_transport_fc.c
39078 +++ b/drivers/scsi/scsi_transport_fc.c
39079 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
39080 * Netlink Infrastructure
39081 */
39082
39083 -static atomic_t fc_event_seq;
39084 +static atomic_unchecked_t fc_event_seq;
39085
39086 /**
39087 * fc_get_event_number - Obtain the next sequential FC event number
39088 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
39089 u32
39090 fc_get_event_number(void)
39091 {
39092 - return atomic_add_return(1, &fc_event_seq);
39093 + return atomic_add_return_unchecked(1, &fc_event_seq);
39094 }
39095 EXPORT_SYMBOL(fc_get_event_number);
39096
39097 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
39098 {
39099 int error;
39100
39101 - atomic_set(&fc_event_seq, 0);
39102 + atomic_set_unchecked(&fc_event_seq, 0);
39103
39104 error = transport_class_register(&fc_host_class);
39105 if (error)
39106 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
39107 char *cp;
39108
39109 *val = simple_strtoul(buf, &cp, 0);
39110 - if ((*cp && (*cp != '\n')) || (*val < 0))
39111 + if (*cp && (*cp != '\n'))
39112 return -EINVAL;
39113 /*
39114 * Check for overflow; dev_loss_tmo is u32
39115 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
39116 index 31969f2..2b348f0 100644
39117 --- a/drivers/scsi/scsi_transport_iscsi.c
39118 +++ b/drivers/scsi/scsi_transport_iscsi.c
39119 @@ -79,7 +79,7 @@ struct iscsi_internal {
39120 struct transport_container session_cont;
39121 };
39122
39123 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
39124 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
39125 static struct workqueue_struct *iscsi_eh_timer_workq;
39126
39127 static DEFINE_IDA(iscsi_sess_ida);
39128 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
39129 int err;
39130
39131 ihost = shost->shost_data;
39132 - session->sid = atomic_add_return(1, &iscsi_session_nr);
39133 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
39134
39135 if (target_id == ISCSI_MAX_TARGET) {
39136 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
39137 @@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
39138 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
39139 ISCSI_TRANSPORT_VERSION);
39140
39141 - atomic_set(&iscsi_session_nr, 0);
39142 + atomic_set_unchecked(&iscsi_session_nr, 0);
39143
39144 err = class_register(&iscsi_transport_class);
39145 if (err)
39146 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
39147 index 21a045e..ec89e03 100644
39148 --- a/drivers/scsi/scsi_transport_srp.c
39149 +++ b/drivers/scsi/scsi_transport_srp.c
39150 @@ -33,7 +33,7 @@
39151 #include "scsi_transport_srp_internal.h"
39152
39153 struct srp_host_attrs {
39154 - atomic_t next_port_id;
39155 + atomic_unchecked_t next_port_id;
39156 };
39157 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
39158
39159 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
39160 struct Scsi_Host *shost = dev_to_shost(dev);
39161 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
39162
39163 - atomic_set(&srp_host->next_port_id, 0);
39164 + atomic_set_unchecked(&srp_host->next_port_id, 0);
39165 return 0;
39166 }
39167
39168 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
39169 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
39170 rport->roles = ids->roles;
39171
39172 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
39173 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
39174 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
39175
39176 transport_setup_device(&rport->dev);
39177 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
39178 index a45e12a..d9120cb 100644
39179 --- a/drivers/scsi/sd.c
39180 +++ b/drivers/scsi/sd.c
39181 @@ -2899,7 +2899,7 @@ static int sd_probe(struct device *dev)
39182 sdkp->disk = gd;
39183 sdkp->index = index;
39184 atomic_set(&sdkp->openers, 0);
39185 - atomic_set(&sdkp->device->ioerr_cnt, 0);
39186 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
39187
39188 if (!sdp->request_queue->rq_timeout) {
39189 if (sdp->type != TYPE_MOD)
39190 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
39191 index be2c9a6..275525c 100644
39192 --- a/drivers/scsi/sg.c
39193 +++ b/drivers/scsi/sg.c
39194 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
39195 sdp->disk->disk_name,
39196 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
39197 NULL,
39198 - (char *)arg);
39199 + (char __user *)arg);
39200 case BLKTRACESTART:
39201 return blk_trace_startstop(sdp->device->request_queue, 1);
39202 case BLKTRACESTOP:
39203 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
39204 index 84c2861..ece0a31 100644
39205 --- a/drivers/spi/spi.c
39206 +++ b/drivers/spi/spi.c
39207 @@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
39208 EXPORT_SYMBOL_GPL(spi_bus_unlock);
39209
39210 /* portable code must never pass more than 32 bytes */
39211 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
39212 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
39213
39214 static u8 *buf;
39215
39216 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
39217 index 34afc16..ffe44dd 100644
39218 --- a/drivers/staging/octeon/ethernet-rx.c
39219 +++ b/drivers/staging/octeon/ethernet-rx.c
39220 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
39221 /* Increment RX stats for virtual ports */
39222 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
39223 #ifdef CONFIG_64BIT
39224 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
39225 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
39226 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
39227 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
39228 #else
39229 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
39230 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
39231 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
39232 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
39233 #endif
39234 }
39235 netif_receive_skb(skb);
39236 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
39237 dev->name);
39238 */
39239 #ifdef CONFIG_64BIT
39240 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
39241 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
39242 #else
39243 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
39244 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
39245 #endif
39246 dev_kfree_skb_irq(skb);
39247 }
39248 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
39249 index 683bedc..86dba9a 100644
39250 --- a/drivers/staging/octeon/ethernet.c
39251 +++ b/drivers/staging/octeon/ethernet.c
39252 @@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
39253 * since the RX tasklet also increments it.
39254 */
39255 #ifdef CONFIG_64BIT
39256 - atomic64_add(rx_status.dropped_packets,
39257 - (atomic64_t *)&priv->stats.rx_dropped);
39258 + atomic64_add_unchecked(rx_status.dropped_packets,
39259 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
39260 #else
39261 - atomic_add(rx_status.dropped_packets,
39262 - (atomic_t *)&priv->stats.rx_dropped);
39263 + atomic_add_unchecked(rx_status.dropped_packets,
39264 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
39265 #endif
39266 }
39267
39268 diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
39269 index a2b7e03..aaf3630 100644
39270 --- a/drivers/staging/ramster/tmem.c
39271 +++ b/drivers/staging/ramster/tmem.c
39272 @@ -50,25 +50,25 @@
39273 * A tmem host implementation must use this function to register callbacks
39274 * for memory allocation.
39275 */
39276 -static struct tmem_hostops tmem_hostops;
39277 +static struct tmem_hostops *tmem_hostops;
39278
39279 static void tmem_objnode_tree_init(void);
39280
39281 void tmem_register_hostops(struct tmem_hostops *m)
39282 {
39283 tmem_objnode_tree_init();
39284 - tmem_hostops = *m;
39285 + tmem_hostops = m;
39286 }
39287
39288 /*
39289 * A tmem host implementation must use this function to register
39290 * callbacks for a page-accessible memory (PAM) implementation.
39291 */
39292 -static struct tmem_pamops tmem_pamops;
39293 +static struct tmem_pamops *tmem_pamops;
39294
39295 void tmem_register_pamops(struct tmem_pamops *m)
39296 {
39297 - tmem_pamops = *m;
39298 + tmem_pamops = m;
39299 }
39300
39301 /*
39302 @@ -174,7 +174,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
39303 obj->pampd_count = 0;
39304 #ifdef CONFIG_RAMSTER
39305 if (tmem_pamops.new_obj != NULL)
39306 - (*tmem_pamops.new_obj)(obj);
39307 + (tmem_pamops->new_obj)(obj);
39308 #endif
39309 SET_SENTINEL(obj, OBJ);
39310
39311 @@ -210,7 +210,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
39312 rbnode = rb_next(rbnode);
39313 tmem_pampd_destroy_all_in_obj(obj, true);
39314 tmem_obj_free(obj, hb);
39315 - (*tmem_hostops.obj_free)(obj, pool);
39316 + (tmem_hostops->obj_free)(obj, pool);
39317 }
39318 spin_unlock(&hb->lock);
39319 }
39320 @@ -261,7 +261,7 @@ static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
39321 ASSERT_SENTINEL(obj, OBJ);
39322 BUG_ON(obj->pool == NULL);
39323 ASSERT_SENTINEL(obj->pool, POOL);
39324 - objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
39325 + objnode = (tmem_hostops->objnode_alloc)(obj->pool);
39326 if (unlikely(objnode == NULL))
39327 goto out;
39328 objnode->obj = obj;
39329 @@ -290,7 +290,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
39330 ASSERT_SENTINEL(pool, POOL);
39331 objnode->obj->objnode_count--;
39332 objnode->obj = NULL;
39333 - (*tmem_hostops.objnode_free)(objnode, pool);
39334 + (tmem_hostops->objnode_free)(objnode, pool);
39335 }
39336
39337 /*
39338 @@ -348,7 +348,7 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
39339 void *old_pampd = *(void **)slot;
39340 *(void **)slot = new_pampd;
39341 if (!no_free)
39342 - (*tmem_pamops.free)(old_pampd, obj->pool,
39343 + (tmem_pamops->free)(old_pampd, obj->pool,
39344 NULL, 0, false);
39345 ret = new_pampd;
39346 }
39347 @@ -505,7 +505,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
39348 if (objnode->slots[i]) {
39349 if (ht == 1) {
39350 obj->pampd_count--;
39351 - (*tmem_pamops.free)(objnode->slots[i],
39352 + (tmem_pamops->free)(objnode->slots[i],
39353 obj->pool, NULL, 0, true);
39354 objnode->slots[i] = NULL;
39355 continue;
39356 @@ -524,7 +524,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
39357 return;
39358 if (obj->objnode_tree_height == 0) {
39359 obj->pampd_count--;
39360 - (*tmem_pamops.free)(obj->objnode_tree_root,
39361 + (tmem_pamops->free)(obj->objnode_tree_root,
39362 obj->pool, NULL, 0, true);
39363 } else {
39364 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
39365 @@ -535,7 +535,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
39366 obj->objnode_tree_root = NULL;
39367 #ifdef CONFIG_RAMSTER
39368 if (tmem_pamops.free_obj != NULL)
39369 - (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
39370 + (tmem_pamops->free_obj)(obj->pool, obj, pool_destroy);
39371 #endif
39372 }
39373
39374 @@ -574,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
39375 /* if found, is a dup put, flush the old one */
39376 pampd_del = tmem_pampd_delete_from_obj(obj, index);
39377 BUG_ON(pampd_del != pampd);
39378 - (*tmem_pamops.free)(pampd, pool, oidp, index, true);
39379 + (tmem_pamops->free)(pampd, pool, oidp, index, true);
39380 if (obj->pampd_count == 0) {
39381 objnew = obj;
39382 objfound = NULL;
39383 @@ -582,7 +582,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
39384 pampd = NULL;
39385 }
39386 } else {
39387 - obj = objnew = (*tmem_hostops.obj_alloc)(pool);
39388 + obj = objnew = (tmem_hostops->obj_alloc)(pool);
39389 if (unlikely(obj == NULL)) {
39390 ret = -ENOMEM;
39391 goto out;
39392 @@ -597,16 +597,16 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
39393 if (unlikely(ret == -ENOMEM))
39394 /* may have partially built objnode tree ("stump") */
39395 goto delete_and_free;
39396 - (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
39397 + (tmem_pamops->create_finish)(pampd, is_ephemeral(pool));
39398 goto out;
39399
39400 delete_and_free:
39401 (void)tmem_pampd_delete_from_obj(obj, index);
39402 if (pampd)
39403 - (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
39404 + (tmem_pamops->free)(pampd, pool, NULL, 0, true);
39405 if (objnew) {
39406 tmem_obj_free(objnew, hb);
39407 - (*tmem_hostops.obj_free)(objnew, pool);
39408 + (tmem_hostops->obj_free)(objnew, pool);
39409 }
39410 out:
39411 spin_unlock(&hb->lock);
39412 @@ -651,7 +651,7 @@ void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
39413 if (pampd != NULL) {
39414 BUG_ON(obj == NULL);
39415 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
39416 - (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
39417 + (tmem_pamops->create_finish)(pampd, is_ephemeral(obj->pool));
39418 } else if (delete) {
39419 BUG_ON(obj == NULL);
39420 (void)tmem_pampd_delete_from_obj(obj, index);
39421 @@ -671,7 +671,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
39422 int ret = 0;
39423
39424 if (!is_ephemeral(pool))
39425 - new_pampd = (*tmem_pamops.repatriate_preload)(
39426 + new_pampd = (tmem_pamops->repatriate_preload)(
39427 old_pampd, pool, oidp, index, &intransit);
39428 if (intransit)
39429 ret = -EAGAIN;
39430 @@ -680,7 +680,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
39431 /* must release the hb->lock else repatriate can't sleep */
39432 spin_unlock(&hb->lock);
39433 if (!intransit)
39434 - ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
39435 + ret = (tmem_pamops->repatriate)(old_pampd, new_pampd, pool,
39436 oidp, index, free, data);
39437 if (ret == -EAGAIN) {
39438 /* rare I think, but should cond_resched()??? */
39439 @@ -714,7 +714,7 @@ int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
39440 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
39441 /* if we bug here, pamops wasn't properly set up for ramster */
39442 BUG_ON(tmem_pamops.replace_in_obj == NULL);
39443 - ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
39444 + ret = (tmem_pamops->replace_in_obj)(new_pampd, obj);
39445 out:
39446 spin_unlock(&hb->lock);
39447 return ret;
39448 @@ -776,15 +776,15 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
39449 if (free) {
39450 if (obj->pampd_count == 0) {
39451 tmem_obj_free(obj, hb);
39452 - (*tmem_hostops.obj_free)(obj, pool);
39453 + (tmem_hostops->obj_free)(obj, pool);
39454 obj = NULL;
39455 }
39456 }
39457 if (free)
39458 - ret = (*tmem_pamops.get_data_and_free)(
39459 + ret = (tmem_pamops->get_data_and_free)(
39460 data, sizep, raw, pampd, pool, oidp, index);
39461 else
39462 - ret = (*tmem_pamops.get_data)(
39463 + ret = (tmem_pamops->get_data)(
39464 data, sizep, raw, pampd, pool, oidp, index);
39465 if (ret < 0)
39466 goto out;
39467 @@ -816,10 +816,10 @@ int tmem_flush_page(struct tmem_pool *pool,
39468 pampd = tmem_pampd_delete_from_obj(obj, index);
39469 if (pampd == NULL)
39470 goto out;
39471 - (*tmem_pamops.free)(pampd, pool, oidp, index, true);
39472 + (tmem_pamops->free)(pampd, pool, oidp, index, true);
39473 if (obj->pampd_count == 0) {
39474 tmem_obj_free(obj, hb);
39475 - (*tmem_hostops.obj_free)(obj, pool);
39476 + (tmem_hostops->obj_free)(obj, pool);
39477 }
39478 ret = 0;
39479
39480 @@ -844,7 +844,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
39481 goto out;
39482 tmem_pampd_destroy_all_in_obj(obj, false);
39483 tmem_obj_free(obj, hb);
39484 - (*tmem_hostops.obj_free)(obj, pool);
39485 + (tmem_hostops->obj_free)(obj, pool);
39486 ret = 0;
39487
39488 out:
39489 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
39490 index dc23395..cf7e9b1 100644
39491 --- a/drivers/staging/rtl8712/rtl871x_io.h
39492 +++ b/drivers/staging/rtl8712/rtl871x_io.h
39493 @@ -108,7 +108,7 @@ struct _io_ops {
39494 u8 *pmem);
39495 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
39496 u8 *pmem);
39497 -};
39498 +} __no_const;
39499
39500 struct io_req {
39501 struct list_head list;
39502 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
39503 index 180c963..1f18377 100644
39504 --- a/drivers/staging/sbe-2t3e3/netdev.c
39505 +++ b/drivers/staging/sbe-2t3e3/netdev.c
39506 @@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39507 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
39508
39509 if (rlen)
39510 - if (copy_to_user(data, &resp, rlen))
39511 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
39512 return -EFAULT;
39513
39514 return 0;
39515 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
39516 index c66b8b3..a4a035b 100644
39517 --- a/drivers/staging/usbip/vhci.h
39518 +++ b/drivers/staging/usbip/vhci.h
39519 @@ -83,7 +83,7 @@ struct vhci_hcd {
39520 unsigned resuming:1;
39521 unsigned long re_timeout;
39522
39523 - atomic_t seqnum;
39524 + atomic_unchecked_t seqnum;
39525
39526 /*
39527 * NOTE:
39528 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
39529 index 620d1be..1cd6711 100644
39530 --- a/drivers/staging/usbip/vhci_hcd.c
39531 +++ b/drivers/staging/usbip/vhci_hcd.c
39532 @@ -471,7 +471,7 @@ static void vhci_tx_urb(struct urb *urb)
39533 return;
39534 }
39535
39536 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
39537 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
39538 if (priv->seqnum == 0xffff)
39539 dev_info(&urb->dev->dev, "seqnum max\n");
39540
39541 @@ -723,7 +723,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
39542 return -ENOMEM;
39543 }
39544
39545 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
39546 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
39547 if (unlink->seqnum == 0xffff)
39548 pr_info("seqnum max\n");
39549
39550 @@ -924,7 +924,7 @@ static int vhci_start(struct usb_hcd *hcd)
39551 vdev->rhport = rhport;
39552 }
39553
39554 - atomic_set(&vhci->seqnum, 0);
39555 + atomic_set_unchecked(&vhci->seqnum, 0);
39556 spin_lock_init(&vhci->lock);
39557
39558 hcd->power_budget = 0; /* no limit */
39559 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
39560 index f0eaf04..5a82e06 100644
39561 --- a/drivers/staging/usbip/vhci_rx.c
39562 +++ b/drivers/staging/usbip/vhci_rx.c
39563 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
39564 if (!urb) {
39565 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
39566 pr_info("max seqnum %d\n",
39567 - atomic_read(&the_controller->seqnum));
39568 + atomic_read_unchecked(&the_controller->seqnum));
39569 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
39570 return;
39571 }
39572 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
39573 index 67b1b88..6392fe9 100644
39574 --- a/drivers/staging/vt6655/hostap.c
39575 +++ b/drivers/staging/vt6655/hostap.c
39576 @@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
39577 *
39578 */
39579
39580 +static net_device_ops_no_const apdev_netdev_ops;
39581 +
39582 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39583 {
39584 PSDevice apdev_priv;
39585 struct net_device *dev = pDevice->dev;
39586 int ret;
39587 - const struct net_device_ops apdev_netdev_ops = {
39588 - .ndo_start_xmit = pDevice->tx_80211,
39589 - };
39590
39591 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
39592
39593 @@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39594 *apdev_priv = *pDevice;
39595 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
39596
39597 + /* only half broken now */
39598 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
39599 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
39600
39601 pDevice->apdev->type = ARPHRD_IEEE80211;
39602 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
39603 index 0a73d40..6fda560 100644
39604 --- a/drivers/staging/vt6656/hostap.c
39605 +++ b/drivers/staging/vt6656/hostap.c
39606 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
39607 *
39608 */
39609
39610 +static net_device_ops_no_const apdev_netdev_ops;
39611 +
39612 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39613 {
39614 PSDevice apdev_priv;
39615 struct net_device *dev = pDevice->dev;
39616 int ret;
39617 - const struct net_device_ops apdev_netdev_ops = {
39618 - .ndo_start_xmit = pDevice->tx_80211,
39619 - };
39620
39621 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
39622
39623 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39624 *apdev_priv = *pDevice;
39625 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
39626
39627 + /* only half broken now */
39628 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
39629 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
39630
39631 pDevice->apdev->type = ARPHRD_IEEE80211;
39632 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
39633 index 56c8e60..1920c63 100644
39634 --- a/drivers/staging/zcache/tmem.c
39635 +++ b/drivers/staging/zcache/tmem.c
39636 @@ -39,7 +39,7 @@
39637 * A tmem host implementation must use this function to register callbacks
39638 * for memory allocation.
39639 */
39640 -static struct tmem_hostops tmem_hostops;
39641 +static tmem_hostops_no_const tmem_hostops;
39642
39643 static void tmem_objnode_tree_init(void);
39644
39645 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
39646 * A tmem host implementation must use this function to register
39647 * callbacks for a page-accessible memory (PAM) implementation
39648 */
39649 -static struct tmem_pamops tmem_pamops;
39650 +static tmem_pamops_no_const tmem_pamops;
39651
39652 void tmem_register_pamops(struct tmem_pamops *m)
39653 {
39654 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
39655 index 0d4aa82..f7832d4 100644
39656 --- a/drivers/staging/zcache/tmem.h
39657 +++ b/drivers/staging/zcache/tmem.h
39658 @@ -180,6 +180,7 @@ struct tmem_pamops {
39659 void (*new_obj)(struct tmem_obj *);
39660 int (*replace_in_obj)(void *, struct tmem_obj *);
39661 };
39662 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
39663 extern void tmem_register_pamops(struct tmem_pamops *m);
39664
39665 /* memory allocation methods provided by the host implementation */
39666 @@ -189,6 +190,7 @@ struct tmem_hostops {
39667 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
39668 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
39669 };
39670 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
39671 extern void tmem_register_hostops(struct tmem_hostops *m);
39672
39673 /* core tmem accessor functions */
39674 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
39675 index 13fe16c..cbdc39a 100644
39676 --- a/drivers/target/target_core_transport.c
39677 +++ b/drivers/target/target_core_transport.c
39678 @@ -1085,7 +1085,7 @@ struct se_device *transport_add_device_to_core_hba(
39679 spin_lock_init(&dev->se_port_lock);
39680 spin_lock_init(&dev->se_tmr_lock);
39681 spin_lock_init(&dev->qf_cmd_lock);
39682 - atomic_set(&dev->dev_ordered_id, 0);
39683 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
39684
39685 se_dev_set_default_attribs(dev, dev_limits);
39686
39687 @@ -1275,7 +1275,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
39688 * Used to determine when ORDERED commands should go from
39689 * Dormant to Active status.
39690 */
39691 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
39692 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
39693 smp_mb__after_atomic_inc();
39694 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
39695 cmd->se_ordered_id, cmd->sam_task_attr,
39696 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
39697 index 0a6a0bc..5501b06 100644
39698 --- a/drivers/tty/cyclades.c
39699 +++ b/drivers/tty/cyclades.c
39700 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
39701 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
39702 info->port.count);
39703 #endif
39704 - info->port.count++;
39705 + atomic_inc(&info->port.count);
39706 #ifdef CY_DEBUG_COUNT
39707 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
39708 - current->pid, info->port.count);
39709 + current->pid, atomic_read(&info->port.count));
39710 #endif
39711
39712 /*
39713 @@ -3989,7 +3989,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
39714 for (j = 0; j < cy_card[i].nports; j++) {
39715 info = &cy_card[i].ports[j];
39716
39717 - if (info->port.count) {
39718 + if (atomic_read(&info->port.count)) {
39719 /* XXX is the ldisc num worth this? */
39720 struct tty_struct *tty;
39721 struct tty_ldisc *ld;
39722 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
39723 index 13ee53b..418d164 100644
39724 --- a/drivers/tty/hvc/hvc_console.c
39725 +++ b/drivers/tty/hvc/hvc_console.c
39726 @@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
39727
39728 spin_lock_irqsave(&hp->port.lock, flags);
39729 /* Check and then increment for fast path open. */
39730 - if (hp->port.count++ > 0) {
39731 + if (atomic_inc_return(&hp->port.count) > 1) {
39732 spin_unlock_irqrestore(&hp->port.lock, flags);
39733 hvc_kick();
39734 return 0;
39735 @@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
39736
39737 spin_lock_irqsave(&hp->port.lock, flags);
39738
39739 - if (--hp->port.count == 0) {
39740 + if (atomic_dec_return(&hp->port.count) == 0) {
39741 spin_unlock_irqrestore(&hp->port.lock, flags);
39742 /* We are done with the tty pointer now. */
39743 tty_port_tty_set(&hp->port, NULL);
39744 @@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
39745 */
39746 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
39747 } else {
39748 - if (hp->port.count < 0)
39749 + if (atomic_read(&hp->port.count) < 0)
39750 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
39751 - hp->vtermno, hp->port.count);
39752 + hp->vtermno, atomic_read(&hp->port.count));
39753 spin_unlock_irqrestore(&hp->port.lock, flags);
39754 }
39755 }
39756 @@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
39757 * open->hangup case this can be called after the final close so prevent
39758 * that from happening for now.
39759 */
39760 - if (hp->port.count <= 0) {
39761 + if (atomic_read(&hp->port.count) <= 0) {
39762 spin_unlock_irqrestore(&hp->port.lock, flags);
39763 return;
39764 }
39765
39766 - hp->port.count = 0;
39767 + atomic_set(&hp->port.count, 0);
39768 spin_unlock_irqrestore(&hp->port.lock, flags);
39769 tty_port_tty_set(&hp->port, NULL);
39770
39771 @@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
39772 return -EPIPE;
39773
39774 /* FIXME what's this (unprotected) check for? */
39775 - if (hp->port.count <= 0)
39776 + if (atomic_read(&hp->port.count) <= 0)
39777 return -EIO;
39778
39779 spin_lock_irqsave(&hp->lock, flags);
39780 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
39781 index cab5c7a..4cc66ea 100644
39782 --- a/drivers/tty/hvc/hvcs.c
39783 +++ b/drivers/tty/hvc/hvcs.c
39784 @@ -83,6 +83,7 @@
39785 #include <asm/hvcserver.h>
39786 #include <asm/uaccess.h>
39787 #include <asm/vio.h>
39788 +#include <asm/local.h>
39789
39790 /*
39791 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
39792 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
39793
39794 spin_lock_irqsave(&hvcsd->lock, flags);
39795
39796 - if (hvcsd->port.count > 0) {
39797 + if (atomic_read(&hvcsd->port.count) > 0) {
39798 spin_unlock_irqrestore(&hvcsd->lock, flags);
39799 printk(KERN_INFO "HVCS: vterm state unchanged. "
39800 "The hvcs device node is still in use.\n");
39801 @@ -1132,7 +1133,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
39802 }
39803 }
39804
39805 - hvcsd->port.count = 0;
39806 + atomic_set(&hvcsd->port.count, 0);
39807 hvcsd->port.tty = tty;
39808 tty->driver_data = hvcsd;
39809
39810 @@ -1185,7 +1186,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
39811 unsigned long flags;
39812
39813 spin_lock_irqsave(&hvcsd->lock, flags);
39814 - hvcsd->port.count++;
39815 + atomic_inc(&hvcsd->port.count);
39816 hvcsd->todo_mask |= HVCS_SCHED_READ;
39817 spin_unlock_irqrestore(&hvcsd->lock, flags);
39818
39819 @@ -1221,7 +1222,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
39820 hvcsd = tty->driver_data;
39821
39822 spin_lock_irqsave(&hvcsd->lock, flags);
39823 - if (--hvcsd->port.count == 0) {
39824 + if (atomic_dec_and_test(&hvcsd->port.count)) {
39825
39826 vio_disable_interrupts(hvcsd->vdev);
39827
39828 @@ -1246,10 +1247,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
39829
39830 free_irq(irq, hvcsd);
39831 return;
39832 - } else if (hvcsd->port.count < 0) {
39833 + } else if (atomic_read(&hvcsd->port.count) < 0) {
39834 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
39835 " is missmanaged.\n",
39836 - hvcsd->vdev->unit_address, hvcsd->port.count);
39837 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
39838 }
39839
39840 spin_unlock_irqrestore(&hvcsd->lock, flags);
39841 @@ -1271,7 +1272,7 @@ static void hvcs_hangup(struct tty_struct * tty)
39842
39843 spin_lock_irqsave(&hvcsd->lock, flags);
39844 /* Preserve this so that we know how many kref refs to put */
39845 - temp_open_count = hvcsd->port.count;
39846 + temp_open_count = atomic_read(&hvcsd->port.count);
39847
39848 /*
39849 * Don't kref put inside the spinlock because the destruction
39850 @@ -1286,7 +1287,7 @@ static void hvcs_hangup(struct tty_struct * tty)
39851 tty->driver_data = NULL;
39852 hvcsd->port.tty = NULL;
39853
39854 - hvcsd->port.count = 0;
39855 + atomic_set(&hvcsd->port.count, 0);
39856
39857 /* This will drop any buffered data on the floor which is OK in a hangup
39858 * scenario. */
39859 @@ -1357,7 +1358,7 @@ static int hvcs_write(struct tty_struct *tty,
39860 * the middle of a write operation? This is a crummy place to do this
39861 * but we want to keep it all in the spinlock.
39862 */
39863 - if (hvcsd->port.count <= 0) {
39864 + if (atomic_read(&hvcsd->port.count) <= 0) {
39865 spin_unlock_irqrestore(&hvcsd->lock, flags);
39866 return -ENODEV;
39867 }
39868 @@ -1431,7 +1432,7 @@ static int hvcs_write_room(struct tty_struct *tty)
39869 {
39870 struct hvcs_struct *hvcsd = tty->driver_data;
39871
39872 - if (!hvcsd || hvcsd->port.count <= 0)
39873 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
39874 return 0;
39875
39876 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
39877 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
39878 index 160f0ad..588b853 100644
39879 --- a/drivers/tty/ipwireless/tty.c
39880 +++ b/drivers/tty/ipwireless/tty.c
39881 @@ -29,6 +29,7 @@
39882 #include <linux/tty_driver.h>
39883 #include <linux/tty_flip.h>
39884 #include <linux/uaccess.h>
39885 +#include <asm/local.h>
39886
39887 #include "tty.h"
39888 #include "network.h"
39889 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
39890 mutex_unlock(&tty->ipw_tty_mutex);
39891 return -ENODEV;
39892 }
39893 - if (tty->port.count == 0)
39894 + if (atomic_read(&tty->port.count) == 0)
39895 tty->tx_bytes_queued = 0;
39896
39897 - tty->port.count++;
39898 + atomic_inc(&tty->port.count);
39899
39900 tty->port.tty = linux_tty;
39901 linux_tty->driver_data = tty;
39902 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
39903
39904 static void do_ipw_close(struct ipw_tty *tty)
39905 {
39906 - tty->port.count--;
39907 -
39908 - if (tty->port.count == 0) {
39909 + if (atomic_dec_return(&tty->port.count) == 0) {
39910 struct tty_struct *linux_tty = tty->port.tty;
39911
39912 if (linux_tty != NULL) {
39913 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
39914 return;
39915
39916 mutex_lock(&tty->ipw_tty_mutex);
39917 - if (tty->port.count == 0) {
39918 + if (atomic_read(&tty->port.count) == 0) {
39919 mutex_unlock(&tty->ipw_tty_mutex);
39920 return;
39921 }
39922 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
39923 return;
39924 }
39925
39926 - if (!tty->port.count) {
39927 + if (!atomic_read(&tty->port.count)) {
39928 mutex_unlock(&tty->ipw_tty_mutex);
39929 return;
39930 }
39931 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
39932 return -ENODEV;
39933
39934 mutex_lock(&tty->ipw_tty_mutex);
39935 - if (!tty->port.count) {
39936 + if (!atomic_read(&tty->port.count)) {
39937 mutex_unlock(&tty->ipw_tty_mutex);
39938 return -EINVAL;
39939 }
39940 @@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
39941 if (!tty)
39942 return -ENODEV;
39943
39944 - if (!tty->port.count)
39945 + if (!atomic_read(&tty->port.count))
39946 return -EINVAL;
39947
39948 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
39949 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
39950 if (!tty)
39951 return 0;
39952
39953 - if (!tty->port.count)
39954 + if (!atomic_read(&tty->port.count))
39955 return 0;
39956
39957 return tty->tx_bytes_queued;
39958 @@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
39959 if (!tty)
39960 return -ENODEV;
39961
39962 - if (!tty->port.count)
39963 + if (!atomic_read(&tty->port.count))
39964 return -EINVAL;
39965
39966 return get_control_lines(tty);
39967 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
39968 if (!tty)
39969 return -ENODEV;
39970
39971 - if (!tty->port.count)
39972 + if (!atomic_read(&tty->port.count))
39973 return -EINVAL;
39974
39975 return set_control_lines(tty, set, clear);
39976 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
39977 if (!tty)
39978 return -ENODEV;
39979
39980 - if (!tty->port.count)
39981 + if (!atomic_read(&tty->port.count))
39982 return -EINVAL;
39983
39984 /* FIXME: Exactly how is the tty object locked here .. */
39985 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
39986 * are gone */
39987 mutex_lock(&ttyj->ipw_tty_mutex);
39988 }
39989 - while (ttyj->port.count)
39990 + while (atomic_read(&ttyj->port.count))
39991 do_ipw_close(ttyj);
39992 ipwireless_disassociate_network_ttys(network,
39993 ttyj->channel_idx);
39994 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
39995 index 56e616b..9d9f10a 100644
39996 --- a/drivers/tty/moxa.c
39997 +++ b/drivers/tty/moxa.c
39998 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
39999 }
40000
40001 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
40002 - ch->port.count++;
40003 + atomic_inc(&ch->port.count);
40004 tty->driver_data = ch;
40005 tty_port_tty_set(&ch->port, tty);
40006 mutex_lock(&ch->port.mutex);
40007 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
40008 index 1e8e8ce..a9efc93 100644
40009 --- a/drivers/tty/n_gsm.c
40010 +++ b/drivers/tty/n_gsm.c
40011 @@ -1638,7 +1638,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
40012 kref_init(&dlci->ref);
40013 mutex_init(&dlci->mutex);
40014 dlci->fifo = &dlci->_fifo;
40015 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
40016 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
40017 kfree(dlci);
40018 return NULL;
40019 }
40020 @@ -2925,7 +2925,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
40021 struct gsm_dlci *dlci = tty->driver_data;
40022 struct tty_port *port = &dlci->port;
40023
40024 - port->count++;
40025 + atomic_inc(&port->count);
40026 dlci_get(dlci);
40027 dlci_get(dlci->gsm->dlci[0]);
40028 mux_get(dlci->gsm);
40029 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
40030 index 8c0b7b4..e88f052 100644
40031 --- a/drivers/tty/n_tty.c
40032 +++ b/drivers/tty/n_tty.c
40033 @@ -2142,6 +2142,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
40034 {
40035 *ops = tty_ldisc_N_TTY;
40036 ops->owner = NULL;
40037 - ops->refcount = ops->flags = 0;
40038 + atomic_set(&ops->refcount, 0);
40039 + ops->flags = 0;
40040 }
40041 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
40042 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
40043 index 8cf8d0a..4ef9ed0 100644
40044 --- a/drivers/tty/pty.c
40045 +++ b/drivers/tty/pty.c
40046 @@ -730,8 +730,10 @@ static void __init unix98_pty_init(void)
40047 panic("Couldn't register Unix98 pts driver");
40048
40049 /* Now create the /dev/ptmx special device */
40050 + pax_open_kernel();
40051 tty_default_fops(&ptmx_fops);
40052 - ptmx_fops.open = ptmx_open;
40053 + *(void **)&ptmx_fops.open = ptmx_open;
40054 + pax_close_kernel();
40055
40056 cdev_init(&ptmx_cdev, &ptmx_fops);
40057 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
40058 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
40059 index 9700d34..df7520c 100644
40060 --- a/drivers/tty/rocket.c
40061 +++ b/drivers/tty/rocket.c
40062 @@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
40063 tty->driver_data = info;
40064 tty_port_tty_set(port, tty);
40065
40066 - if (port->count++ == 0) {
40067 + if (atomic_inc_return(&port->count) == 1) {
40068 atomic_inc(&rp_num_ports_open);
40069
40070 #ifdef ROCKET_DEBUG_OPEN
40071 @@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
40072 #endif
40073 }
40074 #ifdef ROCKET_DEBUG_OPEN
40075 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
40076 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
40077 #endif
40078
40079 /*
40080 @@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
40081 spin_unlock_irqrestore(&info->port.lock, flags);
40082 return;
40083 }
40084 - if (info->port.count)
40085 + if (atomic_read(&info->port.count))
40086 atomic_dec(&rp_num_ports_open);
40087 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
40088 spin_unlock_irqrestore(&info->port.lock, flags);
40089 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
40090 index 1002054..dd644a8 100644
40091 --- a/drivers/tty/serial/kgdboc.c
40092 +++ b/drivers/tty/serial/kgdboc.c
40093 @@ -24,8 +24,9 @@
40094 #define MAX_CONFIG_LEN 40
40095
40096 static struct kgdb_io kgdboc_io_ops;
40097 +static struct kgdb_io kgdboc_io_ops_console;
40098
40099 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
40100 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
40101 static int configured = -1;
40102
40103 static char config[MAX_CONFIG_LEN];
40104 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
40105 kgdboc_unregister_kbd();
40106 if (configured == 1)
40107 kgdb_unregister_io_module(&kgdboc_io_ops);
40108 + else if (configured == 2)
40109 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
40110 }
40111
40112 static int configure_kgdboc(void)
40113 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
40114 int err;
40115 char *cptr = config;
40116 struct console *cons;
40117 + int is_console = 0;
40118
40119 err = kgdboc_option_setup(config);
40120 if (err || !strlen(config) || isspace(config[0]))
40121 goto noconfig;
40122
40123 err = -ENODEV;
40124 - kgdboc_io_ops.is_console = 0;
40125 kgdb_tty_driver = NULL;
40126
40127 kgdboc_use_kms = 0;
40128 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
40129 int idx;
40130 if (cons->device && cons->device(cons, &idx) == p &&
40131 idx == tty_line) {
40132 - kgdboc_io_ops.is_console = 1;
40133 + is_console = 1;
40134 break;
40135 }
40136 cons = cons->next;
40137 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
40138 kgdb_tty_line = tty_line;
40139
40140 do_register:
40141 - err = kgdb_register_io_module(&kgdboc_io_ops);
40142 + if (is_console) {
40143 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
40144 + configured = 2;
40145 + } else {
40146 + err = kgdb_register_io_module(&kgdboc_io_ops);
40147 + configured = 1;
40148 + }
40149 if (err)
40150 goto noconfig;
40151
40152 @@ -205,8 +214,6 @@ do_register:
40153 if (err)
40154 goto nmi_con_failed;
40155
40156 - configured = 1;
40157 -
40158 return 0;
40159
40160 nmi_con_failed:
40161 @@ -223,7 +230,7 @@ noconfig:
40162 static int __init init_kgdboc(void)
40163 {
40164 /* Already configured? */
40165 - if (configured == 1)
40166 + if (configured >= 1)
40167 return 0;
40168
40169 return configure_kgdboc();
40170 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
40171 if (config[len - 1] == '\n')
40172 config[len - 1] = '\0';
40173
40174 - if (configured == 1)
40175 + if (configured >= 1)
40176 cleanup_kgdboc();
40177
40178 /* Go and configure with the new params. */
40179 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
40180 .post_exception = kgdboc_post_exp_handler,
40181 };
40182
40183 +static struct kgdb_io kgdboc_io_ops_console = {
40184 + .name = "kgdboc",
40185 + .read_char = kgdboc_get_char,
40186 + .write_char = kgdboc_put_char,
40187 + .pre_exception = kgdboc_pre_exp_handler,
40188 + .post_exception = kgdboc_post_exp_handler,
40189 + .is_console = 1
40190 +};
40191 +
40192 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
40193 /* This is only available if kgdboc is a built in for early debugging */
40194 static int __init kgdboc_early_init(char *opt)
40195 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
40196 index 7f04717..0f3794f 100644
40197 --- a/drivers/tty/serial/samsung.c
40198 +++ b/drivers/tty/serial/samsung.c
40199 @@ -445,11 +445,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
40200 }
40201 }
40202
40203 +static int s3c64xx_serial_startup(struct uart_port *port);
40204 static int s3c24xx_serial_startup(struct uart_port *port)
40205 {
40206 struct s3c24xx_uart_port *ourport = to_ourport(port);
40207 int ret;
40208
40209 + /* Startup sequence is different for s3c64xx and higher SoC's */
40210 + if (s3c24xx_serial_has_interrupt_mask(port))
40211 + return s3c64xx_serial_startup(port);
40212 +
40213 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
40214 port->mapbase, port->membase);
40215
40216 @@ -1115,10 +1120,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
40217 /* setup info for port */
40218 port->dev = &platdev->dev;
40219
40220 - /* Startup sequence is different for s3c64xx and higher SoC's */
40221 - if (s3c24xx_serial_has_interrupt_mask(port))
40222 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
40223 -
40224 port->uartclk = 1;
40225
40226 if (cfg->uart_flags & UPF_CONS_FLOW) {
40227 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
40228 index 0fcfd98..8244fce 100644
40229 --- a/drivers/tty/serial/serial_core.c
40230 +++ b/drivers/tty/serial/serial_core.c
40231 @@ -1408,7 +1408,7 @@ static void uart_hangup(struct tty_struct *tty)
40232 uart_flush_buffer(tty);
40233 uart_shutdown(tty, state);
40234 spin_lock_irqsave(&port->lock, flags);
40235 - port->count = 0;
40236 + atomic_set(&port->count, 0);
40237 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
40238 spin_unlock_irqrestore(&port->lock, flags);
40239 tty_port_tty_set(port, NULL);
40240 @@ -1504,7 +1504,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
40241 goto end;
40242 }
40243
40244 - port->count++;
40245 + atomic_inc(&port->count);
40246 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
40247 retval = -ENXIO;
40248 goto err_dec_count;
40249 @@ -1531,7 +1531,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
40250 /*
40251 * Make sure the device is in D0 state.
40252 */
40253 - if (port->count == 1)
40254 + if (atomic_read(&port->count) == 1)
40255 uart_change_pm(state, 0);
40256
40257 /*
40258 @@ -1549,7 +1549,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
40259 end:
40260 return retval;
40261 err_dec_count:
40262 - port->count--;
40263 + atomic_inc(&port->count);
40264 mutex_unlock(&port->mutex);
40265 goto end;
40266 }
40267 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
40268 index 70e3a52..5742052 100644
40269 --- a/drivers/tty/synclink.c
40270 +++ b/drivers/tty/synclink.c
40271 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
40272
40273 if (debug_level >= DEBUG_LEVEL_INFO)
40274 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
40275 - __FILE__,__LINE__, info->device_name, info->port.count);
40276 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
40277
40278 if (tty_port_close_start(&info->port, tty, filp) == 0)
40279 goto cleanup;
40280 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
40281 cleanup:
40282 if (debug_level >= DEBUG_LEVEL_INFO)
40283 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
40284 - tty->driver->name, info->port.count);
40285 + tty->driver->name, atomic_read(&info->port.count));
40286
40287 } /* end of mgsl_close() */
40288
40289 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
40290
40291 mgsl_flush_buffer(tty);
40292 shutdown(info);
40293 -
40294 - info->port.count = 0;
40295 +
40296 + atomic_set(&info->port.count, 0);
40297 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
40298 info->port.tty = NULL;
40299
40300 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
40301
40302 if (debug_level >= DEBUG_LEVEL_INFO)
40303 printk("%s(%d):block_til_ready before block on %s count=%d\n",
40304 - __FILE__,__LINE__, tty->driver->name, port->count );
40305 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40306
40307 spin_lock_irqsave(&info->irq_spinlock, flags);
40308 if (!tty_hung_up_p(filp)) {
40309 extra_count = true;
40310 - port->count--;
40311 + atomic_dec(&port->count);
40312 }
40313 spin_unlock_irqrestore(&info->irq_spinlock, flags);
40314 port->blocked_open++;
40315 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
40316
40317 if (debug_level >= DEBUG_LEVEL_INFO)
40318 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
40319 - __FILE__,__LINE__, tty->driver->name, port->count );
40320 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40321
40322 tty_unlock(tty);
40323 schedule();
40324 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
40325
40326 /* FIXME: Racy on hangup during close wait */
40327 if (extra_count)
40328 - port->count++;
40329 + atomic_inc(&port->count);
40330 port->blocked_open--;
40331
40332 if (debug_level >= DEBUG_LEVEL_INFO)
40333 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
40334 - __FILE__,__LINE__, tty->driver->name, port->count );
40335 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40336
40337 if (!retval)
40338 port->flags |= ASYNC_NORMAL_ACTIVE;
40339 @@ -3405,7 +3405,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
40340
40341 if (debug_level >= DEBUG_LEVEL_INFO)
40342 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
40343 - __FILE__,__LINE__,tty->driver->name, info->port.count);
40344 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
40345
40346 /* If port is closing, signal caller to try again */
40347 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
40348 @@ -3424,10 +3424,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
40349 spin_unlock_irqrestore(&info->netlock, flags);
40350 goto cleanup;
40351 }
40352 - info->port.count++;
40353 + atomic_inc(&info->port.count);
40354 spin_unlock_irqrestore(&info->netlock, flags);
40355
40356 - if (info->port.count == 1) {
40357 + if (atomic_read(&info->port.count) == 1) {
40358 /* 1st open on this device, init hardware */
40359 retval = startup(info);
40360 if (retval < 0)
40361 @@ -3451,8 +3451,8 @@ cleanup:
40362 if (retval) {
40363 if (tty->count == 1)
40364 info->port.tty = NULL; /* tty layer will release tty struct */
40365 - if(info->port.count)
40366 - info->port.count--;
40367 + if (atomic_read(&info->port.count))
40368 + atomic_dec(&info->port.count);
40369 }
40370
40371 return retval;
40372 @@ -7661,7 +7661,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
40373 unsigned short new_crctype;
40374
40375 /* return error if TTY interface open */
40376 - if (info->port.count)
40377 + if (atomic_read(&info->port.count))
40378 return -EBUSY;
40379
40380 switch (encoding)
40381 @@ -7756,7 +7756,7 @@ static int hdlcdev_open(struct net_device *dev)
40382
40383 /* arbitrate between network and tty opens */
40384 spin_lock_irqsave(&info->netlock, flags);
40385 - if (info->port.count != 0 || info->netcount != 0) {
40386 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40387 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
40388 spin_unlock_irqrestore(&info->netlock, flags);
40389 return -EBUSY;
40390 @@ -7842,7 +7842,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40391 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
40392
40393 /* return error if TTY interface open */
40394 - if (info->port.count)
40395 + if (atomic_read(&info->port.count))
40396 return -EBUSY;
40397
40398 if (cmd != SIOCWANDEV)
40399 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
40400 index b38e954..ce45b38 100644
40401 --- a/drivers/tty/synclink_gt.c
40402 +++ b/drivers/tty/synclink_gt.c
40403 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
40404 tty->driver_data = info;
40405 info->port.tty = tty;
40406
40407 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
40408 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
40409
40410 /* If port is closing, signal caller to try again */
40411 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
40412 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
40413 mutex_unlock(&info->port.mutex);
40414 goto cleanup;
40415 }
40416 - info->port.count++;
40417 + atomic_inc(&info->port.count);
40418 spin_unlock_irqrestore(&info->netlock, flags);
40419
40420 - if (info->port.count == 1) {
40421 + if (atomic_read(&info->port.count) == 1) {
40422 /* 1st open on this device, init hardware */
40423 retval = startup(info);
40424 if (retval < 0) {
40425 @@ -716,8 +716,8 @@ cleanup:
40426 if (retval) {
40427 if (tty->count == 1)
40428 info->port.tty = NULL; /* tty layer will release tty struct */
40429 - if(info->port.count)
40430 - info->port.count--;
40431 + if(atomic_read(&info->port.count))
40432 + atomic_dec(&info->port.count);
40433 }
40434
40435 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
40436 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40437
40438 if (sanity_check(info, tty->name, "close"))
40439 return;
40440 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
40441 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
40442
40443 if (tty_port_close_start(&info->port, tty, filp) == 0)
40444 goto cleanup;
40445 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40446 tty_port_close_end(&info->port, tty);
40447 info->port.tty = NULL;
40448 cleanup:
40449 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
40450 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
40451 }
40452
40453 static void hangup(struct tty_struct *tty)
40454 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
40455 shutdown(info);
40456
40457 spin_lock_irqsave(&info->port.lock, flags);
40458 - info->port.count = 0;
40459 + atomic_set(&info->port.count, 0);
40460 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
40461 info->port.tty = NULL;
40462 spin_unlock_irqrestore(&info->port.lock, flags);
40463 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
40464 unsigned short new_crctype;
40465
40466 /* return error if TTY interface open */
40467 - if (info->port.count)
40468 + if (atomic_read(&info->port.count))
40469 return -EBUSY;
40470
40471 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
40472 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
40473
40474 /* arbitrate between network and tty opens */
40475 spin_lock_irqsave(&info->netlock, flags);
40476 - if (info->port.count != 0 || info->netcount != 0) {
40477 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40478 DBGINFO(("%s hdlc_open busy\n", dev->name));
40479 spin_unlock_irqrestore(&info->netlock, flags);
40480 return -EBUSY;
40481 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40482 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
40483
40484 /* return error if TTY interface open */
40485 - if (info->port.count)
40486 + if (atomic_read(&info->port.count))
40487 return -EBUSY;
40488
40489 if (cmd != SIOCWANDEV)
40490 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
40491 if (port == NULL)
40492 continue;
40493 spin_lock(&port->lock);
40494 - if ((port->port.count || port->netcount) &&
40495 + if ((atomic_read(&port->port.count) || port->netcount) &&
40496 port->pending_bh && !port->bh_running &&
40497 !port->bh_requested) {
40498 DBGISR(("%s bh queued\n", port->device_name));
40499 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40500 spin_lock_irqsave(&info->lock, flags);
40501 if (!tty_hung_up_p(filp)) {
40502 extra_count = true;
40503 - port->count--;
40504 + atomic_dec(&port->count);
40505 }
40506 spin_unlock_irqrestore(&info->lock, flags);
40507 port->blocked_open++;
40508 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40509 remove_wait_queue(&port->open_wait, &wait);
40510
40511 if (extra_count)
40512 - port->count++;
40513 + atomic_inc(&port->count);
40514 port->blocked_open--;
40515
40516 if (!retval)
40517 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
40518 index f17d9f3..27a041b 100644
40519 --- a/drivers/tty/synclinkmp.c
40520 +++ b/drivers/tty/synclinkmp.c
40521 @@ -751,7 +751,7 @@ static int open(struct tty_struct *tty, struct file *filp)
40522
40523 if (debug_level >= DEBUG_LEVEL_INFO)
40524 printk("%s(%d):%s open(), old ref count = %d\n",
40525 - __FILE__,__LINE__,tty->driver->name, info->port.count);
40526 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
40527
40528 /* If port is closing, signal caller to try again */
40529 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
40530 @@ -770,10 +770,10 @@ static int open(struct tty_struct *tty, struct file *filp)
40531 spin_unlock_irqrestore(&info->netlock, flags);
40532 goto cleanup;
40533 }
40534 - info->port.count++;
40535 + atomic_inc(&info->port.count);
40536 spin_unlock_irqrestore(&info->netlock, flags);
40537
40538 - if (info->port.count == 1) {
40539 + if (atomic_read(&info->port.count) == 1) {
40540 /* 1st open on this device, init hardware */
40541 retval = startup(info);
40542 if (retval < 0)
40543 @@ -797,8 +797,8 @@ cleanup:
40544 if (retval) {
40545 if (tty->count == 1)
40546 info->port.tty = NULL; /* tty layer will release tty struct */
40547 - if(info->port.count)
40548 - info->port.count--;
40549 + if(atomic_read(&info->port.count))
40550 + atomic_dec(&info->port.count);
40551 }
40552
40553 return retval;
40554 @@ -816,7 +816,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40555
40556 if (debug_level >= DEBUG_LEVEL_INFO)
40557 printk("%s(%d):%s close() entry, count=%d\n",
40558 - __FILE__,__LINE__, info->device_name, info->port.count);
40559 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
40560
40561 if (tty_port_close_start(&info->port, tty, filp) == 0)
40562 goto cleanup;
40563 @@ -835,7 +835,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40564 cleanup:
40565 if (debug_level >= DEBUG_LEVEL_INFO)
40566 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
40567 - tty->driver->name, info->port.count);
40568 + tty->driver->name, atomic_read(&info->port.count));
40569 }
40570
40571 /* Called by tty_hangup() when a hangup is signaled.
40572 @@ -858,7 +858,7 @@ static void hangup(struct tty_struct *tty)
40573 shutdown(info);
40574
40575 spin_lock_irqsave(&info->port.lock, flags);
40576 - info->port.count = 0;
40577 + atomic_set(&info->port.count, 0);
40578 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
40579 info->port.tty = NULL;
40580 spin_unlock_irqrestore(&info->port.lock, flags);
40581 @@ -1566,7 +1566,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
40582 unsigned short new_crctype;
40583
40584 /* return error if TTY interface open */
40585 - if (info->port.count)
40586 + if (atomic_read(&info->port.count))
40587 return -EBUSY;
40588
40589 switch (encoding)
40590 @@ -1661,7 +1661,7 @@ static int hdlcdev_open(struct net_device *dev)
40591
40592 /* arbitrate between network and tty opens */
40593 spin_lock_irqsave(&info->netlock, flags);
40594 - if (info->port.count != 0 || info->netcount != 0) {
40595 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40596 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
40597 spin_unlock_irqrestore(&info->netlock, flags);
40598 return -EBUSY;
40599 @@ -1747,7 +1747,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40600 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
40601
40602 /* return error if TTY interface open */
40603 - if (info->port.count)
40604 + if (atomic_read(&info->port.count))
40605 return -EBUSY;
40606
40607 if (cmd != SIOCWANDEV)
40608 @@ -2632,7 +2632,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
40609 * do not request bottom half processing if the
40610 * device is not open in a normal mode.
40611 */
40612 - if ( port && (port->port.count || port->netcount) &&
40613 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
40614 port->pending_bh && !port->bh_running &&
40615 !port->bh_requested ) {
40616 if ( debug_level >= DEBUG_LEVEL_ISR )
40617 @@ -3330,12 +3330,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40618
40619 if (debug_level >= DEBUG_LEVEL_INFO)
40620 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
40621 - __FILE__,__LINE__, tty->driver->name, port->count );
40622 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40623
40624 spin_lock_irqsave(&info->lock, flags);
40625 if (!tty_hung_up_p(filp)) {
40626 extra_count = true;
40627 - port->count--;
40628 + atomic_dec(&port->count);
40629 }
40630 spin_unlock_irqrestore(&info->lock, flags);
40631 port->blocked_open++;
40632 @@ -3364,7 +3364,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40633
40634 if (debug_level >= DEBUG_LEVEL_INFO)
40635 printk("%s(%d):%s block_til_ready() count=%d\n",
40636 - __FILE__,__LINE__, tty->driver->name, port->count );
40637 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40638
40639 tty_unlock(tty);
40640 schedule();
40641 @@ -3375,12 +3375,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40642 remove_wait_queue(&port->open_wait, &wait);
40643
40644 if (extra_count)
40645 - port->count++;
40646 + atomic_inc(&port->count);
40647 port->blocked_open--;
40648
40649 if (debug_level >= DEBUG_LEVEL_INFO)
40650 printk("%s(%d):%s block_til_ready() after, count=%d\n",
40651 - __FILE__,__LINE__, tty->driver->name, port->count );
40652 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40653
40654 if (!retval)
40655 port->flags |= ASYNC_NORMAL_ACTIVE;
40656 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
40657 index 16ee6ce..bfcac57 100644
40658 --- a/drivers/tty/sysrq.c
40659 +++ b/drivers/tty/sysrq.c
40660 @@ -866,7 +866,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
40661 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
40662 size_t count, loff_t *ppos)
40663 {
40664 - if (count) {
40665 + if (count && capable(CAP_SYS_ADMIN)) {
40666 char c;
40667
40668 if (get_user(c, buf))
40669 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
40670 index 2ea176b..2877bc8 100644
40671 --- a/drivers/tty/tty_io.c
40672 +++ b/drivers/tty/tty_io.c
40673 @@ -3395,7 +3395,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
40674
40675 void tty_default_fops(struct file_operations *fops)
40676 {
40677 - *fops = tty_fops;
40678 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
40679 }
40680
40681 /*
40682 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
40683 index 0f2a2c5..471e228 100644
40684 --- a/drivers/tty/tty_ldisc.c
40685 +++ b/drivers/tty/tty_ldisc.c
40686 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
40687 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
40688 struct tty_ldisc_ops *ldo = ld->ops;
40689
40690 - ldo->refcount--;
40691 + atomic_dec(&ldo->refcount);
40692 module_put(ldo->owner);
40693 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
40694
40695 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
40696 spin_lock_irqsave(&tty_ldisc_lock, flags);
40697 tty_ldiscs[disc] = new_ldisc;
40698 new_ldisc->num = disc;
40699 - new_ldisc->refcount = 0;
40700 + atomic_set(&new_ldisc->refcount, 0);
40701 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
40702
40703 return ret;
40704 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
40705 return -EINVAL;
40706
40707 spin_lock_irqsave(&tty_ldisc_lock, flags);
40708 - if (tty_ldiscs[disc]->refcount)
40709 + if (atomic_read(&tty_ldiscs[disc]->refcount))
40710 ret = -EBUSY;
40711 else
40712 tty_ldiscs[disc] = NULL;
40713 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
40714 if (ldops) {
40715 ret = ERR_PTR(-EAGAIN);
40716 if (try_module_get(ldops->owner)) {
40717 - ldops->refcount++;
40718 + atomic_inc(&ldops->refcount);
40719 ret = ldops;
40720 }
40721 }
40722 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
40723 unsigned long flags;
40724
40725 spin_lock_irqsave(&tty_ldisc_lock, flags);
40726 - ldops->refcount--;
40727 + atomic_dec(&ldops->refcount);
40728 module_put(ldops->owner);
40729 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
40730 }
40731 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
40732 index d7bdd8d..feaef30 100644
40733 --- a/drivers/tty/tty_port.c
40734 +++ b/drivers/tty/tty_port.c
40735 @@ -202,7 +202,7 @@ void tty_port_hangup(struct tty_port *port)
40736 unsigned long flags;
40737
40738 spin_lock_irqsave(&port->lock, flags);
40739 - port->count = 0;
40740 + atomic_set(&port->count, 0);
40741 port->flags &= ~ASYNC_NORMAL_ACTIVE;
40742 if (port->tty) {
40743 set_bit(TTY_IO_ERROR, &port->tty->flags);
40744 @@ -328,7 +328,7 @@ int tty_port_block_til_ready(struct tty_port *port,
40745 /* The port lock protects the port counts */
40746 spin_lock_irqsave(&port->lock, flags);
40747 if (!tty_hung_up_p(filp))
40748 - port->count--;
40749 + atomic_dec(&port->count);
40750 port->blocked_open++;
40751 spin_unlock_irqrestore(&port->lock, flags);
40752
40753 @@ -370,7 +370,7 @@ int tty_port_block_til_ready(struct tty_port *port,
40754 we must not mess that up further */
40755 spin_lock_irqsave(&port->lock, flags);
40756 if (!tty_hung_up_p(filp))
40757 - port->count++;
40758 + atomic_inc(&port->count);
40759 port->blocked_open--;
40760 if (retval == 0)
40761 port->flags |= ASYNC_NORMAL_ACTIVE;
40762 @@ -390,19 +390,19 @@ int tty_port_close_start(struct tty_port *port,
40763 return 0;
40764 }
40765
40766 - if (tty->count == 1 && port->count != 1) {
40767 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
40768 printk(KERN_WARNING
40769 "tty_port_close_start: tty->count = 1 port count = %d.\n",
40770 - port->count);
40771 - port->count = 1;
40772 + atomic_read(&port->count));
40773 + atomic_set(&port->count, 1);
40774 }
40775 - if (--port->count < 0) {
40776 + if (atomic_dec_return(&port->count) < 0) {
40777 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
40778 - port->count);
40779 - port->count = 0;
40780 + atomic_read(&port->count));
40781 + atomic_set(&port->count, 0);
40782 }
40783
40784 - if (port->count) {
40785 + if (atomic_read(&port->count)) {
40786 spin_unlock_irqrestore(&port->lock, flags);
40787 if (port->ops->drop)
40788 port->ops->drop(port);
40789 @@ -500,7 +500,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
40790 {
40791 spin_lock_irq(&port->lock);
40792 if (!tty_hung_up_p(filp))
40793 - ++port->count;
40794 + atomic_inc(&port->count);
40795 spin_unlock_irq(&port->lock);
40796 tty_port_tty_set(port, tty);
40797
40798 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
40799 index 681765b..d3ccdf2 100644
40800 --- a/drivers/tty/vt/keyboard.c
40801 +++ b/drivers/tty/vt/keyboard.c
40802 @@ -660,6 +660,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
40803 kbd->kbdmode == VC_OFF) &&
40804 value != KVAL(K_SAK))
40805 return; /* SAK is allowed even in raw mode */
40806 +
40807 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
40808 + {
40809 + void *func = fn_handler[value];
40810 + if (func == fn_show_state || func == fn_show_ptregs ||
40811 + func == fn_show_mem)
40812 + return;
40813 + }
40814 +#endif
40815 +
40816 fn_handler[value](vc);
40817 }
40818
40819 @@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
40820 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
40821 return -EFAULT;
40822
40823 - if (!capable(CAP_SYS_TTY_CONFIG))
40824 - perm = 0;
40825 -
40826 switch (cmd) {
40827 case KDGKBENT:
40828 /* Ensure another thread doesn't free it under us */
40829 @@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
40830 spin_unlock_irqrestore(&kbd_event_lock, flags);
40831 return put_user(val, &user_kbe->kb_value);
40832 case KDSKBENT:
40833 + if (!capable(CAP_SYS_TTY_CONFIG))
40834 + perm = 0;
40835 +
40836 if (!perm)
40837 return -EPERM;
40838 if (!i && v == K_NOSUCHMAP) {
40839 @@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
40840 int i, j, k;
40841 int ret;
40842
40843 - if (!capable(CAP_SYS_TTY_CONFIG))
40844 - perm = 0;
40845 -
40846 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
40847 if (!kbs) {
40848 ret = -ENOMEM;
40849 @@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
40850 kfree(kbs);
40851 return ((p && *p) ? -EOVERFLOW : 0);
40852 case KDSKBSENT:
40853 + if (!capable(CAP_SYS_TTY_CONFIG))
40854 + perm = 0;
40855 +
40856 if (!perm) {
40857 ret = -EPERM;
40858 goto reterr;
40859 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
40860 index 5110f36..8dc0a74 100644
40861 --- a/drivers/uio/uio.c
40862 +++ b/drivers/uio/uio.c
40863 @@ -25,6 +25,7 @@
40864 #include <linux/kobject.h>
40865 #include <linux/cdev.h>
40866 #include <linux/uio_driver.h>
40867 +#include <asm/local.h>
40868
40869 #define UIO_MAX_DEVICES (1U << MINORBITS)
40870
40871 @@ -32,10 +33,10 @@ struct uio_device {
40872 struct module *owner;
40873 struct device *dev;
40874 int minor;
40875 - atomic_t event;
40876 + atomic_unchecked_t event;
40877 struct fasync_struct *async_queue;
40878 wait_queue_head_t wait;
40879 - int vma_count;
40880 + local_t vma_count;
40881 struct uio_info *info;
40882 struct kobject *map_dir;
40883 struct kobject *portio_dir;
40884 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
40885 struct device_attribute *attr, char *buf)
40886 {
40887 struct uio_device *idev = dev_get_drvdata(dev);
40888 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
40889 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
40890 }
40891
40892 static struct device_attribute uio_class_attributes[] = {
40893 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
40894 {
40895 struct uio_device *idev = info->uio_dev;
40896
40897 - atomic_inc(&idev->event);
40898 + atomic_inc_unchecked(&idev->event);
40899 wake_up_interruptible(&idev->wait);
40900 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
40901 }
40902 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
40903 }
40904
40905 listener->dev = idev;
40906 - listener->event_count = atomic_read(&idev->event);
40907 + listener->event_count = atomic_read_unchecked(&idev->event);
40908 filep->private_data = listener;
40909
40910 if (idev->info->open) {
40911 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
40912 return -EIO;
40913
40914 poll_wait(filep, &idev->wait, wait);
40915 - if (listener->event_count != atomic_read(&idev->event))
40916 + if (listener->event_count != atomic_read_unchecked(&idev->event))
40917 return POLLIN | POLLRDNORM;
40918 return 0;
40919 }
40920 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
40921 do {
40922 set_current_state(TASK_INTERRUPTIBLE);
40923
40924 - event_count = atomic_read(&idev->event);
40925 + event_count = atomic_read_unchecked(&idev->event);
40926 if (event_count != listener->event_count) {
40927 if (copy_to_user(buf, &event_count, count))
40928 retval = -EFAULT;
40929 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
40930 static void uio_vma_open(struct vm_area_struct *vma)
40931 {
40932 struct uio_device *idev = vma->vm_private_data;
40933 - idev->vma_count++;
40934 + local_inc(&idev->vma_count);
40935 }
40936
40937 static void uio_vma_close(struct vm_area_struct *vma)
40938 {
40939 struct uio_device *idev = vma->vm_private_data;
40940 - idev->vma_count--;
40941 + local_dec(&idev->vma_count);
40942 }
40943
40944 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40945 @@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
40946 idev->owner = owner;
40947 idev->info = info;
40948 init_waitqueue_head(&idev->wait);
40949 - atomic_set(&idev->event, 0);
40950 + atomic_set_unchecked(&idev->event, 0);
40951
40952 ret = uio_get_minor(idev);
40953 if (ret)
40954 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
40955 index b7eb86a..36d28af 100644
40956 --- a/drivers/usb/atm/cxacru.c
40957 +++ b/drivers/usb/atm/cxacru.c
40958 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
40959 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
40960 if (ret < 2)
40961 return -EINVAL;
40962 - if (index < 0 || index > 0x7f)
40963 + if (index > 0x7f)
40964 return -EINVAL;
40965 pos += tmp;
40966
40967 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
40968 index 35f10bf..6a38a0b 100644
40969 --- a/drivers/usb/atm/usbatm.c
40970 +++ b/drivers/usb/atm/usbatm.c
40971 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40972 if (printk_ratelimit())
40973 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
40974 __func__, vpi, vci);
40975 - atomic_inc(&vcc->stats->rx_err);
40976 + atomic_inc_unchecked(&vcc->stats->rx_err);
40977 return;
40978 }
40979
40980 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40981 if (length > ATM_MAX_AAL5_PDU) {
40982 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
40983 __func__, length, vcc);
40984 - atomic_inc(&vcc->stats->rx_err);
40985 + atomic_inc_unchecked(&vcc->stats->rx_err);
40986 goto out;
40987 }
40988
40989 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40990 if (sarb->len < pdu_length) {
40991 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
40992 __func__, pdu_length, sarb->len, vcc);
40993 - atomic_inc(&vcc->stats->rx_err);
40994 + atomic_inc_unchecked(&vcc->stats->rx_err);
40995 goto out;
40996 }
40997
40998 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
40999 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
41000 __func__, vcc);
41001 - atomic_inc(&vcc->stats->rx_err);
41002 + atomic_inc_unchecked(&vcc->stats->rx_err);
41003 goto out;
41004 }
41005
41006 @@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41007 if (printk_ratelimit())
41008 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
41009 __func__, length);
41010 - atomic_inc(&vcc->stats->rx_drop);
41011 + atomic_inc_unchecked(&vcc->stats->rx_drop);
41012 goto out;
41013 }
41014
41015 @@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41016
41017 vcc->push(vcc, skb);
41018
41019 - atomic_inc(&vcc->stats->rx);
41020 + atomic_inc_unchecked(&vcc->stats->rx);
41021 out:
41022 skb_trim(sarb, 0);
41023 }
41024 @@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
41025 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
41026
41027 usbatm_pop(vcc, skb);
41028 - atomic_inc(&vcc->stats->tx);
41029 + atomic_inc_unchecked(&vcc->stats->tx);
41030
41031 skb = skb_dequeue(&instance->sndqueue);
41032 }
41033 @@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
41034 if (!left--)
41035 return sprintf(page,
41036 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
41037 - atomic_read(&atm_dev->stats.aal5.tx),
41038 - atomic_read(&atm_dev->stats.aal5.tx_err),
41039 - atomic_read(&atm_dev->stats.aal5.rx),
41040 - atomic_read(&atm_dev->stats.aal5.rx_err),
41041 - atomic_read(&atm_dev->stats.aal5.rx_drop));
41042 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
41043 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
41044 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
41045 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
41046 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
41047
41048 if (!left--) {
41049 if (instance->disconnected)
41050 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
41051 index f460de3..95ba1f6 100644
41052 --- a/drivers/usb/core/devices.c
41053 +++ b/drivers/usb/core/devices.c
41054 @@ -126,7 +126,7 @@ static const char format_endpt[] =
41055 * time it gets called.
41056 */
41057 static struct device_connect_event {
41058 - atomic_t count;
41059 + atomic_unchecked_t count;
41060 wait_queue_head_t wait;
41061 } device_event = {
41062 .count = ATOMIC_INIT(1),
41063 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
41064
41065 void usbfs_conn_disc_event(void)
41066 {
41067 - atomic_add(2, &device_event.count);
41068 + atomic_add_unchecked(2, &device_event.count);
41069 wake_up(&device_event.wait);
41070 }
41071
41072 @@ -647,7 +647,7 @@ static unsigned int usb_device_poll(struct file *file,
41073
41074 poll_wait(file, &device_event.wait, wait);
41075
41076 - event_count = atomic_read(&device_event.count);
41077 + event_count = atomic_read_unchecked(&device_event.count);
41078 if (file->f_version != event_count) {
41079 file->f_version = event_count;
41080 return POLLIN | POLLRDNORM;
41081 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
41082 index f034716..aed0368 100644
41083 --- a/drivers/usb/core/hcd.c
41084 +++ b/drivers/usb/core/hcd.c
41085 @@ -1478,7 +1478,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
41086 */
41087 usb_get_urb(urb);
41088 atomic_inc(&urb->use_count);
41089 - atomic_inc(&urb->dev->urbnum);
41090 + atomic_inc_unchecked(&urb->dev->urbnum);
41091 usbmon_urb_submit(&hcd->self, urb);
41092
41093 /* NOTE requirements on root-hub callers (usbfs and the hub
41094 @@ -1505,7 +1505,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
41095 urb->hcpriv = NULL;
41096 INIT_LIST_HEAD(&urb->urb_list);
41097 atomic_dec(&urb->use_count);
41098 - atomic_dec(&urb->dev->urbnum);
41099 + atomic_dec_unchecked(&urb->dev->urbnum);
41100 if (atomic_read(&urb->reject))
41101 wake_up(&usb_kill_urb_queue);
41102 usb_put_urb(urb);
41103 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
41104 index 818e4a0..0fc9589 100644
41105 --- a/drivers/usb/core/sysfs.c
41106 +++ b/drivers/usb/core/sysfs.c
41107 @@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
41108 struct usb_device *udev;
41109
41110 udev = to_usb_device(dev);
41111 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
41112 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
41113 }
41114 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
41115
41116 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
41117 index cd8fb44..17fbe0c 100644
41118 --- a/drivers/usb/core/usb.c
41119 +++ b/drivers/usb/core/usb.c
41120 @@ -397,7 +397,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
41121 set_dev_node(&dev->dev, dev_to_node(bus->controller));
41122 dev->state = USB_STATE_ATTACHED;
41123 dev->lpm_disable_count = 1;
41124 - atomic_set(&dev->urbnum, 0);
41125 + atomic_set_unchecked(&dev->urbnum, 0);
41126
41127 INIT_LIST_HEAD(&dev->ep0.urb_list);
41128 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
41129 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
41130 index 4bfa78a..902bfbd 100644
41131 --- a/drivers/usb/early/ehci-dbgp.c
41132 +++ b/drivers/usb/early/ehci-dbgp.c
41133 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
41134
41135 #ifdef CONFIG_KGDB
41136 static struct kgdb_io kgdbdbgp_io_ops;
41137 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
41138 +static struct kgdb_io kgdbdbgp_io_ops_console;
41139 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
41140 #else
41141 #define dbgp_kgdb_mode (0)
41142 #endif
41143 @@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
41144 .write_char = kgdbdbgp_write_char,
41145 };
41146
41147 +static struct kgdb_io kgdbdbgp_io_ops_console = {
41148 + .name = "kgdbdbgp",
41149 + .read_char = kgdbdbgp_read_char,
41150 + .write_char = kgdbdbgp_write_char,
41151 + .is_console = 1
41152 +};
41153 +
41154 static int kgdbdbgp_wait_time;
41155
41156 static int __init kgdbdbgp_parse_config(char *str)
41157 @@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
41158 ptr++;
41159 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
41160 }
41161 - kgdb_register_io_module(&kgdbdbgp_io_ops);
41162 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
41163 + if (early_dbgp_console.index != -1)
41164 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
41165 + else
41166 + kgdb_register_io_module(&kgdbdbgp_io_ops);
41167
41168 return 0;
41169 }
41170 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
41171 index f173952..83d6ec0 100644
41172 --- a/drivers/usb/gadget/u_serial.c
41173 +++ b/drivers/usb/gadget/u_serial.c
41174 @@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
41175 spin_lock_irq(&port->port_lock);
41176
41177 /* already open? Great. */
41178 - if (port->port.count) {
41179 + if (atomic_read(&port->port.count)) {
41180 status = 0;
41181 - port->port.count++;
41182 + atomic_inc(&port->port.count);
41183
41184 /* currently opening/closing? wait ... */
41185 } else if (port->openclose) {
41186 @@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
41187 tty->driver_data = port;
41188 port->port.tty = tty;
41189
41190 - port->port.count = 1;
41191 + atomic_set(&port->port.count, 1);
41192 port->openclose = false;
41193
41194 /* if connected, start the I/O stream */
41195 @@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
41196
41197 spin_lock_irq(&port->port_lock);
41198
41199 - if (port->port.count != 1) {
41200 - if (port->port.count == 0)
41201 + if (atomic_read(&port->port.count) != 1) {
41202 + if (atomic_read(&port->port.count) == 0)
41203 WARN_ON(1);
41204 else
41205 - --port->port.count;
41206 + atomic_dec(&port->port.count);
41207 goto exit;
41208 }
41209
41210 @@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
41211 * and sleep if necessary
41212 */
41213 port->openclose = true;
41214 - port->port.count = 0;
41215 + atomic_set(&port->port.count, 0);
41216
41217 gser = port->port_usb;
41218 if (gser && gser->disconnect)
41219 @@ -1157,7 +1157,7 @@ static int gs_closed(struct gs_port *port)
41220 int cond;
41221
41222 spin_lock_irq(&port->port_lock);
41223 - cond = (port->port.count == 0) && !port->openclose;
41224 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
41225 spin_unlock_irq(&port->port_lock);
41226 return cond;
41227 }
41228 @@ -1270,7 +1270,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
41229 /* if it's already open, start I/O ... and notify the serial
41230 * protocol about open/close status (connect/disconnect).
41231 */
41232 - if (port->port.count) {
41233 + if (atomic_read(&port->port.count)) {
41234 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
41235 gs_start_io(port);
41236 if (gser->connect)
41237 @@ -1317,7 +1317,7 @@ void gserial_disconnect(struct gserial *gser)
41238
41239 port->port_usb = NULL;
41240 gser->ioport = NULL;
41241 - if (port->port.count > 0 || port->openclose) {
41242 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
41243 wake_up_interruptible(&port->drain_wait);
41244 if (port->port.tty)
41245 tty_hangup(port->port.tty);
41246 @@ -1333,7 +1333,7 @@ void gserial_disconnect(struct gserial *gser)
41247
41248 /* finally, free any unused/unusable I/O buffers */
41249 spin_lock_irqsave(&port->port_lock, flags);
41250 - if (port->port.count == 0 && !port->openclose)
41251 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
41252 gs_buf_free(&port->port_write_buf);
41253 gs_free_requests(gser->out, &port->read_pool, NULL);
41254 gs_free_requests(gser->out, &port->read_queue, NULL);
41255 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
41256 index 5f3bcd3..bfca43f 100644
41257 --- a/drivers/usb/serial/console.c
41258 +++ b/drivers/usb/serial/console.c
41259 @@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
41260
41261 info->port = port;
41262
41263 - ++port->port.count;
41264 + atomic_inc(&port->port.count);
41265 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
41266 if (serial->type->set_termios) {
41267 /*
41268 @@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
41269 }
41270 /* Now that any required fake tty operations are completed restore
41271 * the tty port count */
41272 - --port->port.count;
41273 + atomic_dec(&port->port.count);
41274 /* The console is special in terms of closing the device so
41275 * indicate this port is now acting as a system console. */
41276 port->port.console = 1;
41277 @@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
41278 free_tty:
41279 kfree(tty);
41280 reset_open_count:
41281 - port->port.count = 0;
41282 + atomic_set(&port->port.count, 0);
41283 usb_autopm_put_interface(serial->interface);
41284 error_get_interface:
41285 usb_serial_put(serial);
41286 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
41287 index d6bea3e..60b250e 100644
41288 --- a/drivers/usb/wusbcore/wa-hc.h
41289 +++ b/drivers/usb/wusbcore/wa-hc.h
41290 @@ -192,7 +192,7 @@ struct wahc {
41291 struct list_head xfer_delayed_list;
41292 spinlock_t xfer_list_lock;
41293 struct work_struct xfer_work;
41294 - atomic_t xfer_id_count;
41295 + atomic_unchecked_t xfer_id_count;
41296 };
41297
41298
41299 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
41300 INIT_LIST_HEAD(&wa->xfer_delayed_list);
41301 spin_lock_init(&wa->xfer_list_lock);
41302 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
41303 - atomic_set(&wa->xfer_id_count, 1);
41304 + atomic_set_unchecked(&wa->xfer_id_count, 1);
41305 }
41306
41307 /**
41308 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
41309 index 57c01ab..8a05959 100644
41310 --- a/drivers/usb/wusbcore/wa-xfer.c
41311 +++ b/drivers/usb/wusbcore/wa-xfer.c
41312 @@ -296,7 +296,7 @@ out:
41313 */
41314 static void wa_xfer_id_init(struct wa_xfer *xfer)
41315 {
41316 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
41317 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
41318 }
41319
41320 /*
41321 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
41322 index dedaf81..b0f11ab 100644
41323 --- a/drivers/vhost/vhost.c
41324 +++ b/drivers/vhost/vhost.c
41325 @@ -634,7 +634,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
41326 return 0;
41327 }
41328
41329 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
41330 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
41331 {
41332 struct file *eventfp, *filep = NULL;
41333 bool pollstart = false, pollstop = false;
41334 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
41335 index 0fefa84..7a9d581 100644
41336 --- a/drivers/video/aty/aty128fb.c
41337 +++ b/drivers/video/aty/aty128fb.c
41338 @@ -149,7 +149,7 @@ enum {
41339 };
41340
41341 /* Must match above enum */
41342 -static char * const r128_family[] __devinitconst = {
41343 +static const char * const r128_family[] __devinitconst = {
41344 "AGP",
41345 "PCI",
41346 "PRO AGP",
41347 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
41348 index 5c3960d..15cf8fc 100644
41349 --- a/drivers/video/fbcmap.c
41350 +++ b/drivers/video/fbcmap.c
41351 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
41352 rc = -ENODEV;
41353 goto out;
41354 }
41355 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
41356 - !info->fbops->fb_setcmap)) {
41357 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
41358 rc = -EINVAL;
41359 goto out1;
41360 }
41361 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
41362 index 3ff0105..7589d98 100644
41363 --- a/drivers/video/fbmem.c
41364 +++ b/drivers/video/fbmem.c
41365 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
41366 image->dx += image->width + 8;
41367 }
41368 } else if (rotate == FB_ROTATE_UD) {
41369 - for (x = 0; x < num && image->dx >= 0; x++) {
41370 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
41371 info->fbops->fb_imageblit(info, image);
41372 image->dx -= image->width + 8;
41373 }
41374 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
41375 image->dy += image->height + 8;
41376 }
41377 } else if (rotate == FB_ROTATE_CCW) {
41378 - for (x = 0; x < num && image->dy >= 0; x++) {
41379 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
41380 info->fbops->fb_imageblit(info, image);
41381 image->dy -= image->height + 8;
41382 }
41383 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
41384 return -EFAULT;
41385 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
41386 return -EINVAL;
41387 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
41388 + if (con2fb.framebuffer >= FB_MAX)
41389 return -EINVAL;
41390 if (!registered_fb[con2fb.framebuffer])
41391 request_module("fb%d", con2fb.framebuffer);
41392 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
41393 index 7672d2e..b56437f 100644
41394 --- a/drivers/video/i810/i810_accel.c
41395 +++ b/drivers/video/i810/i810_accel.c
41396 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
41397 }
41398 }
41399 printk("ringbuffer lockup!!!\n");
41400 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
41401 i810_report_error(mmio);
41402 par->dev_flags |= LOCKUP;
41403 info->pixmap.scan_align = 1;
41404 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
41405 index 3c14e43..eafa544 100644
41406 --- a/drivers/video/logo/logo_linux_clut224.ppm
41407 +++ b/drivers/video/logo/logo_linux_clut224.ppm
41408 @@ -1,1604 +1,1123 @@
41409 P3
41410 -# Standard 224-color Linux logo
41411 80 80
41412 255
41413 - 0 0 0 0 0 0 0 0 0 0 0 0
41414 - 0 0 0 0 0 0 0 0 0 0 0 0
41415 - 0 0 0 0 0 0 0 0 0 0 0 0
41416 - 0 0 0 0 0 0 0 0 0 0 0 0
41417 - 0 0 0 0 0 0 0 0 0 0 0 0
41418 - 0 0 0 0 0 0 0 0 0 0 0 0
41419 - 0 0 0 0 0 0 0 0 0 0 0 0
41420 - 0 0 0 0 0 0 0 0 0 0 0 0
41421 - 0 0 0 0 0 0 0 0 0 0 0 0
41422 - 6 6 6 6 6 6 10 10 10 10 10 10
41423 - 10 10 10 6 6 6 6 6 6 6 6 6
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 - 0 0 0 0 0 0 0 0 0 0 0 0
41430 - 0 0 0 0 0 0 0 0 0 0 0 0
41431 - 0 0 0 0 0 0 0 0 0 0 0 0
41432 - 0 0 0 0 0 0 0 0 0 0 0 0
41433 - 0 0 0 0 0 0 0 0 0 0 0 0
41434 - 0 0 0 0 0 0 0 0 0 0 0 0
41435 - 0 0 0 0 0 0 0 0 0 0 0 0
41436 - 0 0 0 0 0 0 0 0 0 0 0 0
41437 - 0 0 0 0 0 0 0 0 0 0 0 0
41438 - 0 0 0 0 0 0 0 0 0 0 0 0
41439 - 0 0 0 0 0 0 0 0 0 0 0 0
41440 - 0 0 0 0 0 0 0 0 0 0 0 0
41441 - 0 0 0 6 6 6 10 10 10 14 14 14
41442 - 22 22 22 26 26 26 30 30 30 34 34 34
41443 - 30 30 30 30 30 30 26 26 26 18 18 18
41444 - 14 14 14 10 10 10 6 6 6 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 0 0 0
41449 - 0 0 0 0 0 0 0 0 0 0 0 0
41450 - 0 0 0 0 0 0 0 0 0 0 0 0
41451 - 0 0 0 0 0 0 0 0 0 0 0 0
41452 - 0 0 0 0 0 0 0 0 0 0 0 0
41453 - 0 0 0 0 0 0 0 0 0 0 0 0
41454 - 0 0 0 0 0 1 0 0 1 0 0 0
41455 - 0 0 0 0 0 0 0 0 0 0 0 0
41456 - 0 0 0 0 0 0 0 0 0 0 0 0
41457 - 0 0 0 0 0 0 0 0 0 0 0 0
41458 - 0 0 0 0 0 0 0 0 0 0 0 0
41459 - 0 0 0 0 0 0 0 0 0 0 0 0
41460 - 0 0 0 0 0 0 0 0 0 0 0 0
41461 - 6 6 6 14 14 14 26 26 26 42 42 42
41462 - 54 54 54 66 66 66 78 78 78 78 78 78
41463 - 78 78 78 74 74 74 66 66 66 54 54 54
41464 - 42 42 42 26 26 26 18 18 18 10 10 10
41465 - 6 6 6 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 0 0 0
41469 - 0 0 0 0 0 0 0 0 0 0 0 0
41470 - 0 0 0 0 0 0 0 0 0 0 0 0
41471 - 0 0 0 0 0 0 0 0 0 0 0 0
41472 - 0 0 0 0 0 0 0 0 0 0 0 0
41473 - 0 0 0 0 0 0 0 0 0 0 0 0
41474 - 0 0 1 0 0 0 0 0 0 0 0 0
41475 - 0 0 0 0 0 0 0 0 0 0 0 0
41476 - 0 0 0 0 0 0 0 0 0 0 0 0
41477 - 0 0 0 0 0 0 0 0 0 0 0 0
41478 - 0 0 0 0 0 0 0 0 0 0 0 0
41479 - 0 0 0 0 0 0 0 0 0 0 0 0
41480 - 0 0 0 0 0 0 0 0 0 10 10 10
41481 - 22 22 22 42 42 42 66 66 66 86 86 86
41482 - 66 66 66 38 38 38 38 38 38 22 22 22
41483 - 26 26 26 34 34 34 54 54 54 66 66 66
41484 - 86 86 86 70 70 70 46 46 46 26 26 26
41485 - 14 14 14 6 6 6 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 0 0 0 0 0 0
41489 - 0 0 0 0 0 0 0 0 0 0 0 0
41490 - 0 0 0 0 0 0 0 0 0 0 0 0
41491 - 0 0 0 0 0 0 0 0 0 0 0 0
41492 - 0 0 0 0 0 0 0 0 0 0 0 0
41493 - 0 0 0 0 0 0 0 0 0 0 0 0
41494 - 0 0 1 0 0 1 0 0 1 0 0 0
41495 - 0 0 0 0 0 0 0 0 0 0 0 0
41496 - 0 0 0 0 0 0 0 0 0 0 0 0
41497 - 0 0 0 0 0 0 0 0 0 0 0 0
41498 - 0 0 0 0 0 0 0 0 0 0 0 0
41499 - 0 0 0 0 0 0 0 0 0 0 0 0
41500 - 0 0 0 0 0 0 10 10 10 26 26 26
41501 - 50 50 50 82 82 82 58 58 58 6 6 6
41502 - 2 2 6 2 2 6 2 2 6 2 2 6
41503 - 2 2 6 2 2 6 2 2 6 2 2 6
41504 - 6 6 6 54 54 54 86 86 86 66 66 66
41505 - 38 38 38 18 18 18 6 6 6 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 0 0 0 0 0 0 0 0 0
41509 - 0 0 0 0 0 0 0 0 0 0 0 0
41510 - 0 0 0 0 0 0 0 0 0 0 0 0
41511 - 0 0 0 0 0 0 0 0 0 0 0 0
41512 - 0 0 0 0 0 0 0 0 0 0 0 0
41513 - 0 0 0 0 0 0 0 0 0 0 0 0
41514 - 0 0 0 0 0 0 0 0 0 0 0 0
41515 - 0 0 0 0 0 0 0 0 0 0 0 0
41516 - 0 0 0 0 0 0 0 0 0 0 0 0
41517 - 0 0 0 0 0 0 0 0 0 0 0 0
41518 - 0 0 0 0 0 0 0 0 0 0 0 0
41519 - 0 0 0 0 0 0 0 0 0 0 0 0
41520 - 0 0 0 6 6 6 22 22 22 50 50 50
41521 - 78 78 78 34 34 34 2 2 6 2 2 6
41522 - 2 2 6 2 2 6 2 2 6 2 2 6
41523 - 2 2 6 2 2 6 2 2 6 2 2 6
41524 - 2 2 6 2 2 6 6 6 6 70 70 70
41525 - 78 78 78 46 46 46 22 22 22 6 6 6
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 - 0 0 0 0 0 0 0 0 0 0 0 0
41529 - 0 0 0 0 0 0 0 0 0 0 0 0
41530 - 0 0 0 0 0 0 0 0 0 0 0 0
41531 - 0 0 0 0 0 0 0 0 0 0 0 0
41532 - 0 0 0 0 0 0 0 0 0 0 0 0
41533 - 0 0 0 0 0 0 0 0 0 0 0 0
41534 - 0 0 1 0 0 1 0 0 1 0 0 0
41535 - 0 0 0 0 0 0 0 0 0 0 0 0
41536 - 0 0 0 0 0 0 0 0 0 0 0 0
41537 - 0 0 0 0 0 0 0 0 0 0 0 0
41538 - 0 0 0 0 0 0 0 0 0 0 0 0
41539 - 0 0 0 0 0 0 0 0 0 0 0 0
41540 - 6 6 6 18 18 18 42 42 42 82 82 82
41541 - 26 26 26 2 2 6 2 2 6 2 2 6
41542 - 2 2 6 2 2 6 2 2 6 2 2 6
41543 - 2 2 6 2 2 6 2 2 6 14 14 14
41544 - 46 46 46 34 34 34 6 6 6 2 2 6
41545 - 42 42 42 78 78 78 42 42 42 18 18 18
41546 - 6 6 6 0 0 0 0 0 0 0 0 0
41547 - 0 0 0 0 0 0 0 0 0 0 0 0
41548 - 0 0 0 0 0 0 0 0 0 0 0 0
41549 - 0 0 0 0 0 0 0 0 0 0 0 0
41550 - 0 0 0 0 0 0 0 0 0 0 0 0
41551 - 0 0 0 0 0 0 0 0 0 0 0 0
41552 - 0 0 0 0 0 0 0 0 0 0 0 0
41553 - 0 0 0 0 0 0 0 0 0 0 0 0
41554 - 0 0 1 0 0 0 0 0 1 0 0 0
41555 - 0 0 0 0 0 0 0 0 0 0 0 0
41556 - 0 0 0 0 0 0 0 0 0 0 0 0
41557 - 0 0 0 0 0 0 0 0 0 0 0 0
41558 - 0 0 0 0 0 0 0 0 0 0 0 0
41559 - 0 0 0 0 0 0 0 0 0 0 0 0
41560 - 10 10 10 30 30 30 66 66 66 58 58 58
41561 - 2 2 6 2 2 6 2 2 6 2 2 6
41562 - 2 2 6 2 2 6 2 2 6 2 2 6
41563 - 2 2 6 2 2 6 2 2 6 26 26 26
41564 - 86 86 86 101 101 101 46 46 46 10 10 10
41565 - 2 2 6 58 58 58 70 70 70 34 34 34
41566 - 10 10 10 0 0 0 0 0 0 0 0 0
41567 - 0 0 0 0 0 0 0 0 0 0 0 0
41568 - 0 0 0 0 0 0 0 0 0 0 0 0
41569 - 0 0 0 0 0 0 0 0 0 0 0 0
41570 - 0 0 0 0 0 0 0 0 0 0 0 0
41571 - 0 0 0 0 0 0 0 0 0 0 0 0
41572 - 0 0 0 0 0 0 0 0 0 0 0 0
41573 - 0 0 0 0 0 0 0 0 0 0 0 0
41574 - 0 0 1 0 0 1 0 0 1 0 0 0
41575 - 0 0 0 0 0 0 0 0 0 0 0 0
41576 - 0 0 0 0 0 0 0 0 0 0 0 0
41577 - 0 0 0 0 0 0 0 0 0 0 0 0
41578 - 0 0 0 0 0 0 0 0 0 0 0 0
41579 - 0 0 0 0 0 0 0 0 0 0 0 0
41580 - 14 14 14 42 42 42 86 86 86 10 10 10
41581 - 2 2 6 2 2 6 2 2 6 2 2 6
41582 - 2 2 6 2 2 6 2 2 6 2 2 6
41583 - 2 2 6 2 2 6 2 2 6 30 30 30
41584 - 94 94 94 94 94 94 58 58 58 26 26 26
41585 - 2 2 6 6 6 6 78 78 78 54 54 54
41586 - 22 22 22 6 6 6 0 0 0 0 0 0
41587 - 0 0 0 0 0 0 0 0 0 0 0 0
41588 - 0 0 0 0 0 0 0 0 0 0 0 0
41589 - 0 0 0 0 0 0 0 0 0 0 0 0
41590 - 0 0 0 0 0 0 0 0 0 0 0 0
41591 - 0 0 0 0 0 0 0 0 0 0 0 0
41592 - 0 0 0 0 0 0 0 0 0 0 0 0
41593 - 0 0 0 0 0 0 0 0 0 0 0 0
41594 - 0 0 0 0 0 0 0 0 0 0 0 0
41595 - 0 0 0 0 0 0 0 0 0 0 0 0
41596 - 0 0 0 0 0 0 0 0 0 0 0 0
41597 - 0 0 0 0 0 0 0 0 0 0 0 0
41598 - 0 0 0 0 0 0 0 0 0 0 0 0
41599 - 0 0 0 0 0 0 0 0 0 6 6 6
41600 - 22 22 22 62 62 62 62 62 62 2 2 6
41601 - 2 2 6 2 2 6 2 2 6 2 2 6
41602 - 2 2 6 2 2 6 2 2 6 2 2 6
41603 - 2 2 6 2 2 6 2 2 6 26 26 26
41604 - 54 54 54 38 38 38 18 18 18 10 10 10
41605 - 2 2 6 2 2 6 34 34 34 82 82 82
41606 - 38 38 38 14 14 14 0 0 0 0 0 0
41607 - 0 0 0 0 0 0 0 0 0 0 0 0
41608 - 0 0 0 0 0 0 0 0 0 0 0 0
41609 - 0 0 0 0 0 0 0 0 0 0 0 0
41610 - 0 0 0 0 0 0 0 0 0 0 0 0
41611 - 0 0 0 0 0 0 0 0 0 0 0 0
41612 - 0 0 0 0 0 0 0 0 0 0 0 0
41613 - 0 0 0 0 0 0 0 0 0 0 0 0
41614 - 0 0 0 0 0 1 0 0 1 0 0 0
41615 - 0 0 0 0 0 0 0 0 0 0 0 0
41616 - 0 0 0 0 0 0 0 0 0 0 0 0
41617 - 0 0 0 0 0 0 0 0 0 0 0 0
41618 - 0 0 0 0 0 0 0 0 0 0 0 0
41619 - 0 0 0 0 0 0 0 0 0 6 6 6
41620 - 30 30 30 78 78 78 30 30 30 2 2 6
41621 - 2 2 6 2 2 6 2 2 6 2 2 6
41622 - 2 2 6 2 2 6 2 2 6 2 2 6
41623 - 2 2 6 2 2 6 2 2 6 10 10 10
41624 - 10 10 10 2 2 6 2 2 6 2 2 6
41625 - 2 2 6 2 2 6 2 2 6 78 78 78
41626 - 50 50 50 18 18 18 6 6 6 0 0 0
41627 - 0 0 0 0 0 0 0 0 0 0 0 0
41628 - 0 0 0 0 0 0 0 0 0 0 0 0
41629 - 0 0 0 0 0 0 0 0 0 0 0 0
41630 - 0 0 0 0 0 0 0 0 0 0 0 0
41631 - 0 0 0 0 0 0 0 0 0 0 0 0
41632 - 0 0 0 0 0 0 0 0 0 0 0 0
41633 - 0 0 0 0 0 0 0 0 0 0 0 0
41634 - 0 0 1 0 0 0 0 0 0 0 0 0
41635 - 0 0 0 0 0 0 0 0 0 0 0 0
41636 - 0 0 0 0 0 0 0 0 0 0 0 0
41637 - 0 0 0 0 0 0 0 0 0 0 0 0
41638 - 0 0 0 0 0 0 0 0 0 0 0 0
41639 - 0 0 0 0 0 0 0 0 0 10 10 10
41640 - 38 38 38 86 86 86 14 14 14 2 2 6
41641 - 2 2 6 2 2 6 2 2 6 2 2 6
41642 - 2 2 6 2 2 6 2 2 6 2 2 6
41643 - 2 2 6 2 2 6 2 2 6 2 2 6
41644 - 2 2 6 2 2 6 2 2 6 2 2 6
41645 - 2 2 6 2 2 6 2 2 6 54 54 54
41646 - 66 66 66 26 26 26 6 6 6 0 0 0
41647 - 0 0 0 0 0 0 0 0 0 0 0 0
41648 - 0 0 0 0 0 0 0 0 0 0 0 0
41649 - 0 0 0 0 0 0 0 0 0 0 0 0
41650 - 0 0 0 0 0 0 0 0 0 0 0 0
41651 - 0 0 0 0 0 0 0 0 0 0 0 0
41652 - 0 0 0 0 0 0 0 0 0 0 0 0
41653 - 0 0 0 0 0 0 0 0 0 0 0 0
41654 - 0 0 0 0 0 1 0 0 1 0 0 0
41655 - 0 0 0 0 0 0 0 0 0 0 0 0
41656 - 0 0 0 0 0 0 0 0 0 0 0 0
41657 - 0 0 0 0 0 0 0 0 0 0 0 0
41658 - 0 0 0 0 0 0 0 0 0 0 0 0
41659 - 0 0 0 0 0 0 0 0 0 14 14 14
41660 - 42 42 42 82 82 82 2 2 6 2 2 6
41661 - 2 2 6 6 6 6 10 10 10 2 2 6
41662 - 2 2 6 2 2 6 2 2 6 2 2 6
41663 - 2 2 6 2 2 6 2 2 6 6 6 6
41664 - 14 14 14 10 10 10 2 2 6 2 2 6
41665 - 2 2 6 2 2 6 2 2 6 18 18 18
41666 - 82 82 82 34 34 34 10 10 10 0 0 0
41667 - 0 0 0 0 0 0 0 0 0 0 0 0
41668 - 0 0 0 0 0 0 0 0 0 0 0 0
41669 - 0 0 0 0 0 0 0 0 0 0 0 0
41670 - 0 0 0 0 0 0 0 0 0 0 0 0
41671 - 0 0 0 0 0 0 0 0 0 0 0 0
41672 - 0 0 0 0 0 0 0 0 0 0 0 0
41673 - 0 0 0 0 0 0 0 0 0 0 0 0
41674 - 0 0 1 0 0 0 0 0 0 0 0 0
41675 - 0 0 0 0 0 0 0 0 0 0 0 0
41676 - 0 0 0 0 0 0 0 0 0 0 0 0
41677 - 0 0 0 0 0 0 0 0 0 0 0 0
41678 - 0 0 0 0 0 0 0 0 0 0 0 0
41679 - 0 0 0 0 0 0 0 0 0 14 14 14
41680 - 46 46 46 86 86 86 2 2 6 2 2 6
41681 - 6 6 6 6 6 6 22 22 22 34 34 34
41682 - 6 6 6 2 2 6 2 2 6 2 2 6
41683 - 2 2 6 2 2 6 18 18 18 34 34 34
41684 - 10 10 10 50 50 50 22 22 22 2 2 6
41685 - 2 2 6 2 2 6 2 2 6 10 10 10
41686 - 86 86 86 42 42 42 14 14 14 0 0 0
41687 - 0 0 0 0 0 0 0 0 0 0 0 0
41688 - 0 0 0 0 0 0 0 0 0 0 0 0
41689 - 0 0 0 0 0 0 0 0 0 0 0 0
41690 - 0 0 0 0 0 0 0 0 0 0 0 0
41691 - 0 0 0 0 0 0 0 0 0 0 0 0
41692 - 0 0 0 0 0 0 0 0 0 0 0 0
41693 - 0 0 0 0 0 0 0 0 0 0 0 0
41694 - 0 0 1 0 0 1 0 0 1 0 0 0
41695 - 0 0 0 0 0 0 0 0 0 0 0 0
41696 - 0 0 0 0 0 0 0 0 0 0 0 0
41697 - 0 0 0 0 0 0 0 0 0 0 0 0
41698 - 0 0 0 0 0 0 0 0 0 0 0 0
41699 - 0 0 0 0 0 0 0 0 0 14 14 14
41700 - 46 46 46 86 86 86 2 2 6 2 2 6
41701 - 38 38 38 116 116 116 94 94 94 22 22 22
41702 - 22 22 22 2 2 6 2 2 6 2 2 6
41703 - 14 14 14 86 86 86 138 138 138 162 162 162
41704 -154 154 154 38 38 38 26 26 26 6 6 6
41705 - 2 2 6 2 2 6 2 2 6 2 2 6
41706 - 86 86 86 46 46 46 14 14 14 0 0 0
41707 - 0 0 0 0 0 0 0 0 0 0 0 0
41708 - 0 0 0 0 0 0 0 0 0 0 0 0
41709 - 0 0 0 0 0 0 0 0 0 0 0 0
41710 - 0 0 0 0 0 0 0 0 0 0 0 0
41711 - 0 0 0 0 0 0 0 0 0 0 0 0
41712 - 0 0 0 0 0 0 0 0 0 0 0 0
41713 - 0 0 0 0 0 0 0 0 0 0 0 0
41714 - 0 0 0 0 0 0 0 0 0 0 0 0
41715 - 0 0 0 0 0 0 0 0 0 0 0 0
41716 - 0 0 0 0 0 0 0 0 0 0 0 0
41717 - 0 0 0 0 0 0 0 0 0 0 0 0
41718 - 0 0 0 0 0 0 0 0 0 0 0 0
41719 - 0 0 0 0 0 0 0 0 0 14 14 14
41720 - 46 46 46 86 86 86 2 2 6 14 14 14
41721 -134 134 134 198 198 198 195 195 195 116 116 116
41722 - 10 10 10 2 2 6 2 2 6 6 6 6
41723 -101 98 89 187 187 187 210 210 210 218 218 218
41724 -214 214 214 134 134 134 14 14 14 6 6 6
41725 - 2 2 6 2 2 6 2 2 6 2 2 6
41726 - 86 86 86 50 50 50 18 18 18 6 6 6
41727 - 0 0 0 0 0 0 0 0 0 0 0 0
41728 - 0 0 0 0 0 0 0 0 0 0 0 0
41729 - 0 0 0 0 0 0 0 0 0 0 0 0
41730 - 0 0 0 0 0 0 0 0 0 0 0 0
41731 - 0 0 0 0 0 0 0 0 0 0 0 0
41732 - 0 0 0 0 0 0 0 0 0 0 0 0
41733 - 0 0 0 0 0 0 0 0 1 0 0 0
41734 - 0 0 1 0 0 1 0 0 1 0 0 0
41735 - 0 0 0 0 0 0 0 0 0 0 0 0
41736 - 0 0 0 0 0 0 0 0 0 0 0 0
41737 - 0 0 0 0 0 0 0 0 0 0 0 0
41738 - 0 0 0 0 0 0 0 0 0 0 0 0
41739 - 0 0 0 0 0 0 0 0 0 14 14 14
41740 - 46 46 46 86 86 86 2 2 6 54 54 54
41741 -218 218 218 195 195 195 226 226 226 246 246 246
41742 - 58 58 58 2 2 6 2 2 6 30 30 30
41743 -210 210 210 253 253 253 174 174 174 123 123 123
41744 -221 221 221 234 234 234 74 74 74 2 2 6
41745 - 2 2 6 2 2 6 2 2 6 2 2 6
41746 - 70 70 70 58 58 58 22 22 22 6 6 6
41747 - 0 0 0 0 0 0 0 0 0 0 0 0
41748 - 0 0 0 0 0 0 0 0 0 0 0 0
41749 - 0 0 0 0 0 0 0 0 0 0 0 0
41750 - 0 0 0 0 0 0 0 0 0 0 0 0
41751 - 0 0 0 0 0 0 0 0 0 0 0 0
41752 - 0 0 0 0 0 0 0 0 0 0 0 0
41753 - 0 0 0 0 0 0 0 0 0 0 0 0
41754 - 0 0 0 0 0 0 0 0 0 0 0 0
41755 - 0 0 0 0 0 0 0 0 0 0 0 0
41756 - 0 0 0 0 0 0 0 0 0 0 0 0
41757 - 0 0 0 0 0 0 0 0 0 0 0 0
41758 - 0 0 0 0 0 0 0 0 0 0 0 0
41759 - 0 0 0 0 0 0 0 0 0 14 14 14
41760 - 46 46 46 82 82 82 2 2 6 106 106 106
41761 -170 170 170 26 26 26 86 86 86 226 226 226
41762 -123 123 123 10 10 10 14 14 14 46 46 46
41763 -231 231 231 190 190 190 6 6 6 70 70 70
41764 - 90 90 90 238 238 238 158 158 158 2 2 6
41765 - 2 2 6 2 2 6 2 2 6 2 2 6
41766 - 70 70 70 58 58 58 22 22 22 6 6 6
41767 - 0 0 0 0 0 0 0 0 0 0 0 0
41768 - 0 0 0 0 0 0 0 0 0 0 0 0
41769 - 0 0 0 0 0 0 0 0 0 0 0 0
41770 - 0 0 0 0 0 0 0 0 0 0 0 0
41771 - 0 0 0 0 0 0 0 0 0 0 0 0
41772 - 0 0 0 0 0 0 0 0 0 0 0 0
41773 - 0 0 0 0 0 0 0 0 1 0 0 0
41774 - 0 0 1 0 0 1 0 0 1 0 0 0
41775 - 0 0 0 0 0 0 0 0 0 0 0 0
41776 - 0 0 0 0 0 0 0 0 0 0 0 0
41777 - 0 0 0 0 0 0 0 0 0 0 0 0
41778 - 0 0 0 0 0 0 0 0 0 0 0 0
41779 - 0 0 0 0 0 0 0 0 0 14 14 14
41780 - 42 42 42 86 86 86 6 6 6 116 116 116
41781 -106 106 106 6 6 6 70 70 70 149 149 149
41782 -128 128 128 18 18 18 38 38 38 54 54 54
41783 -221 221 221 106 106 106 2 2 6 14 14 14
41784 - 46 46 46 190 190 190 198 198 198 2 2 6
41785 - 2 2 6 2 2 6 2 2 6 2 2 6
41786 - 74 74 74 62 62 62 22 22 22 6 6 6
41787 - 0 0 0 0 0 0 0 0 0 0 0 0
41788 - 0 0 0 0 0 0 0 0 0 0 0 0
41789 - 0 0 0 0 0 0 0 0 0 0 0 0
41790 - 0 0 0 0 0 0 0 0 0 0 0 0
41791 - 0 0 0 0 0 0 0 0 0 0 0 0
41792 - 0 0 0 0 0 0 0 0 0 0 0 0
41793 - 0 0 0 0 0 0 0 0 1 0 0 0
41794 - 0 0 1 0 0 0 0 0 1 0 0 0
41795 - 0 0 0 0 0 0 0 0 0 0 0 0
41796 - 0 0 0 0 0 0 0 0 0 0 0 0
41797 - 0 0 0 0 0 0 0 0 0 0 0 0
41798 - 0 0 0 0 0 0 0 0 0 0 0 0
41799 - 0 0 0 0 0 0 0 0 0 14 14 14
41800 - 42 42 42 94 94 94 14 14 14 101 101 101
41801 -128 128 128 2 2 6 18 18 18 116 116 116
41802 -118 98 46 121 92 8 121 92 8 98 78 10
41803 -162 162 162 106 106 106 2 2 6 2 2 6
41804 - 2 2 6 195 195 195 195 195 195 6 6 6
41805 - 2 2 6 2 2 6 2 2 6 2 2 6
41806 - 74 74 74 62 62 62 22 22 22 6 6 6
41807 - 0 0 0 0 0 0 0 0 0 0 0 0
41808 - 0 0 0 0 0 0 0 0 0 0 0 0
41809 - 0 0 0 0 0 0 0 0 0 0 0 0
41810 - 0 0 0 0 0 0 0 0 0 0 0 0
41811 - 0 0 0 0 0 0 0 0 0 0 0 0
41812 - 0 0 0 0 0 0 0 0 0 0 0 0
41813 - 0 0 0 0 0 0 0 0 1 0 0 1
41814 - 0 0 1 0 0 0 0 0 1 0 0 0
41815 - 0 0 0 0 0 0 0 0 0 0 0 0
41816 - 0 0 0 0 0 0 0 0 0 0 0 0
41817 - 0 0 0 0 0 0 0 0 0 0 0 0
41818 - 0 0 0 0 0 0 0 0 0 0 0 0
41819 - 0 0 0 0 0 0 0 0 0 10 10 10
41820 - 38 38 38 90 90 90 14 14 14 58 58 58
41821 -210 210 210 26 26 26 54 38 6 154 114 10
41822 -226 170 11 236 186 11 225 175 15 184 144 12
41823 -215 174 15 175 146 61 37 26 9 2 2 6
41824 - 70 70 70 246 246 246 138 138 138 2 2 6
41825 - 2 2 6 2 2 6 2 2 6 2 2 6
41826 - 70 70 70 66 66 66 26 26 26 6 6 6
41827 - 0 0 0 0 0 0 0 0 0 0 0 0
41828 - 0 0 0 0 0 0 0 0 0 0 0 0
41829 - 0 0 0 0 0 0 0 0 0 0 0 0
41830 - 0 0 0 0 0 0 0 0 0 0 0 0
41831 - 0 0 0 0 0 0 0 0 0 0 0 0
41832 - 0 0 0 0 0 0 0 0 0 0 0 0
41833 - 0 0 0 0 0 0 0 0 0 0 0 0
41834 - 0 0 0 0 0 0 0 0 0 0 0 0
41835 - 0 0 0 0 0 0 0 0 0 0 0 0
41836 - 0 0 0 0 0 0 0 0 0 0 0 0
41837 - 0 0 0 0 0 0 0 0 0 0 0 0
41838 - 0 0 0 0 0 0 0 0 0 0 0 0
41839 - 0 0 0 0 0 0 0 0 0 10 10 10
41840 - 38 38 38 86 86 86 14 14 14 10 10 10
41841 -195 195 195 188 164 115 192 133 9 225 175 15
41842 -239 182 13 234 190 10 232 195 16 232 200 30
41843 -245 207 45 241 208 19 232 195 16 184 144 12
41844 -218 194 134 211 206 186 42 42 42 2 2 6
41845 - 2 2 6 2 2 6 2 2 6 2 2 6
41846 - 50 50 50 74 74 74 30 30 30 6 6 6
41847 - 0 0 0 0 0 0 0 0 0 0 0 0
41848 - 0 0 0 0 0 0 0 0 0 0 0 0
41849 - 0 0 0 0 0 0 0 0 0 0 0 0
41850 - 0 0 0 0 0 0 0 0 0 0 0 0
41851 - 0 0 0 0 0 0 0 0 0 0 0 0
41852 - 0 0 0 0 0 0 0 0 0 0 0 0
41853 - 0 0 0 0 0 0 0 0 0 0 0 0
41854 - 0 0 0 0 0 0 0 0 0 0 0 0
41855 - 0 0 0 0 0 0 0 0 0 0 0 0
41856 - 0 0 0 0 0 0 0 0 0 0 0 0
41857 - 0 0 0 0 0 0 0 0 0 0 0 0
41858 - 0 0 0 0 0 0 0 0 0 0 0 0
41859 - 0 0 0 0 0 0 0 0 0 10 10 10
41860 - 34 34 34 86 86 86 14 14 14 2 2 6
41861 -121 87 25 192 133 9 219 162 10 239 182 13
41862 -236 186 11 232 195 16 241 208 19 244 214 54
41863 -246 218 60 246 218 38 246 215 20 241 208 19
41864 -241 208 19 226 184 13 121 87 25 2 2 6
41865 - 2 2 6 2 2 6 2 2 6 2 2 6
41866 - 50 50 50 82 82 82 34 34 34 10 10 10
41867 - 0 0 0 0 0 0 0 0 0 0 0 0
41868 - 0 0 0 0 0 0 0 0 0 0 0 0
41869 - 0 0 0 0 0 0 0 0 0 0 0 0
41870 - 0 0 0 0 0 0 0 0 0 0 0 0
41871 - 0 0 0 0 0 0 0 0 0 0 0 0
41872 - 0 0 0 0 0 0 0 0 0 0 0 0
41873 - 0 0 0 0 0 0 0 0 0 0 0 0
41874 - 0 0 0 0 0 0 0 0 0 0 0 0
41875 - 0 0 0 0 0 0 0 0 0 0 0 0
41876 - 0 0 0 0 0 0 0 0 0 0 0 0
41877 - 0 0 0 0 0 0 0 0 0 0 0 0
41878 - 0 0 0 0 0 0 0 0 0 0 0 0
41879 - 0 0 0 0 0 0 0 0 0 10 10 10
41880 - 34 34 34 82 82 82 30 30 30 61 42 6
41881 -180 123 7 206 145 10 230 174 11 239 182 13
41882 -234 190 10 238 202 15 241 208 19 246 218 74
41883 -246 218 38 246 215 20 246 215 20 246 215 20
41884 -226 184 13 215 174 15 184 144 12 6 6 6
41885 - 2 2 6 2 2 6 2 2 6 2 2 6
41886 - 26 26 26 94 94 94 42 42 42 14 14 14
41887 - 0 0 0 0 0 0 0 0 0 0 0 0
41888 - 0 0 0 0 0 0 0 0 0 0 0 0
41889 - 0 0 0 0 0 0 0 0 0 0 0 0
41890 - 0 0 0 0 0 0 0 0 0 0 0 0
41891 - 0 0 0 0 0 0 0 0 0 0 0 0
41892 - 0 0 0 0 0 0 0 0 0 0 0 0
41893 - 0 0 0 0 0 0 0 0 0 0 0 0
41894 - 0 0 0 0 0 0 0 0 0 0 0 0
41895 - 0 0 0 0 0 0 0 0 0 0 0 0
41896 - 0 0 0 0 0 0 0 0 0 0 0 0
41897 - 0 0 0 0 0 0 0 0 0 0 0 0
41898 - 0 0 0 0 0 0 0 0 0 0 0 0
41899 - 0 0 0 0 0 0 0 0 0 10 10 10
41900 - 30 30 30 78 78 78 50 50 50 104 69 6
41901 -192 133 9 216 158 10 236 178 12 236 186 11
41902 -232 195 16 241 208 19 244 214 54 245 215 43
41903 -246 215 20 246 215 20 241 208 19 198 155 10
41904 -200 144 11 216 158 10 156 118 10 2 2 6
41905 - 2 2 6 2 2 6 2 2 6 2 2 6
41906 - 6 6 6 90 90 90 54 54 54 18 18 18
41907 - 6 6 6 0 0 0 0 0 0 0 0 0
41908 - 0 0 0 0 0 0 0 0 0 0 0 0
41909 - 0 0 0 0 0 0 0 0 0 0 0 0
41910 - 0 0 0 0 0 0 0 0 0 0 0 0
41911 - 0 0 0 0 0 0 0 0 0 0 0 0
41912 - 0 0 0 0 0 0 0 0 0 0 0 0
41913 - 0 0 0 0 0 0 0 0 0 0 0 0
41914 - 0 0 0 0 0 0 0 0 0 0 0 0
41915 - 0 0 0 0 0 0 0 0 0 0 0 0
41916 - 0 0 0 0 0 0 0 0 0 0 0 0
41917 - 0 0 0 0 0 0 0 0 0 0 0 0
41918 - 0 0 0 0 0 0 0 0 0 0 0 0
41919 - 0 0 0 0 0 0 0 0 0 10 10 10
41920 - 30 30 30 78 78 78 46 46 46 22 22 22
41921 -137 92 6 210 162 10 239 182 13 238 190 10
41922 -238 202 15 241 208 19 246 215 20 246 215 20
41923 -241 208 19 203 166 17 185 133 11 210 150 10
41924 -216 158 10 210 150 10 102 78 10 2 2 6
41925 - 6 6 6 54 54 54 14 14 14 2 2 6
41926 - 2 2 6 62 62 62 74 74 74 30 30 30
41927 - 10 10 10 0 0 0 0 0 0 0 0 0
41928 - 0 0 0 0 0 0 0 0 0 0 0 0
41929 - 0 0 0 0 0 0 0 0 0 0 0 0
41930 - 0 0 0 0 0 0 0 0 0 0 0 0
41931 - 0 0 0 0 0 0 0 0 0 0 0 0
41932 - 0 0 0 0 0 0 0 0 0 0 0 0
41933 - 0 0 0 0 0 0 0 0 0 0 0 0
41934 - 0 0 0 0 0 0 0 0 0 0 0 0
41935 - 0 0 0 0 0 0 0 0 0 0 0 0
41936 - 0 0 0 0 0 0 0 0 0 0 0 0
41937 - 0 0 0 0 0 0 0 0 0 0 0 0
41938 - 0 0 0 0 0 0 0 0 0 0 0 0
41939 - 0 0 0 0 0 0 0 0 0 10 10 10
41940 - 34 34 34 78 78 78 50 50 50 6 6 6
41941 - 94 70 30 139 102 15 190 146 13 226 184 13
41942 -232 200 30 232 195 16 215 174 15 190 146 13
41943 -168 122 10 192 133 9 210 150 10 213 154 11
41944 -202 150 34 182 157 106 101 98 89 2 2 6
41945 - 2 2 6 78 78 78 116 116 116 58 58 58
41946 - 2 2 6 22 22 22 90 90 90 46 46 46
41947 - 18 18 18 6 6 6 0 0 0 0 0 0
41948 - 0 0 0 0 0 0 0 0 0 0 0 0
41949 - 0 0 0 0 0 0 0 0 0 0 0 0
41950 - 0 0 0 0 0 0 0 0 0 0 0 0
41951 - 0 0 0 0 0 0 0 0 0 0 0 0
41952 - 0 0 0 0 0 0 0 0 0 0 0 0
41953 - 0 0 0 0 0 0 0 0 0 0 0 0
41954 - 0 0 0 0 0 0 0 0 0 0 0 0
41955 - 0 0 0 0 0 0 0 0 0 0 0 0
41956 - 0 0 0 0 0 0 0 0 0 0 0 0
41957 - 0 0 0 0 0 0 0 0 0 0 0 0
41958 - 0 0 0 0 0 0 0 0 0 0 0 0
41959 - 0 0 0 0 0 0 0 0 0 10 10 10
41960 - 38 38 38 86 86 86 50 50 50 6 6 6
41961 -128 128 128 174 154 114 156 107 11 168 122 10
41962 -198 155 10 184 144 12 197 138 11 200 144 11
41963 -206 145 10 206 145 10 197 138 11 188 164 115
41964 -195 195 195 198 198 198 174 174 174 14 14 14
41965 - 2 2 6 22 22 22 116 116 116 116 116 116
41966 - 22 22 22 2 2 6 74 74 74 70 70 70
41967 - 30 30 30 10 10 10 0 0 0 0 0 0
41968 - 0 0 0 0 0 0 0 0 0 0 0 0
41969 - 0 0 0 0 0 0 0 0 0 0 0 0
41970 - 0 0 0 0 0 0 0 0 0 0 0 0
41971 - 0 0 0 0 0 0 0 0 0 0 0 0
41972 - 0 0 0 0 0 0 0 0 0 0 0 0
41973 - 0 0 0 0 0 0 0 0 0 0 0 0
41974 - 0 0 0 0 0 0 0 0 0 0 0 0
41975 - 0 0 0 0 0 0 0 0 0 0 0 0
41976 - 0 0 0 0 0 0 0 0 0 0 0 0
41977 - 0 0 0 0 0 0 0 0 0 0 0 0
41978 - 0 0 0 0 0 0 0 0 0 0 0 0
41979 - 0 0 0 0 0 0 6 6 6 18 18 18
41980 - 50 50 50 101 101 101 26 26 26 10 10 10
41981 -138 138 138 190 190 190 174 154 114 156 107 11
41982 -197 138 11 200 144 11 197 138 11 192 133 9
41983 -180 123 7 190 142 34 190 178 144 187 187 187
41984 -202 202 202 221 221 221 214 214 214 66 66 66
41985 - 2 2 6 2 2 6 50 50 50 62 62 62
41986 - 6 6 6 2 2 6 10 10 10 90 90 90
41987 - 50 50 50 18 18 18 6 6 6 0 0 0
41988 - 0 0 0 0 0 0 0 0 0 0 0 0
41989 - 0 0 0 0 0 0 0 0 0 0 0 0
41990 - 0 0 0 0 0 0 0 0 0 0 0 0
41991 - 0 0 0 0 0 0 0 0 0 0 0 0
41992 - 0 0 0 0 0 0 0 0 0 0 0 0
41993 - 0 0 0 0 0 0 0 0 0 0 0 0
41994 - 0 0 0 0 0 0 0 0 0 0 0 0
41995 - 0 0 0 0 0 0 0 0 0 0 0 0
41996 - 0 0 0 0 0 0 0 0 0 0 0 0
41997 - 0 0 0 0 0 0 0 0 0 0 0 0
41998 - 0 0 0 0 0 0 0 0 0 0 0 0
41999 - 0 0 0 0 0 0 10 10 10 34 34 34
42000 - 74 74 74 74 74 74 2 2 6 6 6 6
42001 -144 144 144 198 198 198 190 190 190 178 166 146
42002 -154 121 60 156 107 11 156 107 11 168 124 44
42003 -174 154 114 187 187 187 190 190 190 210 210 210
42004 -246 246 246 253 253 253 253 253 253 182 182 182
42005 - 6 6 6 2 2 6 2 2 6 2 2 6
42006 - 2 2 6 2 2 6 2 2 6 62 62 62
42007 - 74 74 74 34 34 34 14 14 14 0 0 0
42008 - 0 0 0 0 0 0 0 0 0 0 0 0
42009 - 0 0 0 0 0 0 0 0 0 0 0 0
42010 - 0 0 0 0 0 0 0 0 0 0 0 0
42011 - 0 0 0 0 0 0 0 0 0 0 0 0
42012 - 0 0 0 0 0 0 0 0 0 0 0 0
42013 - 0 0 0 0 0 0 0 0 0 0 0 0
42014 - 0 0 0 0 0 0 0 0 0 0 0 0
42015 - 0 0 0 0 0 0 0 0 0 0 0 0
42016 - 0 0 0 0 0 0 0 0 0 0 0 0
42017 - 0 0 0 0 0 0 0 0 0 0 0 0
42018 - 0 0 0 0 0 0 0 0 0 0 0 0
42019 - 0 0 0 10 10 10 22 22 22 54 54 54
42020 - 94 94 94 18 18 18 2 2 6 46 46 46
42021 -234 234 234 221 221 221 190 190 190 190 190 190
42022 -190 190 190 187 187 187 187 187 187 190 190 190
42023 -190 190 190 195 195 195 214 214 214 242 242 242
42024 -253 253 253 253 253 253 253 253 253 253 253 253
42025 - 82 82 82 2 2 6 2 2 6 2 2 6
42026 - 2 2 6 2 2 6 2 2 6 14 14 14
42027 - 86 86 86 54 54 54 22 22 22 6 6 6
42028 - 0 0 0 0 0 0 0 0 0 0 0 0
42029 - 0 0 0 0 0 0 0 0 0 0 0 0
42030 - 0 0 0 0 0 0 0 0 0 0 0 0
42031 - 0 0 0 0 0 0 0 0 0 0 0 0
42032 - 0 0 0 0 0 0 0 0 0 0 0 0
42033 - 0 0 0 0 0 0 0 0 0 0 0 0
42034 - 0 0 0 0 0 0 0 0 0 0 0 0
42035 - 0 0 0 0 0 0 0 0 0 0 0 0
42036 - 0 0 0 0 0 0 0 0 0 0 0 0
42037 - 0 0 0 0 0 0 0 0 0 0 0 0
42038 - 0 0 0 0 0 0 0 0 0 0 0 0
42039 - 6 6 6 18 18 18 46 46 46 90 90 90
42040 - 46 46 46 18 18 18 6 6 6 182 182 182
42041 -253 253 253 246 246 246 206 206 206 190 190 190
42042 -190 190 190 190 190 190 190 190 190 190 190 190
42043 -206 206 206 231 231 231 250 250 250 253 253 253
42044 -253 253 253 253 253 253 253 253 253 253 253 253
42045 -202 202 202 14 14 14 2 2 6 2 2 6
42046 - 2 2 6 2 2 6 2 2 6 2 2 6
42047 - 42 42 42 86 86 86 42 42 42 18 18 18
42048 - 6 6 6 0 0 0 0 0 0 0 0 0
42049 - 0 0 0 0 0 0 0 0 0 0 0 0
42050 - 0 0 0 0 0 0 0 0 0 0 0 0
42051 - 0 0 0 0 0 0 0 0 0 0 0 0
42052 - 0 0 0 0 0 0 0 0 0 0 0 0
42053 - 0 0 0 0 0 0 0 0 0 0 0 0
42054 - 0 0 0 0 0 0 0 0 0 0 0 0
42055 - 0 0 0 0 0 0 0 0 0 0 0 0
42056 - 0 0 0 0 0 0 0 0 0 0 0 0
42057 - 0 0 0 0 0 0 0 0 0 0 0 0
42058 - 0 0 0 0 0 0 0 0 0 6 6 6
42059 - 14 14 14 38 38 38 74 74 74 66 66 66
42060 - 2 2 6 6 6 6 90 90 90 250 250 250
42061 -253 253 253 253 253 253 238 238 238 198 198 198
42062 -190 190 190 190 190 190 195 195 195 221 221 221
42063 -246 246 246 253 253 253 253 253 253 253 253 253
42064 -253 253 253 253 253 253 253 253 253 253 253 253
42065 -253 253 253 82 82 82 2 2 6 2 2 6
42066 - 2 2 6 2 2 6 2 2 6 2 2 6
42067 - 2 2 6 78 78 78 70 70 70 34 34 34
42068 - 14 14 14 6 6 6 0 0 0 0 0 0
42069 - 0 0 0 0 0 0 0 0 0 0 0 0
42070 - 0 0 0 0 0 0 0 0 0 0 0 0
42071 - 0 0 0 0 0 0 0 0 0 0 0 0
42072 - 0 0 0 0 0 0 0 0 0 0 0 0
42073 - 0 0 0 0 0 0 0 0 0 0 0 0
42074 - 0 0 0 0 0 0 0 0 0 0 0 0
42075 - 0 0 0 0 0 0 0 0 0 0 0 0
42076 - 0 0 0 0 0 0 0 0 0 0 0 0
42077 - 0 0 0 0 0 0 0 0 0 0 0 0
42078 - 0 0 0 0 0 0 0 0 0 14 14 14
42079 - 34 34 34 66 66 66 78 78 78 6 6 6
42080 - 2 2 6 18 18 18 218 218 218 253 253 253
42081 -253 253 253 253 253 253 253 253 253 246 246 246
42082 -226 226 226 231 231 231 246 246 246 253 253 253
42083 -253 253 253 253 253 253 253 253 253 253 253 253
42084 -253 253 253 253 253 253 253 253 253 253 253 253
42085 -253 253 253 178 178 178 2 2 6 2 2 6
42086 - 2 2 6 2 2 6 2 2 6 2 2 6
42087 - 2 2 6 18 18 18 90 90 90 62 62 62
42088 - 30 30 30 10 10 10 0 0 0 0 0 0
42089 - 0 0 0 0 0 0 0 0 0 0 0 0
42090 - 0 0 0 0 0 0 0 0 0 0 0 0
42091 - 0 0 0 0 0 0 0 0 0 0 0 0
42092 - 0 0 0 0 0 0 0 0 0 0 0 0
42093 - 0 0 0 0 0 0 0 0 0 0 0 0
42094 - 0 0 0 0 0 0 0 0 0 0 0 0
42095 - 0 0 0 0 0 0 0 0 0 0 0 0
42096 - 0 0 0 0 0 0 0 0 0 0 0 0
42097 - 0 0 0 0 0 0 0 0 0 0 0 0
42098 - 0 0 0 0 0 0 10 10 10 26 26 26
42099 - 58 58 58 90 90 90 18 18 18 2 2 6
42100 - 2 2 6 110 110 110 253 253 253 253 253 253
42101 -253 253 253 253 253 253 253 253 253 253 253 253
42102 -250 250 250 253 253 253 253 253 253 253 253 253
42103 -253 253 253 253 253 253 253 253 253 253 253 253
42104 -253 253 253 253 253 253 253 253 253 253 253 253
42105 -253 253 253 231 231 231 18 18 18 2 2 6
42106 - 2 2 6 2 2 6 2 2 6 2 2 6
42107 - 2 2 6 2 2 6 18 18 18 94 94 94
42108 - 54 54 54 26 26 26 10 10 10 0 0 0
42109 - 0 0 0 0 0 0 0 0 0 0 0 0
42110 - 0 0 0 0 0 0 0 0 0 0 0 0
42111 - 0 0 0 0 0 0 0 0 0 0 0 0
42112 - 0 0 0 0 0 0 0 0 0 0 0 0
42113 - 0 0 0 0 0 0 0 0 0 0 0 0
42114 - 0 0 0 0 0 0 0 0 0 0 0 0
42115 - 0 0 0 0 0 0 0 0 0 0 0 0
42116 - 0 0 0 0 0 0 0 0 0 0 0 0
42117 - 0 0 0 0 0 0 0 0 0 0 0 0
42118 - 0 0 0 6 6 6 22 22 22 50 50 50
42119 - 90 90 90 26 26 26 2 2 6 2 2 6
42120 - 14 14 14 195 195 195 250 250 250 253 253 253
42121 -253 253 253 253 253 253 253 253 253 253 253 253
42122 -253 253 253 253 253 253 253 253 253 253 253 253
42123 -253 253 253 253 253 253 253 253 253 253 253 253
42124 -253 253 253 253 253 253 253 253 253 253 253 253
42125 -250 250 250 242 242 242 54 54 54 2 2 6
42126 - 2 2 6 2 2 6 2 2 6 2 2 6
42127 - 2 2 6 2 2 6 2 2 6 38 38 38
42128 - 86 86 86 50 50 50 22 22 22 6 6 6
42129 - 0 0 0 0 0 0 0 0 0 0 0 0
42130 - 0 0 0 0 0 0 0 0 0 0 0 0
42131 - 0 0 0 0 0 0 0 0 0 0 0 0
42132 - 0 0 0 0 0 0 0 0 0 0 0 0
42133 - 0 0 0 0 0 0 0 0 0 0 0 0
42134 - 0 0 0 0 0 0 0 0 0 0 0 0
42135 - 0 0 0 0 0 0 0 0 0 0 0 0
42136 - 0 0 0 0 0 0 0 0 0 0 0 0
42137 - 0 0 0 0 0 0 0 0 0 0 0 0
42138 - 6 6 6 14 14 14 38 38 38 82 82 82
42139 - 34 34 34 2 2 6 2 2 6 2 2 6
42140 - 42 42 42 195 195 195 246 246 246 253 253 253
42141 -253 253 253 253 253 253 253 253 253 250 250 250
42142 -242 242 242 242 242 242 250 250 250 253 253 253
42143 -253 253 253 253 253 253 253 253 253 253 253 253
42144 -253 253 253 250 250 250 246 246 246 238 238 238
42145 -226 226 226 231 231 231 101 101 101 6 6 6
42146 - 2 2 6 2 2 6 2 2 6 2 2 6
42147 - 2 2 6 2 2 6 2 2 6 2 2 6
42148 - 38 38 38 82 82 82 42 42 42 14 14 14
42149 - 6 6 6 0 0 0 0 0 0 0 0 0
42150 - 0 0 0 0 0 0 0 0 0 0 0 0
42151 - 0 0 0 0 0 0 0 0 0 0 0 0
42152 - 0 0 0 0 0 0 0 0 0 0 0 0
42153 - 0 0 0 0 0 0 0 0 0 0 0 0
42154 - 0 0 0 0 0 0 0 0 0 0 0 0
42155 - 0 0 0 0 0 0 0 0 0 0 0 0
42156 - 0 0 0 0 0 0 0 0 0 0 0 0
42157 - 0 0 0 0 0 0 0 0 0 0 0 0
42158 - 10 10 10 26 26 26 62 62 62 66 66 66
42159 - 2 2 6 2 2 6 2 2 6 6 6 6
42160 - 70 70 70 170 170 170 206 206 206 234 234 234
42161 -246 246 246 250 250 250 250 250 250 238 238 238
42162 -226 226 226 231 231 231 238 238 238 250 250 250
42163 -250 250 250 250 250 250 246 246 246 231 231 231
42164 -214 214 214 206 206 206 202 202 202 202 202 202
42165 -198 198 198 202 202 202 182 182 182 18 18 18
42166 - 2 2 6 2 2 6 2 2 6 2 2 6
42167 - 2 2 6 2 2 6 2 2 6 2 2 6
42168 - 2 2 6 62 62 62 66 66 66 30 30 30
42169 - 10 10 10 0 0 0 0 0 0 0 0 0
42170 - 0 0 0 0 0 0 0 0 0 0 0 0
42171 - 0 0 0 0 0 0 0 0 0 0 0 0
42172 - 0 0 0 0 0 0 0 0 0 0 0 0
42173 - 0 0 0 0 0 0 0 0 0 0 0 0
42174 - 0 0 0 0 0 0 0 0 0 0 0 0
42175 - 0 0 0 0 0 0 0 0 0 0 0 0
42176 - 0 0 0 0 0 0 0 0 0 0 0 0
42177 - 0 0 0 0 0 0 0 0 0 0 0 0
42178 - 14 14 14 42 42 42 82 82 82 18 18 18
42179 - 2 2 6 2 2 6 2 2 6 10 10 10
42180 - 94 94 94 182 182 182 218 218 218 242 242 242
42181 -250 250 250 253 253 253 253 253 253 250 250 250
42182 -234 234 234 253 253 253 253 253 253 253 253 253
42183 -253 253 253 253 253 253 253 253 253 246 246 246
42184 -238 238 238 226 226 226 210 210 210 202 202 202
42185 -195 195 195 195 195 195 210 210 210 158 158 158
42186 - 6 6 6 14 14 14 50 50 50 14 14 14
42187 - 2 2 6 2 2 6 2 2 6 2 2 6
42188 - 2 2 6 6 6 6 86 86 86 46 46 46
42189 - 18 18 18 6 6 6 0 0 0 0 0 0
42190 - 0 0 0 0 0 0 0 0 0 0 0 0
42191 - 0 0 0 0 0 0 0 0 0 0 0 0
42192 - 0 0 0 0 0 0 0 0 0 0 0 0
42193 - 0 0 0 0 0 0 0 0 0 0 0 0
42194 - 0 0 0 0 0 0 0 0 0 0 0 0
42195 - 0 0 0 0 0 0 0 0 0 0 0 0
42196 - 0 0 0 0 0 0 0 0 0 0 0 0
42197 - 0 0 0 0 0 0 0 0 0 6 6 6
42198 - 22 22 22 54 54 54 70 70 70 2 2 6
42199 - 2 2 6 10 10 10 2 2 6 22 22 22
42200 -166 166 166 231 231 231 250 250 250 253 253 253
42201 -253 253 253 253 253 253 253 253 253 250 250 250
42202 -242 242 242 253 253 253 253 253 253 253 253 253
42203 -253 253 253 253 253 253 253 253 253 253 253 253
42204 -253 253 253 253 253 253 253 253 253 246 246 246
42205 -231 231 231 206 206 206 198 198 198 226 226 226
42206 - 94 94 94 2 2 6 6 6 6 38 38 38
42207 - 30 30 30 2 2 6 2 2 6 2 2 6
42208 - 2 2 6 2 2 6 62 62 62 66 66 66
42209 - 26 26 26 10 10 10 0 0 0 0 0 0
42210 - 0 0 0 0 0 0 0 0 0 0 0 0
42211 - 0 0 0 0 0 0 0 0 0 0 0 0
42212 - 0 0 0 0 0 0 0 0 0 0 0 0
42213 - 0 0 0 0 0 0 0 0 0 0 0 0
42214 - 0 0 0 0 0 0 0 0 0 0 0 0
42215 - 0 0 0 0 0 0 0 0 0 0 0 0
42216 - 0 0 0 0 0 0 0 0 0 0 0 0
42217 - 0 0 0 0 0 0 0 0 0 10 10 10
42218 - 30 30 30 74 74 74 50 50 50 2 2 6
42219 - 26 26 26 26 26 26 2 2 6 106 106 106
42220 -238 238 238 253 253 253 253 253 253 253 253 253
42221 -253 253 253 253 253 253 253 253 253 253 253 253
42222 -253 253 253 253 253 253 253 253 253 253 253 253
42223 -253 253 253 253 253 253 253 253 253 253 253 253
42224 -253 253 253 253 253 253 253 253 253 253 253 253
42225 -253 253 253 246 246 246 218 218 218 202 202 202
42226 -210 210 210 14 14 14 2 2 6 2 2 6
42227 - 30 30 30 22 22 22 2 2 6 2 2 6
42228 - 2 2 6 2 2 6 18 18 18 86 86 86
42229 - 42 42 42 14 14 14 0 0 0 0 0 0
42230 - 0 0 0 0 0 0 0 0 0 0 0 0
42231 - 0 0 0 0 0 0 0 0 0 0 0 0
42232 - 0 0 0 0 0 0 0 0 0 0 0 0
42233 - 0 0 0 0 0 0 0 0 0 0 0 0
42234 - 0 0 0 0 0 0 0 0 0 0 0 0
42235 - 0 0 0 0 0 0 0 0 0 0 0 0
42236 - 0 0 0 0 0 0 0 0 0 0 0 0
42237 - 0 0 0 0 0 0 0 0 0 14 14 14
42238 - 42 42 42 90 90 90 22 22 22 2 2 6
42239 - 42 42 42 2 2 6 18 18 18 218 218 218
42240 -253 253 253 253 253 253 253 253 253 253 253 253
42241 -253 253 253 253 253 253 253 253 253 253 253 253
42242 -253 253 253 253 253 253 253 253 253 253 253 253
42243 -253 253 253 253 253 253 253 253 253 253 253 253
42244 -253 253 253 253 253 253 253 253 253 253 253 253
42245 -253 253 253 253 253 253 250 250 250 221 221 221
42246 -218 218 218 101 101 101 2 2 6 14 14 14
42247 - 18 18 18 38 38 38 10 10 10 2 2 6
42248 - 2 2 6 2 2 6 2 2 6 78 78 78
42249 - 58 58 58 22 22 22 6 6 6 0 0 0
42250 - 0 0 0 0 0 0 0 0 0 0 0 0
42251 - 0 0 0 0 0 0 0 0 0 0 0 0
42252 - 0 0 0 0 0 0 0 0 0 0 0 0
42253 - 0 0 0 0 0 0 0 0 0 0 0 0
42254 - 0 0 0 0 0 0 0 0 0 0 0 0
42255 - 0 0 0 0 0 0 0 0 0 0 0 0
42256 - 0 0 0 0 0 0 0 0 0 0 0 0
42257 - 0 0 0 0 0 0 6 6 6 18 18 18
42258 - 54 54 54 82 82 82 2 2 6 26 26 26
42259 - 22 22 22 2 2 6 123 123 123 253 253 253
42260 -253 253 253 253 253 253 253 253 253 253 253 253
42261 -253 253 253 253 253 253 253 253 253 253 253 253
42262 -253 253 253 253 253 253 253 253 253 253 253 253
42263 -253 253 253 253 253 253 253 253 253 253 253 253
42264 -253 253 253 253 253 253 253 253 253 253 253 253
42265 -253 253 253 253 253 253 253 253 253 250 250 250
42266 -238 238 238 198 198 198 6 6 6 38 38 38
42267 - 58 58 58 26 26 26 38 38 38 2 2 6
42268 - 2 2 6 2 2 6 2 2 6 46 46 46
42269 - 78 78 78 30 30 30 10 10 10 0 0 0
42270 - 0 0 0 0 0 0 0 0 0 0 0 0
42271 - 0 0 0 0 0 0 0 0 0 0 0 0
42272 - 0 0 0 0 0 0 0 0 0 0 0 0
42273 - 0 0 0 0 0 0 0 0 0 0 0 0
42274 - 0 0 0 0 0 0 0 0 0 0 0 0
42275 - 0 0 0 0 0 0 0 0 0 0 0 0
42276 - 0 0 0 0 0 0 0 0 0 0 0 0
42277 - 0 0 0 0 0 0 10 10 10 30 30 30
42278 - 74 74 74 58 58 58 2 2 6 42 42 42
42279 - 2 2 6 22 22 22 231 231 231 253 253 253
42280 -253 253 253 253 253 253 253 253 253 253 253 253
42281 -253 253 253 253 253 253 253 253 253 250 250 250
42282 -253 253 253 253 253 253 253 253 253 253 253 253
42283 -253 253 253 253 253 253 253 253 253 253 253 253
42284 -253 253 253 253 253 253 253 253 253 253 253 253
42285 -253 253 253 253 253 253 253 253 253 253 253 253
42286 -253 253 253 246 246 246 46 46 46 38 38 38
42287 - 42 42 42 14 14 14 38 38 38 14 14 14
42288 - 2 2 6 2 2 6 2 2 6 6 6 6
42289 - 86 86 86 46 46 46 14 14 14 0 0 0
42290 - 0 0 0 0 0 0 0 0 0 0 0 0
42291 - 0 0 0 0 0 0 0 0 0 0 0 0
42292 - 0 0 0 0 0 0 0 0 0 0 0 0
42293 - 0 0 0 0 0 0 0 0 0 0 0 0
42294 - 0 0 0 0 0 0 0 0 0 0 0 0
42295 - 0 0 0 0 0 0 0 0 0 0 0 0
42296 - 0 0 0 0 0 0 0 0 0 0 0 0
42297 - 0 0 0 6 6 6 14 14 14 42 42 42
42298 - 90 90 90 18 18 18 18 18 18 26 26 26
42299 - 2 2 6 116 116 116 253 253 253 253 253 253
42300 -253 253 253 253 253 253 253 253 253 253 253 253
42301 -253 253 253 253 253 253 250 250 250 238 238 238
42302 -253 253 253 253 253 253 253 253 253 253 253 253
42303 -253 253 253 253 253 253 253 253 253 253 253 253
42304 -253 253 253 253 253 253 253 253 253 253 253 253
42305 -253 253 253 253 253 253 253 253 253 253 253 253
42306 -253 253 253 253 253 253 94 94 94 6 6 6
42307 - 2 2 6 2 2 6 10 10 10 34 34 34
42308 - 2 2 6 2 2 6 2 2 6 2 2 6
42309 - 74 74 74 58 58 58 22 22 22 6 6 6
42310 - 0 0 0 0 0 0 0 0 0 0 0 0
42311 - 0 0 0 0 0 0 0 0 0 0 0 0
42312 - 0 0 0 0 0 0 0 0 0 0 0 0
42313 - 0 0 0 0 0 0 0 0 0 0 0 0
42314 - 0 0 0 0 0 0 0 0 0 0 0 0
42315 - 0 0 0 0 0 0 0 0 0 0 0 0
42316 - 0 0 0 0 0 0 0 0 0 0 0 0
42317 - 0 0 0 10 10 10 26 26 26 66 66 66
42318 - 82 82 82 2 2 6 38 38 38 6 6 6
42319 - 14 14 14 210 210 210 253 253 253 253 253 253
42320 -253 253 253 253 253 253 253 253 253 253 253 253
42321 -253 253 253 253 253 253 246 246 246 242 242 242
42322 -253 253 253 253 253 253 253 253 253 253 253 253
42323 -253 253 253 253 253 253 253 253 253 253 253 253
42324 -253 253 253 253 253 253 253 253 253 253 253 253
42325 -253 253 253 253 253 253 253 253 253 253 253 253
42326 -253 253 253 253 253 253 144 144 144 2 2 6
42327 - 2 2 6 2 2 6 2 2 6 46 46 46
42328 - 2 2 6 2 2 6 2 2 6 2 2 6
42329 - 42 42 42 74 74 74 30 30 30 10 10 10
42330 - 0 0 0 0 0 0 0 0 0 0 0 0
42331 - 0 0 0 0 0 0 0 0 0 0 0 0
42332 - 0 0 0 0 0 0 0 0 0 0 0 0
42333 - 0 0 0 0 0 0 0 0 0 0 0 0
42334 - 0 0 0 0 0 0 0 0 0 0 0 0
42335 - 0 0 0 0 0 0 0 0 0 0 0 0
42336 - 0 0 0 0 0 0 0 0 0 0 0 0
42337 - 6 6 6 14 14 14 42 42 42 90 90 90
42338 - 26 26 26 6 6 6 42 42 42 2 2 6
42339 - 74 74 74 250 250 250 253 253 253 253 253 253
42340 -253 253 253 253 253 253 253 253 253 253 253 253
42341 -253 253 253 253 253 253 242 242 242 242 242 242
42342 -253 253 253 253 253 253 253 253 253 253 253 253
42343 -253 253 253 253 253 253 253 253 253 253 253 253
42344 -253 253 253 253 253 253 253 253 253 253 253 253
42345 -253 253 253 253 253 253 253 253 253 253 253 253
42346 -253 253 253 253 253 253 182 182 182 2 2 6
42347 - 2 2 6 2 2 6 2 2 6 46 46 46
42348 - 2 2 6 2 2 6 2 2 6 2 2 6
42349 - 10 10 10 86 86 86 38 38 38 10 10 10
42350 - 0 0 0 0 0 0 0 0 0 0 0 0
42351 - 0 0 0 0 0 0 0 0 0 0 0 0
42352 - 0 0 0 0 0 0 0 0 0 0 0 0
42353 - 0 0 0 0 0 0 0 0 0 0 0 0
42354 - 0 0 0 0 0 0 0 0 0 0 0 0
42355 - 0 0 0 0 0 0 0 0 0 0 0 0
42356 - 0 0 0 0 0 0 0 0 0 0 0 0
42357 - 10 10 10 26 26 26 66 66 66 82 82 82
42358 - 2 2 6 22 22 22 18 18 18 2 2 6
42359 -149 149 149 253 253 253 253 253 253 253 253 253
42360 -253 253 253 253 253 253 253 253 253 253 253 253
42361 -253 253 253 253 253 253 234 234 234 242 242 242
42362 -253 253 253 253 253 253 253 253 253 253 253 253
42363 -253 253 253 253 253 253 253 253 253 253 253 253
42364 -253 253 253 253 253 253 253 253 253 253 253 253
42365 -253 253 253 253 253 253 253 253 253 253 253 253
42366 -253 253 253 253 253 253 206 206 206 2 2 6
42367 - 2 2 6 2 2 6 2 2 6 38 38 38
42368 - 2 2 6 2 2 6 2 2 6 2 2 6
42369 - 6 6 6 86 86 86 46 46 46 14 14 14
42370 - 0 0 0 0 0 0 0 0 0 0 0 0
42371 - 0 0 0 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 0 0 0 0 0 0 0 0 0
42376 - 0 0 0 0 0 0 0 0 0 6 6 6
42377 - 18 18 18 46 46 46 86 86 86 18 18 18
42378 - 2 2 6 34 34 34 10 10 10 6 6 6
42379 -210 210 210 253 253 253 253 253 253 253 253 253
42380 -253 253 253 253 253 253 253 253 253 253 253 253
42381 -253 253 253 253 253 253 234 234 234 242 242 242
42382 -253 253 253 253 253 253 253 253 253 253 253 253
42383 -253 253 253 253 253 253 253 253 253 253 253 253
42384 -253 253 253 253 253 253 253 253 253 253 253 253
42385 -253 253 253 253 253 253 253 253 253 253 253 253
42386 -253 253 253 253 253 253 221 221 221 6 6 6
42387 - 2 2 6 2 2 6 6 6 6 30 30 30
42388 - 2 2 6 2 2 6 2 2 6 2 2 6
42389 - 2 2 6 82 82 82 54 54 54 18 18 18
42390 - 6 6 6 0 0 0 0 0 0 0 0 0
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 0 0 0
42396 - 0 0 0 0 0 0 0 0 0 10 10 10
42397 - 26 26 26 66 66 66 62 62 62 2 2 6
42398 - 2 2 6 38 38 38 10 10 10 26 26 26
42399 -238 238 238 253 253 253 253 253 253 253 253 253
42400 -253 253 253 253 253 253 253 253 253 253 253 253
42401 -253 253 253 253 253 253 231 231 231 238 238 238
42402 -253 253 253 253 253 253 253 253 253 253 253 253
42403 -253 253 253 253 253 253 253 253 253 253 253 253
42404 -253 253 253 253 253 253 253 253 253 253 253 253
42405 -253 253 253 253 253 253 253 253 253 253 253 253
42406 -253 253 253 253 253 253 231 231 231 6 6 6
42407 - 2 2 6 2 2 6 10 10 10 30 30 30
42408 - 2 2 6 2 2 6 2 2 6 2 2 6
42409 - 2 2 6 66 66 66 58 58 58 22 22 22
42410 - 6 6 6 0 0 0 0 0 0 0 0 0
42411 - 0 0 0 0 0 0 0 0 0 0 0 0
42412 - 0 0 0 0 0 0 0 0 0 0 0 0
42413 - 0 0 0 0 0 0 0 0 0 0 0 0
42414 - 0 0 0 0 0 0 0 0 0 0 0 0
42415 - 0 0 0 0 0 0 0 0 0 0 0 0
42416 - 0 0 0 0 0 0 0 0 0 10 10 10
42417 - 38 38 38 78 78 78 6 6 6 2 2 6
42418 - 2 2 6 46 46 46 14 14 14 42 42 42
42419 -246 246 246 253 253 253 253 253 253 253 253 253
42420 -253 253 253 253 253 253 253 253 253 253 253 253
42421 -253 253 253 253 253 253 231 231 231 242 242 242
42422 -253 253 253 253 253 253 253 253 253 253 253 253
42423 -253 253 253 253 253 253 253 253 253 253 253 253
42424 -253 253 253 253 253 253 253 253 253 253 253 253
42425 -253 253 253 253 253 253 253 253 253 253 253 253
42426 -253 253 253 253 253 253 234 234 234 10 10 10
42427 - 2 2 6 2 2 6 22 22 22 14 14 14
42428 - 2 2 6 2 2 6 2 2 6 2 2 6
42429 - 2 2 6 66 66 66 62 62 62 22 22 22
42430 - 6 6 6 0 0 0 0 0 0 0 0 0
42431 - 0 0 0 0 0 0 0 0 0 0 0 0
42432 - 0 0 0 0 0 0 0 0 0 0 0 0
42433 - 0 0 0 0 0 0 0 0 0 0 0 0
42434 - 0 0 0 0 0 0 0 0 0 0 0 0
42435 - 0 0 0 0 0 0 0 0 0 0 0 0
42436 - 0 0 0 0 0 0 6 6 6 18 18 18
42437 - 50 50 50 74 74 74 2 2 6 2 2 6
42438 - 14 14 14 70 70 70 34 34 34 62 62 62
42439 -250 250 250 253 253 253 253 253 253 253 253 253
42440 -253 253 253 253 253 253 253 253 253 253 253 253
42441 -253 253 253 253 253 253 231 231 231 246 246 246
42442 -253 253 253 253 253 253 253 253 253 253 253 253
42443 -253 253 253 253 253 253 253 253 253 253 253 253
42444 -253 253 253 253 253 253 253 253 253 253 253 253
42445 -253 253 253 253 253 253 253 253 253 253 253 253
42446 -253 253 253 253 253 253 234 234 234 14 14 14
42447 - 2 2 6 2 2 6 30 30 30 2 2 6
42448 - 2 2 6 2 2 6 2 2 6 2 2 6
42449 - 2 2 6 66 66 66 62 62 62 22 22 22
42450 - 6 6 6 0 0 0 0 0 0 0 0 0
42451 - 0 0 0 0 0 0 0 0 0 0 0 0
42452 - 0 0 0 0 0 0 0 0 0 0 0 0
42453 - 0 0 0 0 0 0 0 0 0 0 0 0
42454 - 0 0 0 0 0 0 0 0 0 0 0 0
42455 - 0 0 0 0 0 0 0 0 0 0 0 0
42456 - 0 0 0 0 0 0 6 6 6 18 18 18
42457 - 54 54 54 62 62 62 2 2 6 2 2 6
42458 - 2 2 6 30 30 30 46 46 46 70 70 70
42459 -250 250 250 253 253 253 253 253 253 253 253 253
42460 -253 253 253 253 253 253 253 253 253 253 253 253
42461 -253 253 253 253 253 253 231 231 231 246 246 246
42462 -253 253 253 253 253 253 253 253 253 253 253 253
42463 -253 253 253 253 253 253 253 253 253 253 253 253
42464 -253 253 253 253 253 253 253 253 253 253 253 253
42465 -253 253 253 253 253 253 253 253 253 253 253 253
42466 -253 253 253 253 253 253 226 226 226 10 10 10
42467 - 2 2 6 6 6 6 30 30 30 2 2 6
42468 - 2 2 6 2 2 6 2 2 6 2 2 6
42469 - 2 2 6 66 66 66 58 58 58 22 22 22
42470 - 6 6 6 0 0 0 0 0 0 0 0 0
42471 - 0 0 0 0 0 0 0 0 0 0 0 0
42472 - 0 0 0 0 0 0 0 0 0 0 0 0
42473 - 0 0 0 0 0 0 0 0 0 0 0 0
42474 - 0 0 0 0 0 0 0 0 0 0 0 0
42475 - 0 0 0 0 0 0 0 0 0 0 0 0
42476 - 0 0 0 0 0 0 6 6 6 22 22 22
42477 - 58 58 58 62 62 62 2 2 6 2 2 6
42478 - 2 2 6 2 2 6 30 30 30 78 78 78
42479 -250 250 250 253 253 253 253 253 253 253 253 253
42480 -253 253 253 253 253 253 253 253 253 253 253 253
42481 -253 253 253 253 253 253 231 231 231 246 246 246
42482 -253 253 253 253 253 253 253 253 253 253 253 253
42483 -253 253 253 253 253 253 253 253 253 253 253 253
42484 -253 253 253 253 253 253 253 253 253 253 253 253
42485 -253 253 253 253 253 253 253 253 253 253 253 253
42486 -253 253 253 253 253 253 206 206 206 2 2 6
42487 - 22 22 22 34 34 34 18 14 6 22 22 22
42488 - 26 26 26 18 18 18 6 6 6 2 2 6
42489 - 2 2 6 82 82 82 54 54 54 18 18 18
42490 - 6 6 6 0 0 0 0 0 0 0 0 0
42491 - 0 0 0 0 0 0 0 0 0 0 0 0
42492 - 0 0 0 0 0 0 0 0 0 0 0 0
42493 - 0 0 0 0 0 0 0 0 0 0 0 0
42494 - 0 0 0 0 0 0 0 0 0 0 0 0
42495 - 0 0 0 0 0 0 0 0 0 0 0 0
42496 - 0 0 0 0 0 0 6 6 6 26 26 26
42497 - 62 62 62 106 106 106 74 54 14 185 133 11
42498 -210 162 10 121 92 8 6 6 6 62 62 62
42499 -238 238 238 253 253 253 253 253 253 253 253 253
42500 -253 253 253 253 253 253 253 253 253 253 253 253
42501 -253 253 253 253 253 253 231 231 231 246 246 246
42502 -253 253 253 253 253 253 253 253 253 253 253 253
42503 -253 253 253 253 253 253 253 253 253 253 253 253
42504 -253 253 253 253 253 253 253 253 253 253 253 253
42505 -253 253 253 253 253 253 253 253 253 253 253 253
42506 -253 253 253 253 253 253 158 158 158 18 18 18
42507 - 14 14 14 2 2 6 2 2 6 2 2 6
42508 - 6 6 6 18 18 18 66 66 66 38 38 38
42509 - 6 6 6 94 94 94 50 50 50 18 18 18
42510 - 6 6 6 0 0 0 0 0 0 0 0 0
42511 - 0 0 0 0 0 0 0 0 0 0 0 0
42512 - 0 0 0 0 0 0 0 0 0 0 0 0
42513 - 0 0 0 0 0 0 0 0 0 0 0 0
42514 - 0 0 0 0 0 0 0 0 0 0 0 0
42515 - 0 0 0 0 0 0 0 0 0 6 6 6
42516 - 10 10 10 10 10 10 18 18 18 38 38 38
42517 - 78 78 78 142 134 106 216 158 10 242 186 14
42518 -246 190 14 246 190 14 156 118 10 10 10 10
42519 - 90 90 90 238 238 238 253 253 253 253 253 253
42520 -253 253 253 253 253 253 253 253 253 253 253 253
42521 -253 253 253 253 253 253 231 231 231 250 250 250
42522 -253 253 253 253 253 253 253 253 253 253 253 253
42523 -253 253 253 253 253 253 253 253 253 253 253 253
42524 -253 253 253 253 253 253 253 253 253 253 253 253
42525 -253 253 253 253 253 253 253 253 253 246 230 190
42526 -238 204 91 238 204 91 181 142 44 37 26 9
42527 - 2 2 6 2 2 6 2 2 6 2 2 6
42528 - 2 2 6 2 2 6 38 38 38 46 46 46
42529 - 26 26 26 106 106 106 54 54 54 18 18 18
42530 - 6 6 6 0 0 0 0 0 0 0 0 0
42531 - 0 0 0 0 0 0 0 0 0 0 0 0
42532 - 0 0 0 0 0 0 0 0 0 0 0 0
42533 - 0 0 0 0 0 0 0 0 0 0 0 0
42534 - 0 0 0 0 0 0 0 0 0 0 0 0
42535 - 0 0 0 6 6 6 14 14 14 22 22 22
42536 - 30 30 30 38 38 38 50 50 50 70 70 70
42537 -106 106 106 190 142 34 226 170 11 242 186 14
42538 -246 190 14 246 190 14 246 190 14 154 114 10
42539 - 6 6 6 74 74 74 226 226 226 253 253 253
42540 -253 253 253 253 253 253 253 253 253 253 253 253
42541 -253 253 253 253 253 253 231 231 231 250 250 250
42542 -253 253 253 253 253 253 253 253 253 253 253 253
42543 -253 253 253 253 253 253 253 253 253 253 253 253
42544 -253 253 253 253 253 253 253 253 253 253 253 253
42545 -253 253 253 253 253 253 253 253 253 228 184 62
42546 -241 196 14 241 208 19 232 195 16 38 30 10
42547 - 2 2 6 2 2 6 2 2 6 2 2 6
42548 - 2 2 6 6 6 6 30 30 30 26 26 26
42549 -203 166 17 154 142 90 66 66 66 26 26 26
42550 - 6 6 6 0 0 0 0 0 0 0 0 0
42551 - 0 0 0 0 0 0 0 0 0 0 0 0
42552 - 0 0 0 0 0 0 0 0 0 0 0 0
42553 - 0 0 0 0 0 0 0 0 0 0 0 0
42554 - 0 0 0 0 0 0 0 0 0 0 0 0
42555 - 6 6 6 18 18 18 38 38 38 58 58 58
42556 - 78 78 78 86 86 86 101 101 101 123 123 123
42557 -175 146 61 210 150 10 234 174 13 246 186 14
42558 -246 190 14 246 190 14 246 190 14 238 190 10
42559 -102 78 10 2 2 6 46 46 46 198 198 198
42560 -253 253 253 253 253 253 253 253 253 253 253 253
42561 -253 253 253 253 253 253 234 234 234 242 242 242
42562 -253 253 253 253 253 253 253 253 253 253 253 253
42563 -253 253 253 253 253 253 253 253 253 253 253 253
42564 -253 253 253 253 253 253 253 253 253 253 253 253
42565 -253 253 253 253 253 253 253 253 253 224 178 62
42566 -242 186 14 241 196 14 210 166 10 22 18 6
42567 - 2 2 6 2 2 6 2 2 6 2 2 6
42568 - 2 2 6 2 2 6 6 6 6 121 92 8
42569 -238 202 15 232 195 16 82 82 82 34 34 34
42570 - 10 10 10 0 0 0 0 0 0 0 0 0
42571 - 0 0 0 0 0 0 0 0 0 0 0 0
42572 - 0 0 0 0 0 0 0 0 0 0 0 0
42573 - 0 0 0 0 0 0 0 0 0 0 0 0
42574 - 0 0 0 0 0 0 0 0 0 0 0 0
42575 - 14 14 14 38 38 38 70 70 70 154 122 46
42576 -190 142 34 200 144 11 197 138 11 197 138 11
42577 -213 154 11 226 170 11 242 186 14 246 190 14
42578 -246 190 14 246 190 14 246 190 14 246 190 14
42579 -225 175 15 46 32 6 2 2 6 22 22 22
42580 -158 158 158 250 250 250 253 253 253 253 253 253
42581 -253 253 253 253 253 253 253 253 253 253 253 253
42582 -253 253 253 253 253 253 253 253 253 253 253 253
42583 -253 253 253 253 253 253 253 253 253 253 253 253
42584 -253 253 253 253 253 253 253 253 253 253 253 253
42585 -253 253 253 250 250 250 242 242 242 224 178 62
42586 -239 182 13 236 186 11 213 154 11 46 32 6
42587 - 2 2 6 2 2 6 2 2 6 2 2 6
42588 - 2 2 6 2 2 6 61 42 6 225 175 15
42589 -238 190 10 236 186 11 112 100 78 42 42 42
42590 - 14 14 14 0 0 0 0 0 0 0 0 0
42591 - 0 0 0 0 0 0 0 0 0 0 0 0
42592 - 0 0 0 0 0 0 0 0 0 0 0 0
42593 - 0 0 0 0 0 0 0 0 0 0 0 0
42594 - 0 0 0 0 0 0 0 0 0 6 6 6
42595 - 22 22 22 54 54 54 154 122 46 213 154 11
42596 -226 170 11 230 174 11 226 170 11 226 170 11
42597 -236 178 12 242 186 14 246 190 14 246 190 14
42598 -246 190 14 246 190 14 246 190 14 246 190 14
42599 -241 196 14 184 144 12 10 10 10 2 2 6
42600 - 6 6 6 116 116 116 242 242 242 253 253 253
42601 -253 253 253 253 253 253 253 253 253 253 253 253
42602 -253 253 253 253 253 253 253 253 253 253 253 253
42603 -253 253 253 253 253 253 253 253 253 253 253 253
42604 -253 253 253 253 253 253 253 253 253 253 253 253
42605 -253 253 253 231 231 231 198 198 198 214 170 54
42606 -236 178 12 236 178 12 210 150 10 137 92 6
42607 - 18 14 6 2 2 6 2 2 6 2 2 6
42608 - 6 6 6 70 47 6 200 144 11 236 178 12
42609 -239 182 13 239 182 13 124 112 88 58 58 58
42610 - 22 22 22 6 6 6 0 0 0 0 0 0
42611 - 0 0 0 0 0 0 0 0 0 0 0 0
42612 - 0 0 0 0 0 0 0 0 0 0 0 0
42613 - 0 0 0 0 0 0 0 0 0 0 0 0
42614 - 0 0 0 0 0 0 0 0 0 10 10 10
42615 - 30 30 30 70 70 70 180 133 36 226 170 11
42616 -239 182 13 242 186 14 242 186 14 246 186 14
42617 -246 190 14 246 190 14 246 190 14 246 190 14
42618 -246 190 14 246 190 14 246 190 14 246 190 14
42619 -246 190 14 232 195 16 98 70 6 2 2 6
42620 - 2 2 6 2 2 6 66 66 66 221 221 221
42621 -253 253 253 253 253 253 253 253 253 253 253 253
42622 -253 253 253 253 253 253 253 253 253 253 253 253
42623 -253 253 253 253 253 253 253 253 253 253 253 253
42624 -253 253 253 253 253 253 253 253 253 253 253 253
42625 -253 253 253 206 206 206 198 198 198 214 166 58
42626 -230 174 11 230 174 11 216 158 10 192 133 9
42627 -163 110 8 116 81 8 102 78 10 116 81 8
42628 -167 114 7 197 138 11 226 170 11 239 182 13
42629 -242 186 14 242 186 14 162 146 94 78 78 78
42630 - 34 34 34 14 14 14 6 6 6 0 0 0
42631 - 0 0 0 0 0 0 0 0 0 0 0 0
42632 - 0 0 0 0 0 0 0 0 0 0 0 0
42633 - 0 0 0 0 0 0 0 0 0 0 0 0
42634 - 0 0 0 0 0 0 0 0 0 6 6 6
42635 - 30 30 30 78 78 78 190 142 34 226 170 11
42636 -239 182 13 246 190 14 246 190 14 246 190 14
42637 -246 190 14 246 190 14 246 190 14 246 190 14
42638 -246 190 14 246 190 14 246 190 14 246 190 14
42639 -246 190 14 241 196 14 203 166 17 22 18 6
42640 - 2 2 6 2 2 6 2 2 6 38 38 38
42641 -218 218 218 253 253 253 253 253 253 253 253 253
42642 -253 253 253 253 253 253 253 253 253 253 253 253
42643 -253 253 253 253 253 253 253 253 253 253 253 253
42644 -253 253 253 253 253 253 253 253 253 253 253 253
42645 -250 250 250 206 206 206 198 198 198 202 162 69
42646 -226 170 11 236 178 12 224 166 10 210 150 10
42647 -200 144 11 197 138 11 192 133 9 197 138 11
42648 -210 150 10 226 170 11 242 186 14 246 190 14
42649 -246 190 14 246 186 14 225 175 15 124 112 88
42650 - 62 62 62 30 30 30 14 14 14 6 6 6
42651 - 0 0 0 0 0 0 0 0 0 0 0 0
42652 - 0 0 0 0 0 0 0 0 0 0 0 0
42653 - 0 0 0 0 0 0 0 0 0 0 0 0
42654 - 0 0 0 0 0 0 0 0 0 10 10 10
42655 - 30 30 30 78 78 78 174 135 50 224 166 10
42656 -239 182 13 246 190 14 246 190 14 246 190 14
42657 -246 190 14 246 190 14 246 190 14 246 190 14
42658 -246 190 14 246 190 14 246 190 14 246 190 14
42659 -246 190 14 246 190 14 241 196 14 139 102 15
42660 - 2 2 6 2 2 6 2 2 6 2 2 6
42661 - 78 78 78 250 250 250 253 253 253 253 253 253
42662 -253 253 253 253 253 253 253 253 253 253 253 253
42663 -253 253 253 253 253 253 253 253 253 253 253 253
42664 -253 253 253 253 253 253 253 253 253 253 253 253
42665 -250 250 250 214 214 214 198 198 198 190 150 46
42666 -219 162 10 236 178 12 234 174 13 224 166 10
42667 -216 158 10 213 154 11 213 154 11 216 158 10
42668 -226 170 11 239 182 13 246 190 14 246 190 14
42669 -246 190 14 246 190 14 242 186 14 206 162 42
42670 -101 101 101 58 58 58 30 30 30 14 14 14
42671 - 6 6 6 0 0 0 0 0 0 0 0 0
42672 - 0 0 0 0 0 0 0 0 0 0 0 0
42673 - 0 0 0 0 0 0 0 0 0 0 0 0
42674 - 0 0 0 0 0 0 0 0 0 10 10 10
42675 - 30 30 30 74 74 74 174 135 50 216 158 10
42676 -236 178 12 246 190 14 246 190 14 246 190 14
42677 -246 190 14 246 190 14 246 190 14 246 190 14
42678 -246 190 14 246 190 14 246 190 14 246 190 14
42679 -246 190 14 246 190 14 241 196 14 226 184 13
42680 - 61 42 6 2 2 6 2 2 6 2 2 6
42681 - 22 22 22 238 238 238 253 253 253 253 253 253
42682 -253 253 253 253 253 253 253 253 253 253 253 253
42683 -253 253 253 253 253 253 253 253 253 253 253 253
42684 -253 253 253 253 253 253 253 253 253 253 253 253
42685 -253 253 253 226 226 226 187 187 187 180 133 36
42686 -216 158 10 236 178 12 239 182 13 236 178 12
42687 -230 174 11 226 170 11 226 170 11 230 174 11
42688 -236 178 12 242 186 14 246 190 14 246 190 14
42689 -246 190 14 246 190 14 246 186 14 239 182 13
42690 -206 162 42 106 106 106 66 66 66 34 34 34
42691 - 14 14 14 6 6 6 0 0 0 0 0 0
42692 - 0 0 0 0 0 0 0 0 0 0 0 0
42693 - 0 0 0 0 0 0 0 0 0 0 0 0
42694 - 0 0 0 0 0 0 0 0 0 6 6 6
42695 - 26 26 26 70 70 70 163 133 67 213 154 11
42696 -236 178 12 246 190 14 246 190 14 246 190 14
42697 -246 190 14 246 190 14 246 190 14 246 190 14
42698 -246 190 14 246 190 14 246 190 14 246 190 14
42699 -246 190 14 246 190 14 246 190 14 241 196 14
42700 -190 146 13 18 14 6 2 2 6 2 2 6
42701 - 46 46 46 246 246 246 253 253 253 253 253 253
42702 -253 253 253 253 253 253 253 253 253 253 253 253
42703 -253 253 253 253 253 253 253 253 253 253 253 253
42704 -253 253 253 253 253 253 253 253 253 253 253 253
42705 -253 253 253 221 221 221 86 86 86 156 107 11
42706 -216 158 10 236 178 12 242 186 14 246 186 14
42707 -242 186 14 239 182 13 239 182 13 242 186 14
42708 -242 186 14 246 186 14 246 190 14 246 190 14
42709 -246 190 14 246 190 14 246 190 14 246 190 14
42710 -242 186 14 225 175 15 142 122 72 66 66 66
42711 - 30 30 30 10 10 10 0 0 0 0 0 0
42712 - 0 0 0 0 0 0 0 0 0 0 0 0
42713 - 0 0 0 0 0 0 0 0 0 0 0 0
42714 - 0 0 0 0 0 0 0 0 0 6 6 6
42715 - 26 26 26 70 70 70 163 133 67 210 150 10
42716 -236 178 12 246 190 14 246 190 14 246 190 14
42717 -246 190 14 246 190 14 246 190 14 246 190 14
42718 -246 190 14 246 190 14 246 190 14 246 190 14
42719 -246 190 14 246 190 14 246 190 14 246 190 14
42720 -232 195 16 121 92 8 34 34 34 106 106 106
42721 -221 221 221 253 253 253 253 253 253 253 253 253
42722 -253 253 253 253 253 253 253 253 253 253 253 253
42723 -253 253 253 253 253 253 253 253 253 253 253 253
42724 -253 253 253 253 253 253 253 253 253 253 253 253
42725 -242 242 242 82 82 82 18 14 6 163 110 8
42726 -216 158 10 236 178 12 242 186 14 246 190 14
42727 -246 190 14 246 190 14 246 190 14 246 190 14
42728 -246 190 14 246 190 14 246 190 14 246 190 14
42729 -246 190 14 246 190 14 246 190 14 246 190 14
42730 -246 190 14 246 190 14 242 186 14 163 133 67
42731 - 46 46 46 18 18 18 6 6 6 0 0 0
42732 - 0 0 0 0 0 0 0 0 0 0 0 0
42733 - 0 0 0 0 0 0 0 0 0 0 0 0
42734 - 0 0 0 0 0 0 0 0 0 10 10 10
42735 - 30 30 30 78 78 78 163 133 67 210 150 10
42736 -236 178 12 246 186 14 246 190 14 246 190 14
42737 -246 190 14 246 190 14 246 190 14 246 190 14
42738 -246 190 14 246 190 14 246 190 14 246 190 14
42739 -246 190 14 246 190 14 246 190 14 246 190 14
42740 -241 196 14 215 174 15 190 178 144 253 253 253
42741 -253 253 253 253 253 253 253 253 253 253 253 253
42742 -253 253 253 253 253 253 253 253 253 253 253 253
42743 -253 253 253 253 253 253 253 253 253 253 253 253
42744 -253 253 253 253 253 253 253 253 253 218 218 218
42745 - 58 58 58 2 2 6 22 18 6 167 114 7
42746 -216 158 10 236 178 12 246 186 14 246 190 14
42747 -246 190 14 246 190 14 246 190 14 246 190 14
42748 -246 190 14 246 190 14 246 190 14 246 190 14
42749 -246 190 14 246 190 14 246 190 14 246 190 14
42750 -246 190 14 246 186 14 242 186 14 190 150 46
42751 - 54 54 54 22 22 22 6 6 6 0 0 0
42752 - 0 0 0 0 0 0 0 0 0 0 0 0
42753 - 0 0 0 0 0 0 0 0 0 0 0 0
42754 - 0 0 0 0 0 0 0 0 0 14 14 14
42755 - 38 38 38 86 86 86 180 133 36 213 154 11
42756 -236 178 12 246 186 14 246 190 14 246 190 14
42757 -246 190 14 246 190 14 246 190 14 246 190 14
42758 -246 190 14 246 190 14 246 190 14 246 190 14
42759 -246 190 14 246 190 14 246 190 14 246 190 14
42760 -246 190 14 232 195 16 190 146 13 214 214 214
42761 -253 253 253 253 253 253 253 253 253 253 253 253
42762 -253 253 253 253 253 253 253 253 253 253 253 253
42763 -253 253 253 253 253 253 253 253 253 253 253 253
42764 -253 253 253 250 250 250 170 170 170 26 26 26
42765 - 2 2 6 2 2 6 37 26 9 163 110 8
42766 -219 162 10 239 182 13 246 186 14 246 190 14
42767 -246 190 14 246 190 14 246 190 14 246 190 14
42768 -246 190 14 246 190 14 246 190 14 246 190 14
42769 -246 190 14 246 190 14 246 190 14 246 190 14
42770 -246 186 14 236 178 12 224 166 10 142 122 72
42771 - 46 46 46 18 18 18 6 6 6 0 0 0
42772 - 0 0 0 0 0 0 0 0 0 0 0 0
42773 - 0 0 0 0 0 0 0 0 0 0 0 0
42774 - 0 0 0 0 0 0 6 6 6 18 18 18
42775 - 50 50 50 109 106 95 192 133 9 224 166 10
42776 -242 186 14 246 190 14 246 190 14 246 190 14
42777 -246 190 14 246 190 14 246 190 14 246 190 14
42778 -246 190 14 246 190 14 246 190 14 246 190 14
42779 -246 190 14 246 190 14 246 190 14 246 190 14
42780 -242 186 14 226 184 13 210 162 10 142 110 46
42781 -226 226 226 253 253 253 253 253 253 253 253 253
42782 -253 253 253 253 253 253 253 253 253 253 253 253
42783 -253 253 253 253 253 253 253 253 253 253 253 253
42784 -198 198 198 66 66 66 2 2 6 2 2 6
42785 - 2 2 6 2 2 6 50 34 6 156 107 11
42786 -219 162 10 239 182 13 246 186 14 246 190 14
42787 -246 190 14 246 190 14 246 190 14 246 190 14
42788 -246 190 14 246 190 14 246 190 14 246 190 14
42789 -246 190 14 246 190 14 246 190 14 242 186 14
42790 -234 174 13 213 154 11 154 122 46 66 66 66
42791 - 30 30 30 10 10 10 0 0 0 0 0 0
42792 - 0 0 0 0 0 0 0 0 0 0 0 0
42793 - 0 0 0 0 0 0 0 0 0 0 0 0
42794 - 0 0 0 0 0 0 6 6 6 22 22 22
42795 - 58 58 58 154 121 60 206 145 10 234 174 13
42796 -242 186 14 246 186 14 246 190 14 246 190 14
42797 -246 190 14 246 190 14 246 190 14 246 190 14
42798 -246 190 14 246 190 14 246 190 14 246 190 14
42799 -246 190 14 246 190 14 246 190 14 246 190 14
42800 -246 186 14 236 178 12 210 162 10 163 110 8
42801 - 61 42 6 138 138 138 218 218 218 250 250 250
42802 -253 253 253 253 253 253 253 253 253 250 250 250
42803 -242 242 242 210 210 210 144 144 144 66 66 66
42804 - 6 6 6 2 2 6 2 2 6 2 2 6
42805 - 2 2 6 2 2 6 61 42 6 163 110 8
42806 -216 158 10 236 178 12 246 190 14 246 190 14
42807 -246 190 14 246 190 14 246 190 14 246 190 14
42808 -246 190 14 246 190 14 246 190 14 246 190 14
42809 -246 190 14 239 182 13 230 174 11 216 158 10
42810 -190 142 34 124 112 88 70 70 70 38 38 38
42811 - 18 18 18 6 6 6 0 0 0 0 0 0
42812 - 0 0 0 0 0 0 0 0 0 0 0 0
42813 - 0 0 0 0 0 0 0 0 0 0 0 0
42814 - 0 0 0 0 0 0 6 6 6 22 22 22
42815 - 62 62 62 168 124 44 206 145 10 224 166 10
42816 -236 178 12 239 182 13 242 186 14 242 186 14
42817 -246 186 14 246 190 14 246 190 14 246 190 14
42818 -246 190 14 246 190 14 246 190 14 246 190 14
42819 -246 190 14 246 190 14 246 190 14 246 190 14
42820 -246 190 14 236 178 12 216 158 10 175 118 6
42821 - 80 54 7 2 2 6 6 6 6 30 30 30
42822 - 54 54 54 62 62 62 50 50 50 38 38 38
42823 - 14 14 14 2 2 6 2 2 6 2 2 6
42824 - 2 2 6 2 2 6 2 2 6 2 2 6
42825 - 2 2 6 6 6 6 80 54 7 167 114 7
42826 -213 154 11 236 178 12 246 190 14 246 190 14
42827 -246 190 14 246 190 14 246 190 14 246 190 14
42828 -246 190 14 242 186 14 239 182 13 239 182 13
42829 -230 174 11 210 150 10 174 135 50 124 112 88
42830 - 82 82 82 54 54 54 34 34 34 18 18 18
42831 - 6 6 6 0 0 0 0 0 0 0 0 0
42832 - 0 0 0 0 0 0 0 0 0 0 0 0
42833 - 0 0 0 0 0 0 0 0 0 0 0 0
42834 - 0 0 0 0 0 0 6 6 6 18 18 18
42835 - 50 50 50 158 118 36 192 133 9 200 144 11
42836 -216 158 10 219 162 10 224 166 10 226 170 11
42837 -230 174 11 236 178 12 239 182 13 239 182 13
42838 -242 186 14 246 186 14 246 190 14 246 190 14
42839 -246 190 14 246 190 14 246 190 14 246 190 14
42840 -246 186 14 230 174 11 210 150 10 163 110 8
42841 -104 69 6 10 10 10 2 2 6 2 2 6
42842 - 2 2 6 2 2 6 2 2 6 2 2 6
42843 - 2 2 6 2 2 6 2 2 6 2 2 6
42844 - 2 2 6 2 2 6 2 2 6 2 2 6
42845 - 2 2 6 6 6 6 91 60 6 167 114 7
42846 -206 145 10 230 174 11 242 186 14 246 190 14
42847 -246 190 14 246 190 14 246 186 14 242 186 14
42848 -239 182 13 230 174 11 224 166 10 213 154 11
42849 -180 133 36 124 112 88 86 86 86 58 58 58
42850 - 38 38 38 22 22 22 10 10 10 6 6 6
42851 - 0 0 0 0 0 0 0 0 0 0 0 0
42852 - 0 0 0 0 0 0 0 0 0 0 0 0
42853 - 0 0 0 0 0 0 0 0 0 0 0 0
42854 - 0 0 0 0 0 0 0 0 0 14 14 14
42855 - 34 34 34 70 70 70 138 110 50 158 118 36
42856 -167 114 7 180 123 7 192 133 9 197 138 11
42857 -200 144 11 206 145 10 213 154 11 219 162 10
42858 -224 166 10 230 174 11 239 182 13 242 186 14
42859 -246 186 14 246 186 14 246 186 14 246 186 14
42860 -239 182 13 216 158 10 185 133 11 152 99 6
42861 -104 69 6 18 14 6 2 2 6 2 2 6
42862 - 2 2 6 2 2 6 2 2 6 2 2 6
42863 - 2 2 6 2 2 6 2 2 6 2 2 6
42864 - 2 2 6 2 2 6 2 2 6 2 2 6
42865 - 2 2 6 6 6 6 80 54 7 152 99 6
42866 -192 133 9 219 162 10 236 178 12 239 182 13
42867 -246 186 14 242 186 14 239 182 13 236 178 12
42868 -224 166 10 206 145 10 192 133 9 154 121 60
42869 - 94 94 94 62 62 62 42 42 42 22 22 22
42870 - 14 14 14 6 6 6 0 0 0 0 0 0
42871 - 0 0 0 0 0 0 0 0 0 0 0 0
42872 - 0 0 0 0 0 0 0 0 0 0 0 0
42873 - 0 0 0 0 0 0 0 0 0 0 0 0
42874 - 0 0 0 0 0 0 0 0 0 6 6 6
42875 - 18 18 18 34 34 34 58 58 58 78 78 78
42876 -101 98 89 124 112 88 142 110 46 156 107 11
42877 -163 110 8 167 114 7 175 118 6 180 123 7
42878 -185 133 11 197 138 11 210 150 10 219 162 10
42879 -226 170 11 236 178 12 236 178 12 234 174 13
42880 -219 162 10 197 138 11 163 110 8 130 83 6
42881 - 91 60 6 10 10 10 2 2 6 2 2 6
42882 - 18 18 18 38 38 38 38 38 38 38 38 38
42883 - 38 38 38 38 38 38 38 38 38 38 38 38
42884 - 38 38 38 38 38 38 26 26 26 2 2 6
42885 - 2 2 6 6 6 6 70 47 6 137 92 6
42886 -175 118 6 200 144 11 219 162 10 230 174 11
42887 -234 174 13 230 174 11 219 162 10 210 150 10
42888 -192 133 9 163 110 8 124 112 88 82 82 82
42889 - 50 50 50 30 30 30 14 14 14 6 6 6
42890 - 0 0 0 0 0 0 0 0 0 0 0 0
42891 - 0 0 0 0 0 0 0 0 0 0 0 0
42892 - 0 0 0 0 0 0 0 0 0 0 0 0
42893 - 0 0 0 0 0 0 0 0 0 0 0 0
42894 - 0 0 0 0 0 0 0 0 0 0 0 0
42895 - 6 6 6 14 14 14 22 22 22 34 34 34
42896 - 42 42 42 58 58 58 74 74 74 86 86 86
42897 -101 98 89 122 102 70 130 98 46 121 87 25
42898 -137 92 6 152 99 6 163 110 8 180 123 7
42899 -185 133 11 197 138 11 206 145 10 200 144 11
42900 -180 123 7 156 107 11 130 83 6 104 69 6
42901 - 50 34 6 54 54 54 110 110 110 101 98 89
42902 - 86 86 86 82 82 82 78 78 78 78 78 78
42903 - 78 78 78 78 78 78 78 78 78 78 78 78
42904 - 78 78 78 82 82 82 86 86 86 94 94 94
42905 -106 106 106 101 101 101 86 66 34 124 80 6
42906 -156 107 11 180 123 7 192 133 9 200 144 11
42907 -206 145 10 200 144 11 192 133 9 175 118 6
42908 -139 102 15 109 106 95 70 70 70 42 42 42
42909 - 22 22 22 10 10 10 0 0 0 0 0 0
42910 - 0 0 0 0 0 0 0 0 0 0 0 0
42911 - 0 0 0 0 0 0 0 0 0 0 0 0
42912 - 0 0 0 0 0 0 0 0 0 0 0 0
42913 - 0 0 0 0 0 0 0 0 0 0 0 0
42914 - 0 0 0 0 0 0 0 0 0 0 0 0
42915 - 0 0 0 0 0 0 6 6 6 10 10 10
42916 - 14 14 14 22 22 22 30 30 30 38 38 38
42917 - 50 50 50 62 62 62 74 74 74 90 90 90
42918 -101 98 89 112 100 78 121 87 25 124 80 6
42919 -137 92 6 152 99 6 152 99 6 152 99 6
42920 -138 86 6 124 80 6 98 70 6 86 66 30
42921 -101 98 89 82 82 82 58 58 58 46 46 46
42922 - 38 38 38 34 34 34 34 34 34 34 34 34
42923 - 34 34 34 34 34 34 34 34 34 34 34 34
42924 - 34 34 34 34 34 34 38 38 38 42 42 42
42925 - 54 54 54 82 82 82 94 86 76 91 60 6
42926 -134 86 6 156 107 11 167 114 7 175 118 6
42927 -175 118 6 167 114 7 152 99 6 121 87 25
42928 -101 98 89 62 62 62 34 34 34 18 18 18
42929 - 6 6 6 0 0 0 0 0 0 0 0 0
42930 - 0 0 0 0 0 0 0 0 0 0 0 0
42931 - 0 0 0 0 0 0 0 0 0 0 0 0
42932 - 0 0 0 0 0 0 0 0 0 0 0 0
42933 - 0 0 0 0 0 0 0 0 0 0 0 0
42934 - 0 0 0 0 0 0 0 0 0 0 0 0
42935 - 0 0 0 0 0 0 0 0 0 0 0 0
42936 - 0 0 0 6 6 6 6 6 6 10 10 10
42937 - 18 18 18 22 22 22 30 30 30 42 42 42
42938 - 50 50 50 66 66 66 86 86 86 101 98 89
42939 -106 86 58 98 70 6 104 69 6 104 69 6
42940 -104 69 6 91 60 6 82 62 34 90 90 90
42941 - 62 62 62 38 38 38 22 22 22 14 14 14
42942 - 10 10 10 10 10 10 10 10 10 10 10 10
42943 - 10 10 10 10 10 10 6 6 6 10 10 10
42944 - 10 10 10 10 10 10 10 10 10 14 14 14
42945 - 22 22 22 42 42 42 70 70 70 89 81 66
42946 - 80 54 7 104 69 6 124 80 6 137 92 6
42947 -134 86 6 116 81 8 100 82 52 86 86 86
42948 - 58 58 58 30 30 30 14 14 14 6 6 6
42949 - 0 0 0 0 0 0 0 0 0 0 0 0
42950 - 0 0 0 0 0 0 0 0 0 0 0 0
42951 - 0 0 0 0 0 0 0 0 0 0 0 0
42952 - 0 0 0 0 0 0 0 0 0 0 0 0
42953 - 0 0 0 0 0 0 0 0 0 0 0 0
42954 - 0 0 0 0 0 0 0 0 0 0 0 0
42955 - 0 0 0 0 0 0 0 0 0 0 0 0
42956 - 0 0 0 0 0 0 0 0 0 0 0 0
42957 - 0 0 0 6 6 6 10 10 10 14 14 14
42958 - 18 18 18 26 26 26 38 38 38 54 54 54
42959 - 70 70 70 86 86 86 94 86 76 89 81 66
42960 - 89 81 66 86 86 86 74 74 74 50 50 50
42961 - 30 30 30 14 14 14 6 6 6 0 0 0
42962 - 0 0 0 0 0 0 0 0 0 0 0 0
42963 - 0 0 0 0 0 0 0 0 0 0 0 0
42964 - 0 0 0 0 0 0 0 0 0 0 0 0
42965 - 6 6 6 18 18 18 34 34 34 58 58 58
42966 - 82 82 82 89 81 66 89 81 66 89 81 66
42967 - 94 86 66 94 86 76 74 74 74 50 50 50
42968 - 26 26 26 14 14 14 6 6 6 0 0 0
42969 - 0 0 0 0 0 0 0 0 0 0 0 0
42970 - 0 0 0 0 0 0 0 0 0 0 0 0
42971 - 0 0 0 0 0 0 0 0 0 0 0 0
42972 - 0 0 0 0 0 0 0 0 0 0 0 0
42973 - 0 0 0 0 0 0 0 0 0 0 0 0
42974 - 0 0 0 0 0 0 0 0 0 0 0 0
42975 - 0 0 0 0 0 0 0 0 0 0 0 0
42976 - 0 0 0 0 0 0 0 0 0 0 0 0
42977 - 0 0 0 0 0 0 0 0 0 0 0 0
42978 - 6 6 6 6 6 6 14 14 14 18 18 18
42979 - 30 30 30 38 38 38 46 46 46 54 54 54
42980 - 50 50 50 42 42 42 30 30 30 18 18 18
42981 - 10 10 10 0 0 0 0 0 0 0 0 0
42982 - 0 0 0 0 0 0 0 0 0 0 0 0
42983 - 0 0 0 0 0 0 0 0 0 0 0 0
42984 - 0 0 0 0 0 0 0 0 0 0 0 0
42985 - 0 0 0 6 6 6 14 14 14 26 26 26
42986 - 38 38 38 50 50 50 58 58 58 58 58 58
42987 - 54 54 54 42 42 42 30 30 30 18 18 18
42988 - 10 10 10 0 0 0 0 0 0 0 0 0
42989 - 0 0 0 0 0 0 0 0 0 0 0 0
42990 - 0 0 0 0 0 0 0 0 0 0 0 0
42991 - 0 0 0 0 0 0 0 0 0 0 0 0
42992 - 0 0 0 0 0 0 0 0 0 0 0 0
42993 - 0 0 0 0 0 0 0 0 0 0 0 0
42994 - 0 0 0 0 0 0 0 0 0 0 0 0
42995 - 0 0 0 0 0 0 0 0 0 0 0 0
42996 - 0 0 0 0 0 0 0 0 0 0 0 0
42997 - 0 0 0 0 0 0 0 0 0 0 0 0
42998 - 0 0 0 0 0 0 0 0 0 6 6 6
42999 - 6 6 6 10 10 10 14 14 14 18 18 18
43000 - 18 18 18 14 14 14 10 10 10 6 6 6
43001 - 0 0 0 0 0 0 0 0 0 0 0 0
43002 - 0 0 0 0 0 0 0 0 0 0 0 0
43003 - 0 0 0 0 0 0 0 0 0 0 0 0
43004 - 0 0 0 0 0 0 0 0 0 0 0 0
43005 - 0 0 0 0 0 0 0 0 0 6 6 6
43006 - 14 14 14 18 18 18 22 22 22 22 22 22
43007 - 18 18 18 14 14 14 10 10 10 6 6 6
43008 - 0 0 0 0 0 0 0 0 0 0 0 0
43009 - 0 0 0 0 0 0 0 0 0 0 0 0
43010 - 0 0 0 0 0 0 0 0 0 0 0 0
43011 - 0 0 0 0 0 0 0 0 0 0 0 0
43012 - 0 0 0 0 0 0 0 0 0 0 0 0
43013 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43014 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43015 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43016 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43017 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43018 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43019 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43020 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43021 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43022 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43023 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43024 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43025 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43026 +4 4 4 4 4 4
43027 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43028 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43029 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43030 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43031 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43032 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43033 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43034 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43035 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43036 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43037 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43038 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43039 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43040 +4 4 4 4 4 4
43041 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43042 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43043 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43044 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
43047 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43048 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43049 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43050 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43051 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43052 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43053 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43054 +4 4 4 4 4 4
43055 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43056 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43057 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43058 +4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
43061 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43062 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43063 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43064 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43065 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43066 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43067 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43068 +4 4 4 4 4 4
43069 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43070 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43071 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43072 +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 4 4 4 4 4 4 4 4 4 4 4 4
43075 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43076 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43077 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43078 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43079 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43080 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43081 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43082 +4 4 4 4 4 4
43083 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43084 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43085 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
43089 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43090 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43091 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43092 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43093 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43094 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43095 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43096 +4 4 4 4 4 4
43097 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43098 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43099 +4 4 4 4 4 4 4 4 4 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 3 3 3 0 0 0 0 0 0
43102 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
43103 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43104 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43105 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43106 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
43107 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
43108 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
43109 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43110 +4 4 4 4 4 4
43111 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43112 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43113 +4 4 4 4 4 4 4 4 4 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 2 2 2 0 0 0 3 4 3 26 28 28
43116 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
43117 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43118 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43119 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43120 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
43121 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
43122 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
43123 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43124 +4 4 4 4 4 4
43125 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43126 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43127 +4 4 4 4 4 4 4 4 4 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 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
43130 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
43131 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
43132 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43133 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43134 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
43135 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
43136 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
43137 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
43138 +4 4 4 4 4 4
43139 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43140 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43141 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43142 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
43143 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
43144 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
43145 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
43146 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43147 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
43148 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
43149 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
43150 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
43151 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
43152 +4 4 4 4 4 4
43153 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43154 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43155 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43156 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
43157 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
43158 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
43159 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
43160 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43161 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
43162 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
43163 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
43164 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
43165 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
43166 +4 4 4 4 4 4
43167 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43168 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43169 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
43170 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
43171 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
43172 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
43173 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
43174 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
43175 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
43176 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
43177 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
43178 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
43179 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
43180 +4 4 4 4 4 4
43181 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43182 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43183 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
43184 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
43185 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
43186 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
43187 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
43188 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
43189 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
43190 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
43191 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
43192 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
43193 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
43194 +4 4 4 4 4 4
43195 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43196 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43197 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
43198 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
43199 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
43200 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
43201 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
43202 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
43203 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
43204 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
43205 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
43206 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
43207 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
43208 +4 4 4 4 4 4
43209 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43210 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43211 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
43212 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
43213 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
43214 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
43215 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
43216 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
43217 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
43218 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
43219 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
43220 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
43221 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
43222 +4 4 4 4 4 4
43223 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43224 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43225 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
43226 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
43227 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
43228 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
43229 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
43230 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
43231 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
43232 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
43233 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
43234 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
43235 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
43236 +4 4 4 4 4 4
43237 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43238 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
43239 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
43240 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
43241 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
43242 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
43243 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
43244 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
43245 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
43246 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
43247 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
43248 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
43249 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
43250 +4 4 4 4 4 4
43251 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43252 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
43253 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
43254 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
43255 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
43256 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
43257 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
43258 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
43259 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
43260 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
43261 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
43262 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
43263 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
43264 +0 0 0 4 4 4
43265 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
43266 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
43267 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
43268 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
43269 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
43270 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
43271 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
43272 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
43273 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
43274 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
43275 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
43276 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
43277 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
43278 +2 0 0 0 0 0
43279 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
43280 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
43281 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
43282 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
43283 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
43284 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
43285 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
43286 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
43287 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
43288 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
43289 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
43290 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
43291 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
43292 +37 38 37 0 0 0
43293 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
43294 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
43295 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
43296 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
43297 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
43298 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
43299 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
43300 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
43301 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
43302 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
43303 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
43304 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
43305 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
43306 +85 115 134 4 0 0
43307 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
43308 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
43309 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
43310 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
43311 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
43312 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
43313 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
43314 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
43315 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
43316 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
43317 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
43318 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
43319 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
43320 +60 73 81 4 0 0
43321 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
43322 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
43323 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
43324 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
43325 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
43326 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
43327 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
43328 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
43329 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
43330 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
43331 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
43332 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
43333 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
43334 +16 19 21 4 0 0
43335 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
43336 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
43337 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
43338 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
43339 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
43340 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
43341 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
43342 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
43343 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
43344 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
43345 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
43346 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
43347 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
43348 +4 0 0 4 3 3
43349 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
43350 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
43351 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
43352 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
43353 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
43354 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
43355 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
43356 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
43357 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
43358 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
43359 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
43360 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
43361 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
43362 +3 2 2 4 4 4
43363 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
43364 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
43365 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
43366 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
43367 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
43368 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
43369 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
43370 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
43371 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
43372 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
43373 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
43374 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
43375 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
43376 +4 4 4 4 4 4
43377 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
43378 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
43379 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
43380 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
43381 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
43382 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
43383 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
43384 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
43385 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
43386 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
43387 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
43388 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
43389 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
43390 +4 4 4 4 4 4
43391 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
43392 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
43393 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
43394 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
43395 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
43396 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
43397 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
43398 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
43399 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
43400 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
43401 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
43402 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
43403 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
43404 +5 5 5 5 5 5
43405 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
43406 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
43407 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
43408 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
43409 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
43410 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43411 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
43412 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
43413 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
43414 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
43415 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
43416 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
43417 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
43418 +5 5 5 4 4 4
43419 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
43420 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
43421 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
43422 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
43423 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
43424 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
43425 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
43426 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
43427 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
43428 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
43429 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
43430 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
43431 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43432 +4 4 4 4 4 4
43433 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
43434 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
43435 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
43436 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
43437 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
43438 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43439 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43440 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
43441 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
43442 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
43443 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
43444 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
43445 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43446 +4 4 4 4 4 4
43447 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
43448 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
43449 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
43450 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
43451 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
43452 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
43453 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
43454 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
43455 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
43456 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
43457 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
43458 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43459 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43460 +4 4 4 4 4 4
43461 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
43462 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
43463 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
43464 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
43465 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
43466 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43467 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43468 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
43469 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
43470 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
43471 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
43472 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43473 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43474 +4 4 4 4 4 4
43475 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
43476 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
43477 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
43478 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
43479 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
43480 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
43481 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
43482 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
43483 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
43484 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
43485 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43486 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43487 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43488 +4 4 4 4 4 4
43489 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
43490 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
43491 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
43492 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
43493 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
43494 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
43495 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
43496 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
43497 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
43498 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
43499 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
43500 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43501 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43502 +4 4 4 4 4 4
43503 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
43504 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
43505 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
43506 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
43507 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
43508 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
43509 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
43510 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
43511 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
43512 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
43513 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
43514 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43515 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43516 +4 4 4 4 4 4
43517 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
43518 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
43519 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
43520 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
43521 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
43522 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
43523 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
43524 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
43525 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
43526 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
43527 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43528 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43529 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43530 +4 4 4 4 4 4
43531 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
43532 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
43533 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
43534 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
43535 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43536 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
43537 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
43538 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
43539 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
43540 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
43541 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43542 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43543 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43544 +4 4 4 4 4 4
43545 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
43546 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
43547 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
43548 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
43549 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43550 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
43551 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
43552 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
43553 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
43554 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
43555 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43556 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43557 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43558 +4 4 4 4 4 4
43559 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
43560 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
43561 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
43562 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
43563 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43564 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
43565 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
43566 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
43567 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
43568 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43569 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43570 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43571 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43572 +4 4 4 4 4 4
43573 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
43574 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
43575 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
43576 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
43577 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
43578 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
43579 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
43580 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
43581 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43582 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43583 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43584 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43585 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43586 +4 4 4 4 4 4
43587 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
43588 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
43589 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
43590 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
43591 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43592 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
43593 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
43594 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
43595 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
43596 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43597 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43598 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43599 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43600 +4 4 4 4 4 4
43601 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
43602 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
43603 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
43604 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
43605 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
43606 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
43607 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
43608 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
43609 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43610 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43611 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43612 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43613 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43614 +4 4 4 4 4 4
43615 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
43616 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
43617 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
43618 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
43619 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
43620 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
43621 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
43622 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
43623 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
43624 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43625 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43626 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43627 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43628 +4 4 4 4 4 4
43629 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
43630 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
43631 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
43632 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
43633 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
43634 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
43635 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
43636 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
43637 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43638 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43639 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43640 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43641 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43642 +4 4 4 4 4 4
43643 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
43644 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
43645 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
43646 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
43647 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
43648 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
43649 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
43650 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
43651 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
43652 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43653 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43654 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43655 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43656 +4 4 4 4 4 4
43657 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
43658 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
43659 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
43660 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
43661 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
43662 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
43663 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
43664 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
43665 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43666 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43667 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43668 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43669 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43670 +4 4 4 4 4 4
43671 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43672 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
43673 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
43674 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
43675 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
43676 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
43677 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
43678 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
43679 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
43680 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43681 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43682 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43683 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43684 +4 4 4 4 4 4
43685 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
43686 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
43687 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
43688 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
43689 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
43690 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
43691 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43692 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
43693 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43694 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43695 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43696 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43697 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43698 +4 4 4 4 4 4
43699 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43700 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
43701 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
43702 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
43703 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
43704 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
43705 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43706 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
43707 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
43708 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43709 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43710 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43711 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43712 +4 4 4 4 4 4
43713 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
43714 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
43715 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
43716 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
43717 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
43718 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
43719 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
43720 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
43721 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
43722 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43723 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43724 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43725 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43726 +4 4 4 4 4 4
43727 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43728 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
43729 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
43730 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
43731 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
43732 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
43733 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
43734 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
43735 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
43736 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43737 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43738 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43739 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43740 +4 4 4 4 4 4
43741 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
43742 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
43743 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
43744 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
43745 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
43746 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
43747 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
43748 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
43749 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
43750 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43751 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43752 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43753 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43754 +4 4 4 4 4 4
43755 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43756 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
43757 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
43758 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
43759 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
43760 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
43761 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
43762 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
43763 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
43764 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43765 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43766 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43767 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43768 +4 4 4 4 4 4
43769 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
43770 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
43771 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
43772 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
43773 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
43774 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
43775 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
43776 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
43777 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
43778 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
43779 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43780 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43781 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43782 +4 4 4 4 4 4
43783 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
43784 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
43785 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
43786 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
43787 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
43788 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
43789 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
43790 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
43791 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
43792 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
43793 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43794 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43795 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43796 +4 4 4 4 4 4
43797 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
43798 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
43799 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
43800 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
43801 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
43802 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
43803 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43804 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
43805 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
43806 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
43807 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43808 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43809 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43810 +4 4 4 4 4 4
43811 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
43812 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
43813 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
43814 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
43815 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
43816 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
43817 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
43818 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
43819 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
43820 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
43821 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43822 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43823 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43824 +4 4 4 4 4 4
43825 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
43826 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
43827 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
43828 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
43829 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
43830 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
43831 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
43832 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
43833 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
43834 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
43835 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43836 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43837 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43838 +4 4 4 4 4 4
43839 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
43840 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
43841 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
43842 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
43843 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
43844 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
43845 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
43846 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
43847 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
43848 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
43849 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43850 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43851 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43852 +4 4 4 4 4 4
43853 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
43854 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
43855 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
43856 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
43857 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
43858 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
43859 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
43860 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
43861 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
43862 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
43863 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43864 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43865 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43866 +4 4 4 4 4 4
43867 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
43868 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
43869 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
43870 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
43871 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
43872 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
43873 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
43874 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
43875 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
43876 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43877 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43878 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43879 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43880 +4 4 4 4 4 4
43881 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
43882 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
43883 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
43884 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
43885 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
43886 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
43887 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
43888 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
43889 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
43890 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43891 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43892 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43893 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43894 +4 4 4 4 4 4
43895 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
43896 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
43897 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
43898 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
43899 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
43900 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
43901 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
43902 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
43903 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
43904 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43905 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43906 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43907 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43908 +4 4 4 4 4 4
43909 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
43910 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
43911 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
43912 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
43913 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
43914 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
43915 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
43916 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
43917 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43918 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43919 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43920 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43921 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43922 +4 4 4 4 4 4
43923 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
43924 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
43925 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
43926 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
43927 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
43928 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
43929 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
43930 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
43931 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43932 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43933 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43934 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43935 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43936 +4 4 4 4 4 4
43937 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
43938 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
43939 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
43940 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
43941 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
43942 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
43943 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
43944 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
43945 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43946 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43947 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43948 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43949 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43950 +4 4 4 4 4 4
43951 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
43952 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
43953 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
43954 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
43955 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
43956 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
43957 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
43958 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
43959 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43960 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43961 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43962 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43963 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43964 +4 4 4 4 4 4
43965 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43966 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
43967 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
43968 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
43969 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
43970 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
43971 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
43972 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
43973 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43974 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43975 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43976 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43977 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43978 +4 4 4 4 4 4
43979 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43980 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
43981 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
43982 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
43983 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
43984 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
43985 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
43986 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43987 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43988 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43989 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43990 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43991 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43992 +4 4 4 4 4 4
43993 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43994 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43995 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
43996 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
43997 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
43998 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
43999 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
44000 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
44001 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44002 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44003 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44004 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44005 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44006 +4 4 4 4 4 4
44007 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44008 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44009 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
44010 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
44011 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
44012 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
44013 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
44014 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44015 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44016 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44017 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44018 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44019 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44020 +4 4 4 4 4 4
44021 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44022 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44023 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44024 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
44025 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
44026 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
44027 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
44028 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44029 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44030 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44031 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44032 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44033 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44034 +4 4 4 4 4 4
44035 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44036 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44037 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44038 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
44039 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
44040 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
44041 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
44042 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44043 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44044 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44045 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44046 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44047 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44048 +4 4 4 4 4 4
44049 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44050 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44051 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44052 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
44053 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
44054 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
44055 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
44056 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44057 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44058 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44059 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44060 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44061 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44062 +4 4 4 4 4 4
44063 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44064 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44065 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44066 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
44067 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
44068 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
44069 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44070 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44071 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44072 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44073 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44074 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44075 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44076 +4 4 4 4 4 4
44077 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44078 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44079 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44080 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44081 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
44082 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
44083 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
44084 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44085 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44086 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44087 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44088 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44089 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44090 +4 4 4 4 4 4
44091 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44092 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44093 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44094 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44095 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
44096 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
44097 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44098 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44099 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44100 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44101 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44102 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44103 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44104 +4 4 4 4 4 4
44105 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44106 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44107 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44108 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44109 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
44110 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
44111 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44112 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44113 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44114 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44115 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44116 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44117 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44118 +4 4 4 4 4 4
44119 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44120 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44121 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44122 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44123 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
44124 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
44125 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44126 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44127 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44128 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44129 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44130 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44131 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44132 +4 4 4 4 4 4
44133 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
44134 index 86d449e..af6a7f7 100644
44135 --- a/drivers/video/udlfb.c
44136 +++ b/drivers/video/udlfb.c
44137 @@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
44138 dlfb_urb_completion(urb);
44139
44140 error:
44141 - atomic_add(bytes_sent, &dev->bytes_sent);
44142 - atomic_add(bytes_identical, &dev->bytes_identical);
44143 - atomic_add(width*height*2, &dev->bytes_rendered);
44144 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
44145 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
44146 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
44147 end_cycles = get_cycles();
44148 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
44149 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
44150 >> 10)), /* Kcycles */
44151 &dev->cpu_kcycles_used);
44152
44153 @@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
44154 dlfb_urb_completion(urb);
44155
44156 error:
44157 - atomic_add(bytes_sent, &dev->bytes_sent);
44158 - atomic_add(bytes_identical, &dev->bytes_identical);
44159 - atomic_add(bytes_rendered, &dev->bytes_rendered);
44160 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
44161 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
44162 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
44163 end_cycles = get_cycles();
44164 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
44165 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
44166 >> 10)), /* Kcycles */
44167 &dev->cpu_kcycles_used);
44168 }
44169 @@ -1372,7 +1372,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
44170 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44171 struct dlfb_data *dev = fb_info->par;
44172 return snprintf(buf, PAGE_SIZE, "%u\n",
44173 - atomic_read(&dev->bytes_rendered));
44174 + atomic_read_unchecked(&dev->bytes_rendered));
44175 }
44176
44177 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
44178 @@ -1380,7 +1380,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
44179 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44180 struct dlfb_data *dev = fb_info->par;
44181 return snprintf(buf, PAGE_SIZE, "%u\n",
44182 - atomic_read(&dev->bytes_identical));
44183 + atomic_read_unchecked(&dev->bytes_identical));
44184 }
44185
44186 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
44187 @@ -1388,7 +1388,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
44188 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44189 struct dlfb_data *dev = fb_info->par;
44190 return snprintf(buf, PAGE_SIZE, "%u\n",
44191 - atomic_read(&dev->bytes_sent));
44192 + atomic_read_unchecked(&dev->bytes_sent));
44193 }
44194
44195 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
44196 @@ -1396,7 +1396,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
44197 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44198 struct dlfb_data *dev = fb_info->par;
44199 return snprintf(buf, PAGE_SIZE, "%u\n",
44200 - atomic_read(&dev->cpu_kcycles_used));
44201 + atomic_read_unchecked(&dev->cpu_kcycles_used));
44202 }
44203
44204 static ssize_t edid_show(
44205 @@ -1456,10 +1456,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
44206 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44207 struct dlfb_data *dev = fb_info->par;
44208
44209 - atomic_set(&dev->bytes_rendered, 0);
44210 - atomic_set(&dev->bytes_identical, 0);
44211 - atomic_set(&dev->bytes_sent, 0);
44212 - atomic_set(&dev->cpu_kcycles_used, 0);
44213 + atomic_set_unchecked(&dev->bytes_rendered, 0);
44214 + atomic_set_unchecked(&dev->bytes_identical, 0);
44215 + atomic_set_unchecked(&dev->bytes_sent, 0);
44216 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
44217
44218 return count;
44219 }
44220 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
44221 index 2f8f82d..191de37 100644
44222 --- a/drivers/video/uvesafb.c
44223 +++ b/drivers/video/uvesafb.c
44224 @@ -19,6 +19,7 @@
44225 #include <linux/io.h>
44226 #include <linux/mutex.h>
44227 #include <linux/slab.h>
44228 +#include <linux/moduleloader.h>
44229 #include <video/edid.h>
44230 #include <video/uvesafb.h>
44231 #ifdef CONFIG_X86
44232 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
44233 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
44234 par->pmi_setpal = par->ypan = 0;
44235 } else {
44236 +
44237 +#ifdef CONFIG_PAX_KERNEXEC
44238 +#ifdef CONFIG_MODULES
44239 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
44240 +#endif
44241 + if (!par->pmi_code) {
44242 + par->pmi_setpal = par->ypan = 0;
44243 + return 0;
44244 + }
44245 +#endif
44246 +
44247 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
44248 + task->t.regs.edi);
44249 +
44250 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44251 + pax_open_kernel();
44252 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
44253 + pax_close_kernel();
44254 +
44255 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
44256 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
44257 +#else
44258 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
44259 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
44260 +#endif
44261 +
44262 printk(KERN_INFO "uvesafb: protected mode interface info at "
44263 "%04x:%04x\n",
44264 (u16)task->t.regs.es, (u16)task->t.regs.edi);
44265 @@ -818,13 +841,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
44266 par->ypan = ypan;
44267
44268 if (par->pmi_setpal || par->ypan) {
44269 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
44270 if (__supported_pte_mask & _PAGE_NX) {
44271 par->pmi_setpal = par->ypan = 0;
44272 printk(KERN_WARNING "uvesafb: NX protection is actively."
44273 "We have better not to use the PMI.\n");
44274 - } else {
44275 + } else
44276 +#endif
44277 uvesafb_vbe_getpmi(task, par);
44278 - }
44279 }
44280 #else
44281 /* The protected mode interface is not available on non-x86. */
44282 @@ -1838,6 +1862,11 @@ out:
44283 if (par->vbe_modes)
44284 kfree(par->vbe_modes);
44285
44286 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44287 + if (par->pmi_code)
44288 + module_free_exec(NULL, par->pmi_code);
44289 +#endif
44290 +
44291 framebuffer_release(info);
44292 return err;
44293 }
44294 @@ -1864,6 +1893,12 @@ static int uvesafb_remove(struct platform_device *dev)
44295 kfree(par->vbe_state_orig);
44296 if (par->vbe_state_saved)
44297 kfree(par->vbe_state_saved);
44298 +
44299 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44300 + if (par->pmi_code)
44301 + module_free_exec(NULL, par->pmi_code);
44302 +#endif
44303 +
44304 }
44305
44306 framebuffer_release(info);
44307 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
44308 index 501b340..86bd4cf 100644
44309 --- a/drivers/video/vesafb.c
44310 +++ b/drivers/video/vesafb.c
44311 @@ -9,6 +9,7 @@
44312 */
44313
44314 #include <linux/module.h>
44315 +#include <linux/moduleloader.h>
44316 #include <linux/kernel.h>
44317 #include <linux/errno.h>
44318 #include <linux/string.h>
44319 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
44320 static int vram_total __initdata; /* Set total amount of memory */
44321 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
44322 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
44323 -static void (*pmi_start)(void) __read_mostly;
44324 -static void (*pmi_pal) (void) __read_mostly;
44325 +static void (*pmi_start)(void) __read_only;
44326 +static void (*pmi_pal) (void) __read_only;
44327 static int depth __read_mostly;
44328 static int vga_compat __read_mostly;
44329 /* --------------------------------------------------------------------- */
44330 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
44331 unsigned int size_vmode;
44332 unsigned int size_remap;
44333 unsigned int size_total;
44334 + void *pmi_code = NULL;
44335
44336 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
44337 return -ENODEV;
44338 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
44339 size_remap = size_total;
44340 vesafb_fix.smem_len = size_remap;
44341
44342 -#ifndef __i386__
44343 - screen_info.vesapm_seg = 0;
44344 -#endif
44345 -
44346 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
44347 printk(KERN_WARNING
44348 "vesafb: cannot reserve video memory at 0x%lx\n",
44349 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
44350 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
44351 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
44352
44353 +#ifdef __i386__
44354 +
44355 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44356 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
44357 + if (!pmi_code)
44358 +#elif !defined(CONFIG_PAX_KERNEXEC)
44359 + if (0)
44360 +#endif
44361 +
44362 +#endif
44363 + screen_info.vesapm_seg = 0;
44364 +
44365 if (screen_info.vesapm_seg) {
44366 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
44367 - screen_info.vesapm_seg,screen_info.vesapm_off);
44368 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
44369 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
44370 }
44371
44372 if (screen_info.vesapm_seg < 0xc000)
44373 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
44374
44375 if (ypan || pmi_setpal) {
44376 unsigned short *pmi_base;
44377 +
44378 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
44379 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
44380 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
44381 +
44382 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44383 + pax_open_kernel();
44384 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
44385 +#else
44386 + pmi_code = pmi_base;
44387 +#endif
44388 +
44389 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
44390 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
44391 +
44392 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44393 + pmi_start = ktva_ktla(pmi_start);
44394 + pmi_pal = ktva_ktla(pmi_pal);
44395 + pax_close_kernel();
44396 +#endif
44397 +
44398 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
44399 if (pmi_base[3]) {
44400 printk(KERN_INFO "vesafb: pmi: ports = ");
44401 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
44402 info->node, info->fix.id);
44403 return 0;
44404 err:
44405 +
44406 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44407 + module_free_exec(NULL, pmi_code);
44408 +#endif
44409 +
44410 if (info->screen_base)
44411 iounmap(info->screen_base);
44412 framebuffer_release(info);
44413 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
44414 index 88714ae..16c2e11 100644
44415 --- a/drivers/video/via/via_clock.h
44416 +++ b/drivers/video/via/via_clock.h
44417 @@ -56,7 +56,7 @@ struct via_clock {
44418
44419 void (*set_engine_pll_state)(u8 state);
44420 void (*set_engine_pll)(struct via_pll_config config);
44421 -};
44422 +} __no_const;
44423
44424
44425 static inline u32 get_pll_internal_frequency(u32 ref_freq,
44426 diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
44427 index 6b1b7e1..b2fa4d5 100644
44428 --- a/drivers/virtio/virtio_mmio.c
44429 +++ b/drivers/virtio/virtio_mmio.c
44430 @@ -530,7 +530,7 @@ static int vm_cmdline_set(const char *device,
44431
44432 resources[0].end = memparse(device, &str) - 1;
44433
44434 - processed = sscanf(str, "@%lli:%u%n:%d%n",
44435 + processed = sscanf(str, "@%lli:%llu%n:%d%n",
44436 &base, &resources[1].start, &consumed,
44437 &vm_cmdline_id, &consumed);
44438
44439 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
44440 index fef20db..d28b1ab 100644
44441 --- a/drivers/xen/xenfs/xenstored.c
44442 +++ b/drivers/xen/xenfs/xenstored.c
44443 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
44444 static int xsd_kva_open(struct inode *inode, struct file *file)
44445 {
44446 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
44447 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44448 + NULL);
44449 +#else
44450 xen_store_interface);
44451 +#endif
44452 +
44453 if (!file->private_data)
44454 return -ENOMEM;
44455 return 0;
44456 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
44457 index 890bed5..17ae73e 100644
44458 --- a/fs/9p/vfs_inode.c
44459 +++ b/fs/9p/vfs_inode.c
44460 @@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
44461 void
44462 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
44463 {
44464 - char *s = nd_get_link(nd);
44465 + const char *s = nd_get_link(nd);
44466
44467 p9_debug(P9_DEBUG_VFS, " %s %s\n",
44468 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
44469 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
44470 index 0efd152..b5802ad 100644
44471 --- a/fs/Kconfig.binfmt
44472 +++ b/fs/Kconfig.binfmt
44473 @@ -89,7 +89,7 @@ config HAVE_AOUT
44474
44475 config BINFMT_AOUT
44476 tristate "Kernel support for a.out and ECOFF binaries"
44477 - depends on HAVE_AOUT
44478 + depends on HAVE_AOUT && BROKEN
44479 ---help---
44480 A.out (Assembler.OUTput) is a set of formats for libraries and
44481 executables used in the earliest versions of UNIX. Linux used
44482 diff --git a/fs/aio.c b/fs/aio.c
44483 index 71f613c..9d01f1f 100644
44484 --- a/fs/aio.c
44485 +++ b/fs/aio.c
44486 @@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
44487 size += sizeof(struct io_event) * nr_events;
44488 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
44489
44490 - if (nr_pages < 0)
44491 + if (nr_pages <= 0)
44492 return -EINVAL;
44493
44494 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
44495 @@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
44496 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
44497 {
44498 ssize_t ret;
44499 + struct iovec iovstack;
44500
44501 #ifdef CONFIG_COMPAT
44502 if (compat)
44503 ret = compat_rw_copy_check_uvector(type,
44504 (struct compat_iovec __user *)kiocb->ki_buf,
44505 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
44506 + kiocb->ki_nbytes, 1, &iovstack,
44507 &kiocb->ki_iovec);
44508 else
44509 #endif
44510 ret = rw_copy_check_uvector(type,
44511 (struct iovec __user *)kiocb->ki_buf,
44512 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
44513 + kiocb->ki_nbytes, 1, &iovstack,
44514 &kiocb->ki_iovec);
44515 if (ret < 0)
44516 goto out;
44517 @@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
44518 if (ret < 0)
44519 goto out;
44520
44521 + if (kiocb->ki_iovec == &iovstack) {
44522 + kiocb->ki_inline_vec = iovstack;
44523 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
44524 + }
44525 kiocb->ki_nr_segs = kiocb->ki_nbytes;
44526 kiocb->ki_cur_seg = 0;
44527 /* ki_nbytes/left now reflect bytes instead of segs */
44528 diff --git a/fs/attr.c b/fs/attr.c
44529 index cce7df5..eaa2731 100644
44530 --- a/fs/attr.c
44531 +++ b/fs/attr.c
44532 @@ -100,6 +100,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
44533 unsigned long limit;
44534
44535 limit = rlimit(RLIMIT_FSIZE);
44536 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
44537 if (limit != RLIM_INFINITY && offset > limit)
44538 goto out_sig;
44539 if (offset > inode->i_sb->s_maxbytes)
44540 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
44541 index dce436e..55e670d 100644
44542 --- a/fs/autofs4/waitq.c
44543 +++ b/fs/autofs4/waitq.c
44544 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
44545 {
44546 unsigned long sigpipe, flags;
44547 mm_segment_t fs;
44548 - const char *data = (const char *)addr;
44549 + const char __user *data = (const char __force_user *)addr;
44550 ssize_t wr = 0;
44551
44552 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
44553 @@ -347,6 +347,10 @@ static int validate_request(struct autofs_wait_queue **wait,
44554 return 1;
44555 }
44556
44557 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44558 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
44559 +#endif
44560 +
44561 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
44562 enum autofs_notify notify)
44563 {
44564 @@ -380,7 +384,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
44565
44566 /* If this is a direct mount request create a dummy name */
44567 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
44568 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44569 + /* this name does get written to userland via autofs4_write() */
44570 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
44571 +#else
44572 qstr.len = sprintf(name, "%p", dentry);
44573 +#endif
44574 else {
44575 qstr.len = autofs4_getpath(sbi, dentry, &name);
44576 if (!qstr.len) {
44577 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
44578 index 2b3bda8..6a2d4be 100644
44579 --- a/fs/befs/linuxvfs.c
44580 +++ b/fs/befs/linuxvfs.c
44581 @@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
44582 {
44583 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
44584 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
44585 - char *link = nd_get_link(nd);
44586 + const char *link = nd_get_link(nd);
44587 if (!IS_ERR(link))
44588 kfree(link);
44589 }
44590 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
44591 index 0e7a6f8..332b1ca 100644
44592 --- a/fs/binfmt_aout.c
44593 +++ b/fs/binfmt_aout.c
44594 @@ -16,6 +16,7 @@
44595 #include <linux/string.h>
44596 #include <linux/fs.h>
44597 #include <linux/file.h>
44598 +#include <linux/security.h>
44599 #include <linux/stat.h>
44600 #include <linux/fcntl.h>
44601 #include <linux/ptrace.h>
44602 @@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
44603 #endif
44604 # define START_STACK(u) ((void __user *)u.start_stack)
44605
44606 + memset(&dump, 0, sizeof(dump));
44607 +
44608 fs = get_fs();
44609 set_fs(KERNEL_DS);
44610 has_dumped = 1;
44611 @@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
44612
44613 /* If the size of the dump file exceeds the rlimit, then see what would happen
44614 if we wrote the stack, but not the data area. */
44615 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
44616 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
44617 dump.u_dsize = 0;
44618
44619 /* Make sure we have enough room to write the stack and data areas. */
44620 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
44621 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
44622 dump.u_ssize = 0;
44623
44624 @@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
44625 rlim = rlimit(RLIMIT_DATA);
44626 if (rlim >= RLIM_INFINITY)
44627 rlim = ~0;
44628 +
44629 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
44630 if (ex.a_data + ex.a_bss > rlim)
44631 return -ENOMEM;
44632
44633 @@ -267,6 +274,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
44634
44635 install_exec_creds(bprm);
44636
44637 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44638 + current->mm->pax_flags = 0UL;
44639 +#endif
44640 +
44641 +#ifdef CONFIG_PAX_PAGEEXEC
44642 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
44643 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
44644 +
44645 +#ifdef CONFIG_PAX_EMUTRAMP
44646 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
44647 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
44648 +#endif
44649 +
44650 +#ifdef CONFIG_PAX_MPROTECT
44651 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
44652 + current->mm->pax_flags |= MF_PAX_MPROTECT;
44653 +#endif
44654 +
44655 + }
44656 +#endif
44657 +
44658 if (N_MAGIC(ex) == OMAGIC) {
44659 unsigned long text_addr, map_size;
44660 loff_t pos;
44661 @@ -332,7 +360,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
44662 }
44663
44664 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
44665 - PROT_READ | PROT_WRITE | PROT_EXEC,
44666 + PROT_READ | PROT_WRITE,
44667 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
44668 fd_offset + ex.a_text);
44669 if (error != N_DATADDR(ex)) {
44670 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
44671 index fbd9f60..0b845dd 100644
44672 --- a/fs/binfmt_elf.c
44673 +++ b/fs/binfmt_elf.c
44674 @@ -33,6 +33,7 @@
44675 #include <linux/elf.h>
44676 #include <linux/utsname.h>
44677 #include <linux/coredump.h>
44678 +#include <linux/xattr.h>
44679 #include <asm/uaccess.h>
44680 #include <asm/param.h>
44681 #include <asm/page.h>
44682 @@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
44683 #define elf_core_dump NULL
44684 #endif
44685
44686 +#ifdef CONFIG_PAX_MPROTECT
44687 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
44688 +#endif
44689 +
44690 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
44691 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
44692 #else
44693 @@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
44694 .load_binary = load_elf_binary,
44695 .load_shlib = load_elf_library,
44696 .core_dump = elf_core_dump,
44697 +
44698 +#ifdef CONFIG_PAX_MPROTECT
44699 + .handle_mprotect= elf_handle_mprotect,
44700 +#endif
44701 +
44702 .min_coredump = ELF_EXEC_PAGESIZE,
44703 };
44704
44705 @@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
44706
44707 static int set_brk(unsigned long start, unsigned long end)
44708 {
44709 + unsigned long e = end;
44710 +
44711 start = ELF_PAGEALIGN(start);
44712 end = ELF_PAGEALIGN(end);
44713 if (end > start) {
44714 @@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
44715 if (BAD_ADDR(addr))
44716 return addr;
44717 }
44718 - current->mm->start_brk = current->mm->brk = end;
44719 + current->mm->start_brk = current->mm->brk = e;
44720 return 0;
44721 }
44722
44723 @@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
44724 elf_addr_t __user *u_rand_bytes;
44725 const char *k_platform = ELF_PLATFORM;
44726 const char *k_base_platform = ELF_BASE_PLATFORM;
44727 - unsigned char k_rand_bytes[16];
44728 + u32 k_rand_bytes[4];
44729 int items;
44730 elf_addr_t *elf_info;
44731 int ei_index = 0;
44732 const struct cred *cred = current_cred();
44733 struct vm_area_struct *vma;
44734 + unsigned long saved_auxv[AT_VECTOR_SIZE];
44735
44736 /*
44737 * In some cases (e.g. Hyper-Threading), we want to avoid L1
44738 @@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
44739 * Generate 16 random bytes for userspace PRNG seeding.
44740 */
44741 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
44742 - u_rand_bytes = (elf_addr_t __user *)
44743 - STACK_ALLOC(p, sizeof(k_rand_bytes));
44744 + srandom32(k_rand_bytes[0] ^ random32());
44745 + srandom32(k_rand_bytes[1] ^ random32());
44746 + srandom32(k_rand_bytes[2] ^ random32());
44747 + srandom32(k_rand_bytes[3] ^ random32());
44748 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
44749 + u_rand_bytes = (elf_addr_t __user *) p;
44750 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
44751 return -EFAULT;
44752
44753 @@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
44754 return -EFAULT;
44755 current->mm->env_end = p;
44756
44757 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
44758 +
44759 /* Put the elf_info on the stack in the right place. */
44760 sp = (elf_addr_t __user *)envp + 1;
44761 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
44762 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
44763 return -EFAULT;
44764 return 0;
44765 }
44766 @@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
44767 an ELF header */
44768
44769 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44770 - struct file *interpreter, unsigned long *interp_map_addr,
44771 - unsigned long no_base)
44772 + struct file *interpreter, unsigned long no_base)
44773 {
44774 struct elf_phdr *elf_phdata;
44775 struct elf_phdr *eppnt;
44776 - unsigned long load_addr = 0;
44777 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
44778 int load_addr_set = 0;
44779 unsigned long last_bss = 0, elf_bss = 0;
44780 - unsigned long error = ~0UL;
44781 + unsigned long error = -EINVAL;
44782 unsigned long total_size;
44783 int retval, i, size;
44784
44785 @@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44786 goto out_close;
44787 }
44788
44789 +#ifdef CONFIG_PAX_SEGMEXEC
44790 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
44791 + pax_task_size = SEGMEXEC_TASK_SIZE;
44792 +#endif
44793 +
44794 eppnt = elf_phdata;
44795 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
44796 if (eppnt->p_type == PT_LOAD) {
44797 @@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44798 map_addr = elf_map(interpreter, load_addr + vaddr,
44799 eppnt, elf_prot, elf_type, total_size);
44800 total_size = 0;
44801 - if (!*interp_map_addr)
44802 - *interp_map_addr = map_addr;
44803 error = map_addr;
44804 if (BAD_ADDR(map_addr))
44805 goto out_close;
44806 @@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44807 k = load_addr + eppnt->p_vaddr;
44808 if (BAD_ADDR(k) ||
44809 eppnt->p_filesz > eppnt->p_memsz ||
44810 - eppnt->p_memsz > TASK_SIZE ||
44811 - TASK_SIZE - eppnt->p_memsz < k) {
44812 + eppnt->p_memsz > pax_task_size ||
44813 + pax_task_size - eppnt->p_memsz < k) {
44814 error = -ENOMEM;
44815 goto out_close;
44816 }
44817 @@ -530,6 +551,315 @@ out:
44818 return error;
44819 }
44820
44821 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
44822 +#ifdef CONFIG_PAX_SOFTMODE
44823 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
44824 +{
44825 + unsigned long pax_flags = 0UL;
44826 +
44827 +#ifdef CONFIG_PAX_PAGEEXEC
44828 + if (elf_phdata->p_flags & PF_PAGEEXEC)
44829 + pax_flags |= MF_PAX_PAGEEXEC;
44830 +#endif
44831 +
44832 +#ifdef CONFIG_PAX_SEGMEXEC
44833 + if (elf_phdata->p_flags & PF_SEGMEXEC)
44834 + pax_flags |= MF_PAX_SEGMEXEC;
44835 +#endif
44836 +
44837 +#ifdef CONFIG_PAX_EMUTRAMP
44838 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
44839 + pax_flags |= MF_PAX_EMUTRAMP;
44840 +#endif
44841 +
44842 +#ifdef CONFIG_PAX_MPROTECT
44843 + if (elf_phdata->p_flags & PF_MPROTECT)
44844 + pax_flags |= MF_PAX_MPROTECT;
44845 +#endif
44846 +
44847 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44848 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
44849 + pax_flags |= MF_PAX_RANDMMAP;
44850 +#endif
44851 +
44852 + return pax_flags;
44853 +}
44854 +#endif
44855 +
44856 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
44857 +{
44858 + unsigned long pax_flags = 0UL;
44859 +
44860 +#ifdef CONFIG_PAX_PAGEEXEC
44861 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
44862 + pax_flags |= MF_PAX_PAGEEXEC;
44863 +#endif
44864 +
44865 +#ifdef CONFIG_PAX_SEGMEXEC
44866 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
44867 + pax_flags |= MF_PAX_SEGMEXEC;
44868 +#endif
44869 +
44870 +#ifdef CONFIG_PAX_EMUTRAMP
44871 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
44872 + pax_flags |= MF_PAX_EMUTRAMP;
44873 +#endif
44874 +
44875 +#ifdef CONFIG_PAX_MPROTECT
44876 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
44877 + pax_flags |= MF_PAX_MPROTECT;
44878 +#endif
44879 +
44880 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44881 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
44882 + pax_flags |= MF_PAX_RANDMMAP;
44883 +#endif
44884 +
44885 + return pax_flags;
44886 +}
44887 +#endif
44888 +
44889 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
44890 +#ifdef CONFIG_PAX_SOFTMODE
44891 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
44892 +{
44893 + unsigned long pax_flags = 0UL;
44894 +
44895 +#ifdef CONFIG_PAX_PAGEEXEC
44896 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
44897 + pax_flags |= MF_PAX_PAGEEXEC;
44898 +#endif
44899 +
44900 +#ifdef CONFIG_PAX_SEGMEXEC
44901 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
44902 + pax_flags |= MF_PAX_SEGMEXEC;
44903 +#endif
44904 +
44905 +#ifdef CONFIG_PAX_EMUTRAMP
44906 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
44907 + pax_flags |= MF_PAX_EMUTRAMP;
44908 +#endif
44909 +
44910 +#ifdef CONFIG_PAX_MPROTECT
44911 + if (pax_flags_softmode & MF_PAX_MPROTECT)
44912 + pax_flags |= MF_PAX_MPROTECT;
44913 +#endif
44914 +
44915 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44916 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
44917 + pax_flags |= MF_PAX_RANDMMAP;
44918 +#endif
44919 +
44920 + return pax_flags;
44921 +}
44922 +#endif
44923 +
44924 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
44925 +{
44926 + unsigned long pax_flags = 0UL;
44927 +
44928 +#ifdef CONFIG_PAX_PAGEEXEC
44929 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
44930 + pax_flags |= MF_PAX_PAGEEXEC;
44931 +#endif
44932 +
44933 +#ifdef CONFIG_PAX_SEGMEXEC
44934 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
44935 + pax_flags |= MF_PAX_SEGMEXEC;
44936 +#endif
44937 +
44938 +#ifdef CONFIG_PAX_EMUTRAMP
44939 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
44940 + pax_flags |= MF_PAX_EMUTRAMP;
44941 +#endif
44942 +
44943 +#ifdef CONFIG_PAX_MPROTECT
44944 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
44945 + pax_flags |= MF_PAX_MPROTECT;
44946 +#endif
44947 +
44948 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44949 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
44950 + pax_flags |= MF_PAX_RANDMMAP;
44951 +#endif
44952 +
44953 + return pax_flags;
44954 +}
44955 +#endif
44956 +
44957 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44958 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
44959 +{
44960 + unsigned long pax_flags = 0UL;
44961 +
44962 +#ifdef CONFIG_PAX_EI_PAX
44963 +
44964 +#ifdef CONFIG_PAX_PAGEEXEC
44965 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
44966 + pax_flags |= MF_PAX_PAGEEXEC;
44967 +#endif
44968 +
44969 +#ifdef CONFIG_PAX_SEGMEXEC
44970 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
44971 + pax_flags |= MF_PAX_SEGMEXEC;
44972 +#endif
44973 +
44974 +#ifdef CONFIG_PAX_EMUTRAMP
44975 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
44976 + pax_flags |= MF_PAX_EMUTRAMP;
44977 +#endif
44978 +
44979 +#ifdef CONFIG_PAX_MPROTECT
44980 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
44981 + pax_flags |= MF_PAX_MPROTECT;
44982 +#endif
44983 +
44984 +#ifdef CONFIG_PAX_ASLR
44985 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
44986 + pax_flags |= MF_PAX_RANDMMAP;
44987 +#endif
44988 +
44989 +#else
44990 +
44991 +#ifdef CONFIG_PAX_PAGEEXEC
44992 + pax_flags |= MF_PAX_PAGEEXEC;
44993 +#endif
44994 +
44995 +#ifdef CONFIG_PAX_SEGMEXEC
44996 + pax_flags |= MF_PAX_SEGMEXEC;
44997 +#endif
44998 +
44999 +#ifdef CONFIG_PAX_MPROTECT
45000 + pax_flags |= MF_PAX_MPROTECT;
45001 +#endif
45002 +
45003 +#ifdef CONFIG_PAX_RANDMMAP
45004 + if (randomize_va_space)
45005 + pax_flags |= MF_PAX_RANDMMAP;
45006 +#endif
45007 +
45008 +#endif
45009 +
45010 + return pax_flags;
45011 +}
45012 +
45013 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
45014 +{
45015 +
45016 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
45017 + unsigned long i;
45018 +
45019 + for (i = 0UL; i < elf_ex->e_phnum; i++)
45020 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
45021 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
45022 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
45023 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
45024 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
45025 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
45026 + return ~0UL;
45027 +
45028 +#ifdef CONFIG_PAX_SOFTMODE
45029 + if (pax_softmode)
45030 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
45031 + else
45032 +#endif
45033 +
45034 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
45035 + break;
45036 + }
45037 +#endif
45038 +
45039 + return ~0UL;
45040 +}
45041 +
45042 +static unsigned long pax_parse_xattr_pax(struct file * const file)
45043 +{
45044 +
45045 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
45046 + ssize_t xattr_size, i;
45047 + unsigned char xattr_value[5];
45048 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
45049 +
45050 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
45051 + if (xattr_size <= 0 || xattr_size > 5)
45052 + return ~0UL;
45053 +
45054 + for (i = 0; i < xattr_size; i++)
45055 + switch (xattr_value[i]) {
45056 + default:
45057 + return ~0UL;
45058 +
45059 +#define parse_flag(option1, option2, flag) \
45060 + case option1: \
45061 + if (pax_flags_hardmode & MF_PAX_##flag) \
45062 + return ~0UL; \
45063 + pax_flags_hardmode |= MF_PAX_##flag; \
45064 + break; \
45065 + case option2: \
45066 + if (pax_flags_softmode & MF_PAX_##flag) \
45067 + return ~0UL; \
45068 + pax_flags_softmode |= MF_PAX_##flag; \
45069 + break;
45070 +
45071 + parse_flag('p', 'P', PAGEEXEC);
45072 + parse_flag('e', 'E', EMUTRAMP);
45073 + parse_flag('m', 'M', MPROTECT);
45074 + parse_flag('r', 'R', RANDMMAP);
45075 + parse_flag('s', 'S', SEGMEXEC);
45076 +
45077 +#undef parse_flag
45078 + }
45079 +
45080 + if (pax_flags_hardmode & pax_flags_softmode)
45081 + return ~0UL;
45082 +
45083 +#ifdef CONFIG_PAX_SOFTMODE
45084 + if (pax_softmode)
45085 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
45086 + else
45087 +#endif
45088 +
45089 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
45090 +#else
45091 + return ~0UL;
45092 +#endif
45093 +
45094 +}
45095 +
45096 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
45097 +{
45098 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
45099 +
45100 + pax_flags = pax_parse_ei_pax(elf_ex);
45101 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
45102 + xattr_pax_flags = pax_parse_xattr_pax(file);
45103 +
45104 + if (pt_pax_flags == ~0UL)
45105 + pt_pax_flags = xattr_pax_flags;
45106 + else if (xattr_pax_flags == ~0UL)
45107 + xattr_pax_flags = pt_pax_flags;
45108 + if (pt_pax_flags != xattr_pax_flags)
45109 + return -EINVAL;
45110 + if (pt_pax_flags != ~0UL)
45111 + pax_flags = pt_pax_flags;
45112 +
45113 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
45114 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45115 + if ((__supported_pte_mask & _PAGE_NX))
45116 + pax_flags &= ~MF_PAX_SEGMEXEC;
45117 + else
45118 + pax_flags &= ~MF_PAX_PAGEEXEC;
45119 + }
45120 +#endif
45121 +
45122 + if (0 > pax_check_flags(&pax_flags))
45123 + return -EINVAL;
45124 +
45125 + current->mm->pax_flags = pax_flags;
45126 + return 0;
45127 +}
45128 +#endif
45129 +
45130 /*
45131 * These are the functions used to load ELF style executables and shared
45132 * libraries. There is no binary dependent code anywhere else.
45133 @@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
45134 {
45135 unsigned int random_variable = 0;
45136
45137 +#ifdef CONFIG_PAX_RANDUSTACK
45138 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
45139 + return stack_top - current->mm->delta_stack;
45140 +#endif
45141 +
45142 if ((current->flags & PF_RANDOMIZE) &&
45143 !(current->personality & ADDR_NO_RANDOMIZE)) {
45144 random_variable = get_random_int() & STACK_RND_MASK;
45145 @@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
45146 unsigned long load_addr = 0, load_bias = 0;
45147 int load_addr_set = 0;
45148 char * elf_interpreter = NULL;
45149 - unsigned long error;
45150 + unsigned long error = 0;
45151 struct elf_phdr *elf_ppnt, *elf_phdata;
45152 unsigned long elf_bss, elf_brk;
45153 int retval, i;
45154 @@ -574,11 +909,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
45155 unsigned long start_code, end_code, start_data, end_data;
45156 unsigned long reloc_func_desc __maybe_unused = 0;
45157 int executable_stack = EXSTACK_DEFAULT;
45158 - unsigned long def_flags = 0;
45159 struct {
45160 struct elfhdr elf_ex;
45161 struct elfhdr interp_elf_ex;
45162 } *loc;
45163 + unsigned long pax_task_size = TASK_SIZE;
45164
45165 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
45166 if (!loc) {
45167 @@ -714,11 +1049,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
45168 goto out_free_dentry;
45169
45170 /* OK, This is the point of no return */
45171 - current->mm->def_flags = def_flags;
45172 +
45173 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45174 + current->mm->pax_flags = 0UL;
45175 +#endif
45176 +
45177 +#ifdef CONFIG_PAX_DLRESOLVE
45178 + current->mm->call_dl_resolve = 0UL;
45179 +#endif
45180 +
45181 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
45182 + current->mm->call_syscall = 0UL;
45183 +#endif
45184 +
45185 +#ifdef CONFIG_PAX_ASLR
45186 + current->mm->delta_mmap = 0UL;
45187 + current->mm->delta_stack = 0UL;
45188 +#endif
45189 +
45190 + current->mm->def_flags = 0;
45191 +
45192 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45193 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
45194 + send_sig(SIGKILL, current, 0);
45195 + goto out_free_dentry;
45196 + }
45197 +#endif
45198 +
45199 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
45200 + pax_set_initial_flags(bprm);
45201 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
45202 + if (pax_set_initial_flags_func)
45203 + (pax_set_initial_flags_func)(bprm);
45204 +#endif
45205 +
45206 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
45207 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
45208 + current->mm->context.user_cs_limit = PAGE_SIZE;
45209 + current->mm->def_flags |= VM_PAGEEXEC;
45210 + }
45211 +#endif
45212 +
45213 +#ifdef CONFIG_PAX_SEGMEXEC
45214 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
45215 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
45216 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
45217 + pax_task_size = SEGMEXEC_TASK_SIZE;
45218 + current->mm->def_flags |= VM_NOHUGEPAGE;
45219 + }
45220 +#endif
45221 +
45222 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
45223 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45224 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
45225 + put_cpu();
45226 + }
45227 +#endif
45228
45229 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
45230 may depend on the personality. */
45231 SET_PERSONALITY(loc->elf_ex);
45232 +
45233 +#ifdef CONFIG_PAX_ASLR
45234 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
45235 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
45236 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
45237 + }
45238 +#endif
45239 +
45240 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45241 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45242 + executable_stack = EXSTACK_DISABLE_X;
45243 + current->personality &= ~READ_IMPLIES_EXEC;
45244 + } else
45245 +#endif
45246 +
45247 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
45248 current->personality |= READ_IMPLIES_EXEC;
45249
45250 @@ -809,6 +1214,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
45251 #else
45252 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
45253 #endif
45254 +
45255 +#ifdef CONFIG_PAX_RANDMMAP
45256 + /* PaX: randomize base address at the default exe base if requested */
45257 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
45258 +#ifdef CONFIG_SPARC64
45259 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
45260 +#else
45261 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
45262 +#endif
45263 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
45264 + elf_flags |= MAP_FIXED;
45265 + }
45266 +#endif
45267 +
45268 }
45269
45270 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
45271 @@ -841,9 +1260,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
45272 * allowed task size. Note that p_filesz must always be
45273 * <= p_memsz so it is only necessary to check p_memsz.
45274 */
45275 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
45276 - elf_ppnt->p_memsz > TASK_SIZE ||
45277 - TASK_SIZE - elf_ppnt->p_memsz < k) {
45278 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
45279 + elf_ppnt->p_memsz > pax_task_size ||
45280 + pax_task_size - elf_ppnt->p_memsz < k) {
45281 /* set_brk can never work. Avoid overflows. */
45282 send_sig(SIGKILL, current, 0);
45283 retval = -EINVAL;
45284 @@ -882,17 +1301,44 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
45285 goto out_free_dentry;
45286 }
45287 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
45288 - send_sig(SIGSEGV, current, 0);
45289 - retval = -EFAULT; /* Nobody gets to see this, but.. */
45290 - goto out_free_dentry;
45291 + /*
45292 + * This bss-zeroing can fail if the ELF
45293 + * file specifies odd protections. So
45294 + * we don't check the return value
45295 + */
45296 }
45297
45298 +#ifdef CONFIG_PAX_RANDMMAP
45299 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
45300 + unsigned long start, size;
45301 +
45302 + start = ELF_PAGEALIGN(elf_brk);
45303 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
45304 + down_read(&current->mm->mmap_sem);
45305 + retval = -ENOMEM;
45306 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
45307 + unsigned long prot = PROT_NONE;
45308 +
45309 + up_read(&current->mm->mmap_sem);
45310 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
45311 +// if (current->personality & ADDR_NO_RANDOMIZE)
45312 +// prot = PROT_READ;
45313 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
45314 + retval = IS_ERR_VALUE(start) ? start : 0;
45315 + } else
45316 + up_read(&current->mm->mmap_sem);
45317 + if (retval == 0)
45318 + retval = set_brk(start + size, start + size + PAGE_SIZE);
45319 + if (retval < 0) {
45320 + send_sig(SIGKILL, current, 0);
45321 + goto out_free_dentry;
45322 + }
45323 + }
45324 +#endif
45325 +
45326 if (elf_interpreter) {
45327 - unsigned long interp_map_addr = 0;
45328 -
45329 elf_entry = load_elf_interp(&loc->interp_elf_ex,
45330 interpreter,
45331 - &interp_map_addr,
45332 load_bias);
45333 if (!IS_ERR((void *)elf_entry)) {
45334 /*
45335 @@ -1114,7 +1560,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
45336 * Decide what to dump of a segment, part, all or none.
45337 */
45338 static unsigned long vma_dump_size(struct vm_area_struct *vma,
45339 - unsigned long mm_flags)
45340 + unsigned long mm_flags, long signr)
45341 {
45342 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
45343
45344 @@ -1151,7 +1597,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
45345 if (vma->vm_file == NULL)
45346 return 0;
45347
45348 - if (FILTER(MAPPED_PRIVATE))
45349 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
45350 goto whole;
45351
45352 /*
45353 @@ -1373,9 +1819,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
45354 {
45355 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
45356 int i = 0;
45357 - do
45358 + do {
45359 i += 2;
45360 - while (auxv[i - 2] != AT_NULL);
45361 + } while (auxv[i - 2] != AT_NULL);
45362 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
45363 }
45364
45365 @@ -2003,14 +2449,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
45366 }
45367
45368 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
45369 - unsigned long mm_flags)
45370 + struct coredump_params *cprm)
45371 {
45372 struct vm_area_struct *vma;
45373 size_t size = 0;
45374
45375 for (vma = first_vma(current, gate_vma); vma != NULL;
45376 vma = next_vma(vma, gate_vma))
45377 - size += vma_dump_size(vma, mm_flags);
45378 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
45379 return size;
45380 }
45381
45382 @@ -2104,7 +2550,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45383
45384 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
45385
45386 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
45387 + offset += elf_core_vma_data_size(gate_vma, cprm);
45388 offset += elf_core_extra_data_size();
45389 e_shoff = offset;
45390
45391 @@ -2118,10 +2564,12 @@ static int elf_core_dump(struct coredump_params *cprm)
45392 offset = dataoff;
45393
45394 size += sizeof(*elf);
45395 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
45396 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
45397 goto end_coredump;
45398
45399 size += sizeof(*phdr4note);
45400 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
45401 if (size > cprm->limit
45402 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
45403 goto end_coredump;
45404 @@ -2135,7 +2583,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45405 phdr.p_offset = offset;
45406 phdr.p_vaddr = vma->vm_start;
45407 phdr.p_paddr = 0;
45408 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
45409 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
45410 phdr.p_memsz = vma->vm_end - vma->vm_start;
45411 offset += phdr.p_filesz;
45412 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
45413 @@ -2146,6 +2594,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45414 phdr.p_align = ELF_EXEC_PAGESIZE;
45415
45416 size += sizeof(phdr);
45417 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
45418 if (size > cprm->limit
45419 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
45420 goto end_coredump;
45421 @@ -2170,7 +2619,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45422 unsigned long addr;
45423 unsigned long end;
45424
45425 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
45426 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
45427
45428 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
45429 struct page *page;
45430 @@ -2179,6 +2628,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45431 page = get_dump_page(addr);
45432 if (page) {
45433 void *kaddr = kmap(page);
45434 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
45435 stop = ((size += PAGE_SIZE) > cprm->limit) ||
45436 !dump_write(cprm->file, kaddr,
45437 PAGE_SIZE);
45438 @@ -2196,6 +2646,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45439
45440 if (e_phnum == PN_XNUM) {
45441 size += sizeof(*shdr4extnum);
45442 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
45443 if (size > cprm->limit
45444 || !dump_write(cprm->file, shdr4extnum,
45445 sizeof(*shdr4extnum)))
45446 @@ -2216,6 +2667,97 @@ out:
45447
45448 #endif /* CONFIG_ELF_CORE */
45449
45450 +#ifdef CONFIG_PAX_MPROTECT
45451 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
45452 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
45453 + * we'll remove VM_MAYWRITE for good on RELRO segments.
45454 + *
45455 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
45456 + * basis because we want to allow the common case and not the special ones.
45457 + */
45458 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
45459 +{
45460 + struct elfhdr elf_h;
45461 + struct elf_phdr elf_p;
45462 + unsigned long i;
45463 + unsigned long oldflags;
45464 + bool is_textrel_rw, is_textrel_rx, is_relro;
45465 +
45466 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
45467 + return;
45468 +
45469 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
45470 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
45471 +
45472 +#ifdef CONFIG_PAX_ELFRELOCS
45473 + /* possible TEXTREL */
45474 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
45475 + 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);
45476 +#else
45477 + is_textrel_rw = false;
45478 + is_textrel_rx = false;
45479 +#endif
45480 +
45481 + /* possible RELRO */
45482 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
45483 +
45484 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
45485 + return;
45486 +
45487 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
45488 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
45489 +
45490 +#ifdef CONFIG_PAX_ETEXECRELOCS
45491 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
45492 +#else
45493 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
45494 +#endif
45495 +
45496 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
45497 + !elf_check_arch(&elf_h) ||
45498 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
45499 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
45500 + return;
45501 +
45502 + for (i = 0UL; i < elf_h.e_phnum; i++) {
45503 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
45504 + return;
45505 + switch (elf_p.p_type) {
45506 + case PT_DYNAMIC:
45507 + if (!is_textrel_rw && !is_textrel_rx)
45508 + continue;
45509 + i = 0UL;
45510 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
45511 + elf_dyn dyn;
45512 +
45513 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
45514 + return;
45515 + if (dyn.d_tag == DT_NULL)
45516 + return;
45517 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
45518 + gr_log_textrel(vma);
45519 + if (is_textrel_rw)
45520 + vma->vm_flags |= VM_MAYWRITE;
45521 + else
45522 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
45523 + vma->vm_flags &= ~VM_MAYWRITE;
45524 + return;
45525 + }
45526 + i++;
45527 + }
45528 + return;
45529 +
45530 + case PT_GNU_RELRO:
45531 + if (!is_relro)
45532 + continue;
45533 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
45534 + vma->vm_flags &= ~VM_MAYWRITE;
45535 + return;
45536 + }
45537 + }
45538 +}
45539 +#endif
45540 +
45541 static int __init init_elf_binfmt(void)
45542 {
45543 register_binfmt(&elf_format);
45544 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
45545 index e280352..7b2f231 100644
45546 --- a/fs/binfmt_flat.c
45547 +++ b/fs/binfmt_flat.c
45548 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
45549 realdatastart = (unsigned long) -ENOMEM;
45550 printk("Unable to allocate RAM for process data, errno %d\n",
45551 (int)-realdatastart);
45552 + down_write(&current->mm->mmap_sem);
45553 vm_munmap(textpos, text_len);
45554 + up_write(&current->mm->mmap_sem);
45555 ret = realdatastart;
45556 goto err;
45557 }
45558 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
45559 }
45560 if (IS_ERR_VALUE(result)) {
45561 printk("Unable to read data+bss, errno %d\n", (int)-result);
45562 + down_write(&current->mm->mmap_sem);
45563 vm_munmap(textpos, text_len);
45564 vm_munmap(realdatastart, len);
45565 + up_write(&current->mm->mmap_sem);
45566 ret = result;
45567 goto err;
45568 }
45569 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
45570 }
45571 if (IS_ERR_VALUE(result)) {
45572 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
45573 + down_write(&current->mm->mmap_sem);
45574 vm_munmap(textpos, text_len + data_len + extra +
45575 MAX_SHARED_LIBS * sizeof(unsigned long));
45576 + up_write(&current->mm->mmap_sem);
45577 ret = result;
45578 goto err;
45579 }
45580 diff --git a/fs/bio.c b/fs/bio.c
45581 index b96fc6c..431d628 100644
45582 --- a/fs/bio.c
45583 +++ b/fs/bio.c
45584 @@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
45585 /*
45586 * Overflow, abort
45587 */
45588 - if (end < start)
45589 + if (end < start || end - start > INT_MAX - nr_pages)
45590 return ERR_PTR(-EINVAL);
45591
45592 nr_pages += end - start;
45593 @@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
45594 /*
45595 * Overflow, abort
45596 */
45597 - if (end < start)
45598 + if (end < start || end - start > INT_MAX - nr_pages)
45599 return ERR_PTR(-EINVAL);
45600
45601 nr_pages += end - start;
45602 @@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
45603 const int read = bio_data_dir(bio) == READ;
45604 struct bio_map_data *bmd = bio->bi_private;
45605 int i;
45606 - char *p = bmd->sgvecs[0].iov_base;
45607 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
45608
45609 __bio_for_each_segment(bvec, bio, i, 0) {
45610 char *addr = page_address(bvec->bv_page);
45611 diff --git a/fs/block_dev.c b/fs/block_dev.c
45612 index ab3a456..7da538b 100644
45613 --- a/fs/block_dev.c
45614 +++ b/fs/block_dev.c
45615 @@ -651,7 +651,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
45616 else if (bdev->bd_contains == bdev)
45617 return true; /* is a whole device which isn't held */
45618
45619 - else if (whole->bd_holder == bd_may_claim)
45620 + else if (whole->bd_holder == (void *)bd_may_claim)
45621 return true; /* is a partition of a device that is being partitioned */
45622 else if (whole->bd_holder != NULL)
45623 return false; /* is a partition of a held device */
45624 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
45625 index cdfb4c4..da736d4 100644
45626 --- a/fs/btrfs/ctree.c
45627 +++ b/fs/btrfs/ctree.c
45628 @@ -1035,9 +1035,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
45629 free_extent_buffer(buf);
45630 add_root_to_dirty_list(root);
45631 } else {
45632 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
45633 - parent_start = parent->start;
45634 - else
45635 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
45636 + if (parent)
45637 + parent_start = parent->start;
45638 + else
45639 + parent_start = 0;
45640 + } else
45641 parent_start = 0;
45642
45643 WARN_ON(trans->transid != btrfs_header_generation(parent));
45644 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
45645 index 95542a1..95a8727 100644
45646 --- a/fs/btrfs/inode.c
45647 +++ b/fs/btrfs/inode.c
45648 @@ -7243,7 +7243,7 @@ fail:
45649 return -ENOMEM;
45650 }
45651
45652 -static int btrfs_getattr(struct vfsmount *mnt,
45653 +int btrfs_getattr(struct vfsmount *mnt,
45654 struct dentry *dentry, struct kstat *stat)
45655 {
45656 struct inode *inode = dentry->d_inode;
45657 @@ -7257,6 +7257,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
45658 return 0;
45659 }
45660
45661 +EXPORT_SYMBOL(btrfs_getattr);
45662 +
45663 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
45664 +{
45665 + return BTRFS_I(inode)->root->anon_dev;
45666 +}
45667 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
45668 +
45669 /*
45670 * If a file is moved, it will inherit the cow and compression flags of the new
45671 * directory.
45672 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
45673 index 8fcf9a5..a200000 100644
45674 --- a/fs/btrfs/ioctl.c
45675 +++ b/fs/btrfs/ioctl.c
45676 @@ -2965,9 +2965,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
45677 for (i = 0; i < num_types; i++) {
45678 struct btrfs_space_info *tmp;
45679
45680 + /* Don't copy in more than we allocated */
45681 if (!slot_count)
45682 break;
45683
45684 + slot_count--;
45685 +
45686 info = NULL;
45687 rcu_read_lock();
45688 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
45689 @@ -2989,10 +2992,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
45690 memcpy(dest, &space, sizeof(space));
45691 dest++;
45692 space_args.total_spaces++;
45693 - slot_count--;
45694 }
45695 - if (!slot_count)
45696 - break;
45697 }
45698 up_read(&info->groups_sem);
45699 }
45700 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
45701 index 776f0aa..3aad281 100644
45702 --- a/fs/btrfs/relocation.c
45703 +++ b/fs/btrfs/relocation.c
45704 @@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
45705 }
45706 spin_unlock(&rc->reloc_root_tree.lock);
45707
45708 - BUG_ON((struct btrfs_root *)node->data != root);
45709 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
45710
45711 if (!del) {
45712 spin_lock(&rc->reloc_root_tree.lock);
45713 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
45714 index 622f469..e8d2d55 100644
45715 --- a/fs/cachefiles/bind.c
45716 +++ b/fs/cachefiles/bind.c
45717 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
45718 args);
45719
45720 /* start by checking things over */
45721 - ASSERT(cache->fstop_percent >= 0 &&
45722 - cache->fstop_percent < cache->fcull_percent &&
45723 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
45724 cache->fcull_percent < cache->frun_percent &&
45725 cache->frun_percent < 100);
45726
45727 - ASSERT(cache->bstop_percent >= 0 &&
45728 - cache->bstop_percent < cache->bcull_percent &&
45729 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
45730 cache->bcull_percent < cache->brun_percent &&
45731 cache->brun_percent < 100);
45732
45733 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
45734 index 0a1467b..6a53245 100644
45735 --- a/fs/cachefiles/daemon.c
45736 +++ b/fs/cachefiles/daemon.c
45737 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
45738 if (n > buflen)
45739 return -EMSGSIZE;
45740
45741 - if (copy_to_user(_buffer, buffer, n) != 0)
45742 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
45743 return -EFAULT;
45744
45745 return n;
45746 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
45747 if (test_bit(CACHEFILES_DEAD, &cache->flags))
45748 return -EIO;
45749
45750 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
45751 + if (datalen > PAGE_SIZE - 1)
45752 return -EOPNOTSUPP;
45753
45754 /* drag the command string into the kernel so we can parse it */
45755 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
45756 if (args[0] != '%' || args[1] != '\0')
45757 return -EINVAL;
45758
45759 - if (fstop < 0 || fstop >= cache->fcull_percent)
45760 + if (fstop >= cache->fcull_percent)
45761 return cachefiles_daemon_range_error(cache, args);
45762
45763 cache->fstop_percent = fstop;
45764 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
45765 if (args[0] != '%' || args[1] != '\0')
45766 return -EINVAL;
45767
45768 - if (bstop < 0 || bstop >= cache->bcull_percent)
45769 + if (bstop >= cache->bcull_percent)
45770 return cachefiles_daemon_range_error(cache, args);
45771
45772 cache->bstop_percent = bstop;
45773 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
45774 index bd6bc1b..b627b53 100644
45775 --- a/fs/cachefiles/internal.h
45776 +++ b/fs/cachefiles/internal.h
45777 @@ -57,7 +57,7 @@ struct cachefiles_cache {
45778 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
45779 struct rb_root active_nodes; /* active nodes (can't be culled) */
45780 rwlock_t active_lock; /* lock for active_nodes */
45781 - atomic_t gravecounter; /* graveyard uniquifier */
45782 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
45783 unsigned frun_percent; /* when to stop culling (% files) */
45784 unsigned fcull_percent; /* when to start culling (% files) */
45785 unsigned fstop_percent; /* when to stop allocating (% files) */
45786 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
45787 * proc.c
45788 */
45789 #ifdef CONFIG_CACHEFILES_HISTOGRAM
45790 -extern atomic_t cachefiles_lookup_histogram[HZ];
45791 -extern atomic_t cachefiles_mkdir_histogram[HZ];
45792 -extern atomic_t cachefiles_create_histogram[HZ];
45793 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
45794 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
45795 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
45796
45797 extern int __init cachefiles_proc_init(void);
45798 extern void cachefiles_proc_cleanup(void);
45799 static inline
45800 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
45801 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
45802 {
45803 unsigned long jif = jiffies - start_jif;
45804 if (jif >= HZ)
45805 jif = HZ - 1;
45806 - atomic_inc(&histogram[jif]);
45807 + atomic_inc_unchecked(&histogram[jif]);
45808 }
45809
45810 #else
45811 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
45812 index b0b5f7c..039bb26 100644
45813 --- a/fs/cachefiles/namei.c
45814 +++ b/fs/cachefiles/namei.c
45815 @@ -318,7 +318,7 @@ try_again:
45816 /* first step is to make up a grave dentry in the graveyard */
45817 sprintf(nbuffer, "%08x%08x",
45818 (uint32_t) get_seconds(),
45819 - (uint32_t) atomic_inc_return(&cache->gravecounter));
45820 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
45821
45822 /* do the multiway lock magic */
45823 trap = lock_rename(cache->graveyard, dir);
45824 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
45825 index eccd339..4c1d995 100644
45826 --- a/fs/cachefiles/proc.c
45827 +++ b/fs/cachefiles/proc.c
45828 @@ -14,9 +14,9 @@
45829 #include <linux/seq_file.h>
45830 #include "internal.h"
45831
45832 -atomic_t cachefiles_lookup_histogram[HZ];
45833 -atomic_t cachefiles_mkdir_histogram[HZ];
45834 -atomic_t cachefiles_create_histogram[HZ];
45835 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
45836 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
45837 +atomic_unchecked_t cachefiles_create_histogram[HZ];
45838
45839 /*
45840 * display the latency histogram
45841 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
45842 return 0;
45843 default:
45844 index = (unsigned long) v - 3;
45845 - x = atomic_read(&cachefiles_lookup_histogram[index]);
45846 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
45847 - z = atomic_read(&cachefiles_create_histogram[index]);
45848 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
45849 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
45850 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
45851 if (x == 0 && y == 0 && z == 0)
45852 return 0;
45853
45854 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
45855 index c994691..2a1537f 100644
45856 --- a/fs/cachefiles/rdwr.c
45857 +++ b/fs/cachefiles/rdwr.c
45858 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
45859 old_fs = get_fs();
45860 set_fs(KERNEL_DS);
45861 ret = file->f_op->write(
45862 - file, (const void __user *) data, len, &pos);
45863 + file, (const void __force_user *) data, len, &pos);
45864 set_fs(old_fs);
45865 kunmap(page);
45866 if (ret != len)
45867 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
45868 index e5b7731..b9c59fb 100644
45869 --- a/fs/ceph/dir.c
45870 +++ b/fs/ceph/dir.c
45871 @@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
45872 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
45873 struct ceph_mds_client *mdsc = fsc->mdsc;
45874 unsigned frag = fpos_frag(filp->f_pos);
45875 - int off = fpos_off(filp->f_pos);
45876 + unsigned int off = fpos_off(filp->f_pos);
45877 int err;
45878 u32 ftype;
45879 struct ceph_mds_reply_info_parsed *rinfo;
45880 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
45881 index d9ea6ed..1e6c8ac 100644
45882 --- a/fs/cifs/cifs_debug.c
45883 +++ b/fs/cifs/cifs_debug.c
45884 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
45885
45886 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
45887 #ifdef CONFIG_CIFS_STATS2
45888 - atomic_set(&totBufAllocCount, 0);
45889 - atomic_set(&totSmBufAllocCount, 0);
45890 + atomic_set_unchecked(&totBufAllocCount, 0);
45891 + atomic_set_unchecked(&totSmBufAllocCount, 0);
45892 #endif /* CONFIG_CIFS_STATS2 */
45893 spin_lock(&cifs_tcp_ses_lock);
45894 list_for_each(tmp1, &cifs_tcp_ses_list) {
45895 @@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
45896 tcon = list_entry(tmp3,
45897 struct cifs_tcon,
45898 tcon_list);
45899 - atomic_set(&tcon->num_smbs_sent, 0);
45900 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
45901 if (server->ops->clear_stats)
45902 server->ops->clear_stats(tcon);
45903 }
45904 @@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
45905 smBufAllocCount.counter, cifs_min_small);
45906 #ifdef CONFIG_CIFS_STATS2
45907 seq_printf(m, "Total Large %d Small %d Allocations\n",
45908 - atomic_read(&totBufAllocCount),
45909 - atomic_read(&totSmBufAllocCount));
45910 + atomic_read_unchecked(&totBufAllocCount),
45911 + atomic_read_unchecked(&totSmBufAllocCount));
45912 #endif /* CONFIG_CIFS_STATS2 */
45913
45914 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
45915 @@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
45916 if (tcon->need_reconnect)
45917 seq_puts(m, "\tDISCONNECTED ");
45918 seq_printf(m, "\nSMBs: %d",
45919 - atomic_read(&tcon->num_smbs_sent));
45920 + atomic_read_unchecked(&tcon->num_smbs_sent));
45921 if (server->ops->print_stats)
45922 server->ops->print_stats(m, tcon);
45923 }
45924 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
45925 index e7931cc..76a1ab9 100644
45926 --- a/fs/cifs/cifsfs.c
45927 +++ b/fs/cifs/cifsfs.c
45928 @@ -999,7 +999,7 @@ cifs_init_request_bufs(void)
45929 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
45930 cifs_req_cachep = kmem_cache_create("cifs_request",
45931 CIFSMaxBufSize + max_hdr_size, 0,
45932 - SLAB_HWCACHE_ALIGN, NULL);
45933 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
45934 if (cifs_req_cachep == NULL)
45935 return -ENOMEM;
45936
45937 @@ -1026,7 +1026,7 @@ cifs_init_request_bufs(void)
45938 efficient to alloc 1 per page off the slab compared to 17K (5page)
45939 alloc of large cifs buffers even when page debugging is on */
45940 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
45941 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
45942 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
45943 NULL);
45944 if (cifs_sm_req_cachep == NULL) {
45945 mempool_destroy(cifs_req_poolp);
45946 @@ -1111,8 +1111,8 @@ init_cifs(void)
45947 atomic_set(&bufAllocCount, 0);
45948 atomic_set(&smBufAllocCount, 0);
45949 #ifdef CONFIG_CIFS_STATS2
45950 - atomic_set(&totBufAllocCount, 0);
45951 - atomic_set(&totSmBufAllocCount, 0);
45952 + atomic_set_unchecked(&totBufAllocCount, 0);
45953 + atomic_set_unchecked(&totSmBufAllocCount, 0);
45954 #endif /* CONFIG_CIFS_STATS2 */
45955
45956 atomic_set(&midCount, 0);
45957 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
45958 index f5af252..489b5f2 100644
45959 --- a/fs/cifs/cifsglob.h
45960 +++ b/fs/cifs/cifsglob.h
45961 @@ -751,35 +751,35 @@ struct cifs_tcon {
45962 __u16 Flags; /* optional support bits */
45963 enum statusEnum tidStatus;
45964 #ifdef CONFIG_CIFS_STATS
45965 - atomic_t num_smbs_sent;
45966 + atomic_unchecked_t num_smbs_sent;
45967 union {
45968 struct {
45969 - atomic_t num_writes;
45970 - atomic_t num_reads;
45971 - atomic_t num_flushes;
45972 - atomic_t num_oplock_brks;
45973 - atomic_t num_opens;
45974 - atomic_t num_closes;
45975 - atomic_t num_deletes;
45976 - atomic_t num_mkdirs;
45977 - atomic_t num_posixopens;
45978 - atomic_t num_posixmkdirs;
45979 - atomic_t num_rmdirs;
45980 - atomic_t num_renames;
45981 - atomic_t num_t2renames;
45982 - atomic_t num_ffirst;
45983 - atomic_t num_fnext;
45984 - atomic_t num_fclose;
45985 - atomic_t num_hardlinks;
45986 - atomic_t num_symlinks;
45987 - atomic_t num_locks;
45988 - atomic_t num_acl_get;
45989 - atomic_t num_acl_set;
45990 + atomic_unchecked_t num_writes;
45991 + atomic_unchecked_t num_reads;
45992 + atomic_unchecked_t num_flushes;
45993 + atomic_unchecked_t num_oplock_brks;
45994 + atomic_unchecked_t num_opens;
45995 + atomic_unchecked_t num_closes;
45996 + atomic_unchecked_t num_deletes;
45997 + atomic_unchecked_t num_mkdirs;
45998 + atomic_unchecked_t num_posixopens;
45999 + atomic_unchecked_t num_posixmkdirs;
46000 + atomic_unchecked_t num_rmdirs;
46001 + atomic_unchecked_t num_renames;
46002 + atomic_unchecked_t num_t2renames;
46003 + atomic_unchecked_t num_ffirst;
46004 + atomic_unchecked_t num_fnext;
46005 + atomic_unchecked_t num_fclose;
46006 + atomic_unchecked_t num_hardlinks;
46007 + atomic_unchecked_t num_symlinks;
46008 + atomic_unchecked_t num_locks;
46009 + atomic_unchecked_t num_acl_get;
46010 + atomic_unchecked_t num_acl_set;
46011 } cifs_stats;
46012 #ifdef CONFIG_CIFS_SMB2
46013 struct {
46014 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
46015 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
46016 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
46017 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
46018 } smb2_stats;
46019 #endif /* CONFIG_CIFS_SMB2 */
46020 } stats;
46021 @@ -1094,7 +1094,7 @@ build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
46022 }
46023
46024 #ifdef CONFIG_CIFS_STATS
46025 -#define cifs_stats_inc atomic_inc
46026 +#define cifs_stats_inc atomic_inc_unchecked
46027
46028 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
46029 unsigned int bytes)
46030 @@ -1459,8 +1459,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
46031 /* Various Debug counters */
46032 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
46033 #ifdef CONFIG_CIFS_STATS2
46034 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
46035 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
46036 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
46037 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
46038 #endif
46039 GLOBAL_EXTERN atomic_t smBufAllocCount;
46040 GLOBAL_EXTERN atomic_t midCount;
46041 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
46042 index 51dc2fb..1e12a33 100644
46043 --- a/fs/cifs/link.c
46044 +++ b/fs/cifs/link.c
46045 @@ -616,7 +616,7 @@ symlink_exit:
46046
46047 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
46048 {
46049 - char *p = nd_get_link(nd);
46050 + const char *p = nd_get_link(nd);
46051 if (!IS_ERR(p))
46052 kfree(p);
46053 }
46054 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
46055 index 3a00c0d..42d901c 100644
46056 --- a/fs/cifs/misc.c
46057 +++ b/fs/cifs/misc.c
46058 @@ -169,7 +169,7 @@ cifs_buf_get(void)
46059 memset(ret_buf, 0, buf_size + 3);
46060 atomic_inc(&bufAllocCount);
46061 #ifdef CONFIG_CIFS_STATS2
46062 - atomic_inc(&totBufAllocCount);
46063 + atomic_inc_unchecked(&totBufAllocCount);
46064 #endif /* CONFIG_CIFS_STATS2 */
46065 }
46066
46067 @@ -204,7 +204,7 @@ cifs_small_buf_get(void)
46068 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
46069 atomic_inc(&smBufAllocCount);
46070 #ifdef CONFIG_CIFS_STATS2
46071 - atomic_inc(&totSmBufAllocCount);
46072 + atomic_inc_unchecked(&totSmBufAllocCount);
46073 #endif /* CONFIG_CIFS_STATS2 */
46074
46075 }
46076 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
46077 index 591bf19..690d600 100644
46078 --- a/fs/cifs/smb1ops.c
46079 +++ b/fs/cifs/smb1ops.c
46080 @@ -617,27 +617,27 @@ static void
46081 cifs_clear_stats(struct cifs_tcon *tcon)
46082 {
46083 #ifdef CONFIG_CIFS_STATS
46084 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
46085 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
46086 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
46087 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
46088 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
46089 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
46090 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
46091 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
46092 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
46093 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
46094 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
46095 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
46096 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
46097 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
46098 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
46099 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
46100 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
46101 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
46102 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
46103 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
46104 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
46105 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
46106 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
46107 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
46108 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
46109 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
46110 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
46111 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
46112 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
46113 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
46114 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
46115 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
46116 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
46117 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
46118 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
46119 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
46120 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
46121 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
46122 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
46123 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
46124 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
46125 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
46126 #endif
46127 }
46128
46129 @@ -646,36 +646,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
46130 {
46131 #ifdef CONFIG_CIFS_STATS
46132 seq_printf(m, " Oplocks breaks: %d",
46133 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
46134 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
46135 seq_printf(m, "\nReads: %d Bytes: %llu",
46136 - atomic_read(&tcon->stats.cifs_stats.num_reads),
46137 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
46138 (long long)(tcon->bytes_read));
46139 seq_printf(m, "\nWrites: %d Bytes: %llu",
46140 - atomic_read(&tcon->stats.cifs_stats.num_writes),
46141 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
46142 (long long)(tcon->bytes_written));
46143 seq_printf(m, "\nFlushes: %d",
46144 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
46145 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
46146 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
46147 - atomic_read(&tcon->stats.cifs_stats.num_locks),
46148 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
46149 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
46150 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
46151 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
46152 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
46153 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
46154 - atomic_read(&tcon->stats.cifs_stats.num_opens),
46155 - atomic_read(&tcon->stats.cifs_stats.num_closes),
46156 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
46157 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
46158 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
46159 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
46160 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
46161 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
46162 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
46163 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
46164 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
46165 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
46166 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
46167 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
46168 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
46169 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
46170 seq_printf(m, "\nRenames: %d T2 Renames %d",
46171 - atomic_read(&tcon->stats.cifs_stats.num_renames),
46172 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
46173 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
46174 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
46175 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
46176 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
46177 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
46178 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
46179 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
46180 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
46181 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
46182 #endif
46183 }
46184
46185 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
46186 index 4d9dbe0..0af4601 100644
46187 --- a/fs/cifs/smb2ops.c
46188 +++ b/fs/cifs/smb2ops.c
46189 @@ -291,8 +291,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
46190 #ifdef CONFIG_CIFS_STATS
46191 int i;
46192 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
46193 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
46194 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
46195 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
46196 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
46197 }
46198 #endif
46199 }
46200 @@ -301,66 +301,66 @@ static void
46201 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
46202 {
46203 #ifdef CONFIG_CIFS_STATS
46204 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
46205 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
46206 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
46207 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
46208 seq_printf(m, "\nNegotiates: %d sent %d failed",
46209 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
46210 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
46211 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
46212 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
46213 seq_printf(m, "\nSessionSetups: %d sent %d failed",
46214 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
46215 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
46216 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
46217 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
46218 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
46219 seq_printf(m, "\nLogoffs: %d sent %d failed",
46220 - atomic_read(&sent[SMB2_LOGOFF_HE]),
46221 - atomic_read(&failed[SMB2_LOGOFF_HE]));
46222 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
46223 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
46224 seq_printf(m, "\nTreeConnects: %d sent %d failed",
46225 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
46226 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
46227 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
46228 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
46229 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
46230 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
46231 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
46232 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
46233 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
46234 seq_printf(m, "\nCreates: %d sent %d failed",
46235 - atomic_read(&sent[SMB2_CREATE_HE]),
46236 - atomic_read(&failed[SMB2_CREATE_HE]));
46237 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
46238 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
46239 seq_printf(m, "\nCloses: %d sent %d failed",
46240 - atomic_read(&sent[SMB2_CLOSE_HE]),
46241 - atomic_read(&failed[SMB2_CLOSE_HE]));
46242 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
46243 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
46244 seq_printf(m, "\nFlushes: %d sent %d failed",
46245 - atomic_read(&sent[SMB2_FLUSH_HE]),
46246 - atomic_read(&failed[SMB2_FLUSH_HE]));
46247 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
46248 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
46249 seq_printf(m, "\nReads: %d sent %d failed",
46250 - atomic_read(&sent[SMB2_READ_HE]),
46251 - atomic_read(&failed[SMB2_READ_HE]));
46252 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
46253 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
46254 seq_printf(m, "\nWrites: %d sent %d failed",
46255 - atomic_read(&sent[SMB2_WRITE_HE]),
46256 - atomic_read(&failed[SMB2_WRITE_HE]));
46257 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
46258 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
46259 seq_printf(m, "\nLocks: %d sent %d failed",
46260 - atomic_read(&sent[SMB2_LOCK_HE]),
46261 - atomic_read(&failed[SMB2_LOCK_HE]));
46262 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
46263 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
46264 seq_printf(m, "\nIOCTLs: %d sent %d failed",
46265 - atomic_read(&sent[SMB2_IOCTL_HE]),
46266 - atomic_read(&failed[SMB2_IOCTL_HE]));
46267 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
46268 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
46269 seq_printf(m, "\nCancels: %d sent %d failed",
46270 - atomic_read(&sent[SMB2_CANCEL_HE]),
46271 - atomic_read(&failed[SMB2_CANCEL_HE]));
46272 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
46273 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
46274 seq_printf(m, "\nEchos: %d sent %d failed",
46275 - atomic_read(&sent[SMB2_ECHO_HE]),
46276 - atomic_read(&failed[SMB2_ECHO_HE]));
46277 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
46278 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
46279 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
46280 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
46281 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
46282 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
46283 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
46284 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
46285 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
46286 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
46287 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
46288 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
46289 seq_printf(m, "\nQueryInfos: %d sent %d failed",
46290 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
46291 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
46292 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
46293 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
46294 seq_printf(m, "\nSetInfos: %d sent %d failed",
46295 - atomic_read(&sent[SMB2_SET_INFO_HE]),
46296 - atomic_read(&failed[SMB2_SET_INFO_HE]));
46297 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
46298 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
46299 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
46300 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
46301 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
46302 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
46303 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
46304 #endif
46305 }
46306
46307 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
46308 index 958ae0e..505c9d0 100644
46309 --- a/fs/coda/cache.c
46310 +++ b/fs/coda/cache.c
46311 @@ -24,7 +24,7 @@
46312 #include "coda_linux.h"
46313 #include "coda_cache.h"
46314
46315 -static atomic_t permission_epoch = ATOMIC_INIT(0);
46316 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
46317
46318 /* replace or extend an acl cache hit */
46319 void coda_cache_enter(struct inode *inode, int mask)
46320 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
46321 struct coda_inode_info *cii = ITOC(inode);
46322
46323 spin_lock(&cii->c_lock);
46324 - cii->c_cached_epoch = atomic_read(&permission_epoch);
46325 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
46326 if (cii->c_uid != current_fsuid()) {
46327 cii->c_uid = current_fsuid();
46328 cii->c_cached_perm = mask;
46329 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
46330 {
46331 struct coda_inode_info *cii = ITOC(inode);
46332 spin_lock(&cii->c_lock);
46333 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
46334 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
46335 spin_unlock(&cii->c_lock);
46336 }
46337
46338 /* remove all acl caches */
46339 void coda_cache_clear_all(struct super_block *sb)
46340 {
46341 - atomic_inc(&permission_epoch);
46342 + atomic_inc_unchecked(&permission_epoch);
46343 }
46344
46345
46346 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
46347 spin_lock(&cii->c_lock);
46348 hit = (mask & cii->c_cached_perm) == mask &&
46349 cii->c_uid == current_fsuid() &&
46350 - cii->c_cached_epoch == atomic_read(&permission_epoch);
46351 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
46352 spin_unlock(&cii->c_lock);
46353
46354 return hit;
46355 diff --git a/fs/compat.c b/fs/compat.c
46356 index 015e1e1..5ce8e54 100644
46357 --- a/fs/compat.c
46358 +++ b/fs/compat.c
46359 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
46360
46361 set_fs(KERNEL_DS);
46362 /* The __user pointer cast is valid because of the set_fs() */
46363 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
46364 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
46365 set_fs(oldfs);
46366 /* truncating is ok because it's a user address */
46367 if (!ret)
46368 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
46369 goto out;
46370
46371 ret = -EINVAL;
46372 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
46373 + if (nr_segs > UIO_MAXIOV)
46374 goto out;
46375 if (nr_segs > fast_segs) {
46376 ret = -ENOMEM;
46377 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
46378
46379 struct compat_readdir_callback {
46380 struct compat_old_linux_dirent __user *dirent;
46381 + struct file * file;
46382 int result;
46383 };
46384
46385 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
46386 buf->result = -EOVERFLOW;
46387 return -EOVERFLOW;
46388 }
46389 +
46390 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46391 + return 0;
46392 +
46393 buf->result++;
46394 dirent = buf->dirent;
46395 if (!access_ok(VERIFY_WRITE, dirent,
46396 @@ -878,6 +883,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
46397
46398 buf.result = 0;
46399 buf.dirent = dirent;
46400 + buf.file = f.file;
46401
46402 error = vfs_readdir(f.file, compat_fillonedir, &buf);
46403 if (buf.result)
46404 @@ -897,6 +903,7 @@ struct compat_linux_dirent {
46405 struct compat_getdents_callback {
46406 struct compat_linux_dirent __user *current_dir;
46407 struct compat_linux_dirent __user *previous;
46408 + struct file * file;
46409 int count;
46410 int error;
46411 };
46412 @@ -918,6 +925,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
46413 buf->error = -EOVERFLOW;
46414 return -EOVERFLOW;
46415 }
46416 +
46417 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46418 + return 0;
46419 +
46420 dirent = buf->previous;
46421 if (dirent) {
46422 if (__put_user(offset, &dirent->d_off))
46423 @@ -963,6 +974,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
46424 buf.previous = NULL;
46425 buf.count = count;
46426 buf.error = 0;
46427 + buf.file = f.file;
46428
46429 error = vfs_readdir(f.file, compat_filldir, &buf);
46430 if (error >= 0)
46431 @@ -983,6 +995,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
46432 struct compat_getdents_callback64 {
46433 struct linux_dirent64 __user *current_dir;
46434 struct linux_dirent64 __user *previous;
46435 + struct file * file;
46436 int count;
46437 int error;
46438 };
46439 @@ -999,6 +1012,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
46440 buf->error = -EINVAL; /* only used if we fail.. */
46441 if (reclen > buf->count)
46442 return -EINVAL;
46443 +
46444 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46445 + return 0;
46446 +
46447 dirent = buf->previous;
46448
46449 if (dirent) {
46450 @@ -1048,13 +1065,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
46451 buf.previous = NULL;
46452 buf.count = count;
46453 buf.error = 0;
46454 + buf.file = f.file;
46455
46456 error = vfs_readdir(f.file, compat_filldir64, &buf);
46457 if (error >= 0)
46458 error = buf.error;
46459 lastdirent = buf.previous;
46460 if (lastdirent) {
46461 - typeof(lastdirent->d_off) d_off = f.file->f_pos;
46462 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
46463 if (__put_user_unaligned(d_off, &lastdirent->d_off))
46464 error = -EFAULT;
46465 else
46466 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
46467 index a81147e..20bf2b5 100644
46468 --- a/fs/compat_binfmt_elf.c
46469 +++ b/fs/compat_binfmt_elf.c
46470 @@ -30,11 +30,13 @@
46471 #undef elf_phdr
46472 #undef elf_shdr
46473 #undef elf_note
46474 +#undef elf_dyn
46475 #undef elf_addr_t
46476 #define elfhdr elf32_hdr
46477 #define elf_phdr elf32_phdr
46478 #define elf_shdr elf32_shdr
46479 #define elf_note elf32_note
46480 +#define elf_dyn Elf32_Dyn
46481 #define elf_addr_t Elf32_Addr
46482
46483 /*
46484 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
46485 index 4c6285f..b7a2411 100644
46486 --- a/fs/compat_ioctl.c
46487 +++ b/fs/compat_ioctl.c
46488 @@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
46489 return -EFAULT;
46490 if (__get_user(udata, &ss32->iomem_base))
46491 return -EFAULT;
46492 - ss.iomem_base = compat_ptr(udata);
46493 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
46494 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
46495 __get_user(ss.port_high, &ss32->port_high))
46496 return -EFAULT;
46497 @@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
46498 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
46499 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
46500 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
46501 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
46502 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
46503 return -EFAULT;
46504
46505 return ioctl_preallocate(file, p);
46506 @@ -1617,8 +1617,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
46507 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
46508 {
46509 unsigned int a, b;
46510 - a = *(unsigned int *)p;
46511 - b = *(unsigned int *)q;
46512 + a = *(const unsigned int *)p;
46513 + b = *(const unsigned int *)q;
46514 if (a > b)
46515 return 1;
46516 if (a < b)
46517 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
46518 index 7414ae2..d98ad6d 100644
46519 --- a/fs/configfs/dir.c
46520 +++ b/fs/configfs/dir.c
46521 @@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
46522 }
46523 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
46524 struct configfs_dirent *next;
46525 - const char * name;
46526 + const unsigned char * name;
46527 + char d_name[sizeof(next->s_dentry->d_iname)];
46528 int len;
46529 struct inode *inode = NULL;
46530
46531 @@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
46532 continue;
46533
46534 name = configfs_get_name(next);
46535 - len = strlen(name);
46536 + if (next->s_dentry && name == next->s_dentry->d_iname) {
46537 + len = next->s_dentry->d_name.len;
46538 + memcpy(d_name, name, len);
46539 + name = d_name;
46540 + } else
46541 + len = strlen(name);
46542
46543 /*
46544 * We'll have a dentry and an inode for
46545 diff --git a/fs/coredump.c b/fs/coredump.c
46546 index ce47379..68c8e43 100644
46547 --- a/fs/coredump.c
46548 +++ b/fs/coredump.c
46549 @@ -52,7 +52,7 @@ struct core_name {
46550 char *corename;
46551 int used, size;
46552 };
46553 -static atomic_t call_count = ATOMIC_INIT(1);
46554 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
46555
46556 /* The maximal length of core_pattern is also specified in sysctl.c */
46557
46558 @@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
46559 {
46560 char *old_corename = cn->corename;
46561
46562 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
46563 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
46564 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
46565
46566 if (!cn->corename) {
46567 @@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
46568 int pid_in_pattern = 0;
46569 int err = 0;
46570
46571 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
46572 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
46573 cn->corename = kmalloc(cn->size, GFP_KERNEL);
46574 cn->used = 0;
46575
46576 @@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
46577 pipe = file->f_path.dentry->d_inode->i_pipe;
46578
46579 pipe_lock(pipe);
46580 - pipe->readers++;
46581 - pipe->writers--;
46582 + atomic_inc(&pipe->readers);
46583 + atomic_dec(&pipe->writers);
46584
46585 - while ((pipe->readers > 1) && (!signal_pending(current))) {
46586 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
46587 wake_up_interruptible_sync(&pipe->wait);
46588 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
46589 pipe_wait(pipe);
46590 }
46591
46592 - pipe->readers--;
46593 - pipe->writers++;
46594 + atomic_dec(&pipe->readers);
46595 + atomic_inc(&pipe->writers);
46596 pipe_unlock(pipe);
46597
46598 }
46599 @@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46600 int ispipe;
46601 struct files_struct *displaced;
46602 bool need_nonrelative = false;
46603 - static atomic_t core_dump_count = ATOMIC_INIT(0);
46604 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
46605 + long signr = siginfo->si_signo;
46606 struct coredump_params cprm = {
46607 .siginfo = siginfo,
46608 .regs = regs,
46609 @@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46610 .mm_flags = mm->flags,
46611 };
46612
46613 - audit_core_dumps(siginfo->si_signo);
46614 + audit_core_dumps(signr);
46615 +
46616 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
46617 + gr_handle_brute_attach(cprm.mm_flags);
46618
46619 binfmt = mm->binfmt;
46620 if (!binfmt || !binfmt->core_dump)
46621 @@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46622 need_nonrelative = true;
46623 }
46624
46625 - retval = coredump_wait(siginfo->si_signo, &core_state);
46626 + retval = coredump_wait(signr, &core_state);
46627 if (retval < 0)
46628 goto fail_creds;
46629
46630 @@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46631 }
46632 cprm.limit = RLIM_INFINITY;
46633
46634 - dump_count = atomic_inc_return(&core_dump_count);
46635 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
46636 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
46637 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
46638 task_tgid_vnr(current), current->comm);
46639 @@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46640 } else {
46641 struct inode *inode;
46642
46643 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
46644 +
46645 if (cprm.limit < binfmt->min_coredump)
46646 goto fail_unlock;
46647
46648 @@ -640,7 +646,7 @@ close_fail:
46649 filp_close(cprm.file, NULL);
46650 fail_dropcount:
46651 if (ispipe)
46652 - atomic_dec(&core_dump_count);
46653 + atomic_dec_unchecked(&core_dump_count);
46654 fail_unlock:
46655 kfree(cn.corename);
46656 fail_corename:
46657 @@ -659,7 +665,7 @@ fail:
46658 */
46659 int dump_write(struct file *file, const void *addr, int nr)
46660 {
46661 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
46662 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
46663 }
46664 EXPORT_SYMBOL(dump_write);
46665
46666 diff --git a/fs/dcache.c b/fs/dcache.c
46667 index 0d0adb6..f4646e9 100644
46668 --- a/fs/dcache.c
46669 +++ b/fs/dcache.c
46670 @@ -3164,7 +3164,7 @@ void __init vfs_caches_init(unsigned long mempages)
46671 mempages -= reserve;
46672
46673 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
46674 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
46675 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
46676
46677 dcache_init();
46678 inode_init();
46679 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
46680 index b607d92..41fda09 100644
46681 --- a/fs/debugfs/inode.c
46682 +++ b/fs/debugfs/inode.c
46683 @@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
46684 */
46685 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
46686 {
46687 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
46688 + return __create_file(name, S_IFDIR | S_IRWXU,
46689 +#else
46690 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
46691 +#endif
46692 parent, NULL, NULL);
46693 }
46694 EXPORT_SYMBOL_GPL(debugfs_create_dir);
46695 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
46696 index cc7709e..7e7211f 100644
46697 --- a/fs/ecryptfs/inode.c
46698 +++ b/fs/ecryptfs/inode.c
46699 @@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
46700 old_fs = get_fs();
46701 set_fs(get_ds());
46702 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
46703 - (char __user *)lower_buf,
46704 + (char __force_user *)lower_buf,
46705 PATH_MAX);
46706 set_fs(old_fs);
46707 if (rc < 0)
46708 @@ -706,7 +706,7 @@ out:
46709 static void
46710 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
46711 {
46712 - char *buf = nd_get_link(nd);
46713 + const char *buf = nd_get_link(nd);
46714 if (!IS_ERR(buf)) {
46715 /* Free the char* */
46716 kfree(buf);
46717 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
46718 index 412e6ed..4292d22 100644
46719 --- a/fs/ecryptfs/miscdev.c
46720 +++ b/fs/ecryptfs/miscdev.c
46721 @@ -315,7 +315,7 @@ check_list:
46722 goto out_unlock_msg_ctx;
46723 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
46724 if (msg_ctx->msg) {
46725 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
46726 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
46727 goto out_unlock_msg_ctx;
46728 i += packet_length_size;
46729 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
46730 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
46731 index b2a34a1..162fa69 100644
46732 --- a/fs/ecryptfs/read_write.c
46733 +++ b/fs/ecryptfs/read_write.c
46734 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
46735 return -EIO;
46736 fs_save = get_fs();
46737 set_fs(get_ds());
46738 - rc = vfs_write(lower_file, data, size, &offset);
46739 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
46740 set_fs(fs_save);
46741 mark_inode_dirty_sync(ecryptfs_inode);
46742 return rc;
46743 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
46744 return -EIO;
46745 fs_save = get_fs();
46746 set_fs(get_ds());
46747 - rc = vfs_read(lower_file, data, size, &offset);
46748 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
46749 set_fs(fs_save);
46750 return rc;
46751 }
46752 diff --git a/fs/exec.c b/fs/exec.c
46753 index c6e6de4..45e71ad 100644
46754 --- a/fs/exec.c
46755 +++ b/fs/exec.c
46756 @@ -55,6 +55,17 @@
46757 #include <linux/pipe_fs_i.h>
46758 #include <linux/oom.h>
46759 #include <linux/compat.h>
46760 +#include <linux/random.h>
46761 +#include <linux/seq_file.h>
46762 +#include <linux/coredump.h>
46763 +#include <linux/mman.h>
46764 +
46765 +#ifdef CONFIG_PAX_REFCOUNT
46766 +#include <linux/kallsyms.h>
46767 +#include <linux/kdebug.h>
46768 +#endif
46769 +
46770 +#include <trace/events/fs.h>
46771
46772 #include <asm/uaccess.h>
46773 #include <asm/mmu_context.h>
46774 @@ -66,6 +77,18 @@
46775
46776 #include <trace/events/sched.h>
46777
46778 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
46779 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
46780 +{
46781 + 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");
46782 +}
46783 +#endif
46784 +
46785 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
46786 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
46787 +EXPORT_SYMBOL(pax_set_initial_flags_func);
46788 +#endif
46789 +
46790 int suid_dumpable = 0;
46791
46792 static LIST_HEAD(formats);
46793 @@ -180,18 +203,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
46794 int write)
46795 {
46796 struct page *page;
46797 - int ret;
46798
46799 -#ifdef CONFIG_STACK_GROWSUP
46800 - if (write) {
46801 - ret = expand_downwards(bprm->vma, pos);
46802 - if (ret < 0)
46803 - return NULL;
46804 - }
46805 -#endif
46806 - ret = get_user_pages(current, bprm->mm, pos,
46807 - 1, write, 1, &page, NULL);
46808 - if (ret <= 0)
46809 + if (0 > expand_downwards(bprm->vma, pos))
46810 + return NULL;
46811 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
46812 return NULL;
46813
46814 if (write) {
46815 @@ -207,6 +222,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
46816 if (size <= ARG_MAX)
46817 return page;
46818
46819 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46820 + // only allow 512KB for argv+env on suid/sgid binaries
46821 + // to prevent easy ASLR exhaustion
46822 + if (((bprm->cred->euid != current_euid()) ||
46823 + (bprm->cred->egid != current_egid())) &&
46824 + (size > (512 * 1024))) {
46825 + put_page(page);
46826 + return NULL;
46827 + }
46828 +#endif
46829 +
46830 /*
46831 * Limit to 1/4-th the stack size for the argv+env strings.
46832 * This ensures that:
46833 @@ -266,6 +292,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
46834 vma->vm_end = STACK_TOP_MAX;
46835 vma->vm_start = vma->vm_end - PAGE_SIZE;
46836 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
46837 +
46838 +#ifdef CONFIG_PAX_SEGMEXEC
46839 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
46840 +#endif
46841 +
46842 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
46843 INIT_LIST_HEAD(&vma->anon_vma_chain);
46844
46845 @@ -276,6 +307,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
46846 mm->stack_vm = mm->total_vm = 1;
46847 up_write(&mm->mmap_sem);
46848 bprm->p = vma->vm_end - sizeof(void *);
46849 +
46850 +#ifdef CONFIG_PAX_RANDUSTACK
46851 + if (randomize_va_space)
46852 + bprm->p ^= random32() & ~PAGE_MASK;
46853 +#endif
46854 +
46855 return 0;
46856 err:
46857 up_write(&mm->mmap_sem);
46858 @@ -384,19 +421,7 @@ err:
46859 return err;
46860 }
46861
46862 -struct user_arg_ptr {
46863 -#ifdef CONFIG_COMPAT
46864 - bool is_compat;
46865 -#endif
46866 - union {
46867 - const char __user *const __user *native;
46868 -#ifdef CONFIG_COMPAT
46869 - const compat_uptr_t __user *compat;
46870 -#endif
46871 - } ptr;
46872 -};
46873 -
46874 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
46875 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
46876 {
46877 const char __user *native;
46878
46879 @@ -405,14 +430,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
46880 compat_uptr_t compat;
46881
46882 if (get_user(compat, argv.ptr.compat + nr))
46883 - return ERR_PTR(-EFAULT);
46884 + return (const char __force_user *)ERR_PTR(-EFAULT);
46885
46886 return compat_ptr(compat);
46887 }
46888 #endif
46889
46890 if (get_user(native, argv.ptr.native + nr))
46891 - return ERR_PTR(-EFAULT);
46892 + return (const char __force_user *)ERR_PTR(-EFAULT);
46893
46894 return native;
46895 }
46896 @@ -431,11 +456,12 @@ static int count(struct user_arg_ptr argv, int max)
46897 if (!p)
46898 break;
46899
46900 - if (IS_ERR(p))
46901 + if (IS_ERR((const char __force_kernel *)p))
46902 return -EFAULT;
46903
46904 - if (i++ >= max)
46905 + if (i >= max)
46906 return -E2BIG;
46907 + ++i;
46908
46909 if (fatal_signal_pending(current))
46910 return -ERESTARTNOHAND;
46911 @@ -465,7 +491,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
46912
46913 ret = -EFAULT;
46914 str = get_user_arg_ptr(argv, argc);
46915 - if (IS_ERR(str))
46916 + if (IS_ERR((const char __force_kernel *)str))
46917 goto out;
46918
46919 len = strnlen_user(str, MAX_ARG_STRLEN);
46920 @@ -547,7 +573,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
46921 int r;
46922 mm_segment_t oldfs = get_fs();
46923 struct user_arg_ptr argv = {
46924 - .ptr.native = (const char __user *const __user *)__argv,
46925 + .ptr.native = (const char __force_user *const __force_user *)__argv,
46926 };
46927
46928 set_fs(KERNEL_DS);
46929 @@ -582,7 +608,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
46930 unsigned long new_end = old_end - shift;
46931 struct mmu_gather tlb;
46932
46933 - BUG_ON(new_start > new_end);
46934 + if (new_start >= new_end || new_start < mmap_min_addr)
46935 + return -ENOMEM;
46936
46937 /*
46938 * ensure there are no vmas between where we want to go
46939 @@ -591,6 +618,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
46940 if (vma != find_vma(mm, new_start))
46941 return -EFAULT;
46942
46943 +#ifdef CONFIG_PAX_SEGMEXEC
46944 + BUG_ON(pax_find_mirror_vma(vma));
46945 +#endif
46946 +
46947 /*
46948 * cover the whole range: [new_start, old_end)
46949 */
46950 @@ -671,10 +702,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
46951 stack_top = arch_align_stack(stack_top);
46952 stack_top = PAGE_ALIGN(stack_top);
46953
46954 - if (unlikely(stack_top < mmap_min_addr) ||
46955 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
46956 - return -ENOMEM;
46957 -
46958 stack_shift = vma->vm_end - stack_top;
46959
46960 bprm->p -= stack_shift;
46961 @@ -686,8 +713,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
46962 bprm->exec -= stack_shift;
46963
46964 down_write(&mm->mmap_sem);
46965 +
46966 + /* Move stack pages down in memory. */
46967 + if (stack_shift) {
46968 + ret = shift_arg_pages(vma, stack_shift);
46969 + if (ret)
46970 + goto out_unlock;
46971 + }
46972 +
46973 vm_flags = VM_STACK_FLAGS;
46974
46975 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
46976 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46977 + vm_flags &= ~VM_EXEC;
46978 +
46979 +#ifdef CONFIG_PAX_MPROTECT
46980 + if (mm->pax_flags & MF_PAX_MPROTECT)
46981 + vm_flags &= ~VM_MAYEXEC;
46982 +#endif
46983 +
46984 + }
46985 +#endif
46986 +
46987 /*
46988 * Adjust stack execute permissions; explicitly enable for
46989 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
46990 @@ -706,13 +753,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
46991 goto out_unlock;
46992 BUG_ON(prev != vma);
46993
46994 - /* Move stack pages down in memory. */
46995 - if (stack_shift) {
46996 - ret = shift_arg_pages(vma, stack_shift);
46997 - if (ret)
46998 - goto out_unlock;
46999 - }
47000 -
47001 /* mprotect_fixup is overkill to remove the temporary stack flags */
47002 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
47003
47004 @@ -736,6 +776,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
47005 #endif
47006 current->mm->start_stack = bprm->p;
47007 ret = expand_stack(vma, stack_base);
47008 +
47009 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_ASLR)
47010 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
47011 + unsigned long size, flags, vm_flags;
47012 +
47013 + size = STACK_TOP - vma->vm_end;
47014 + flags = MAP_FIXED | MAP_PRIVATE;
47015 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
47016 +
47017 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, flags, vm_flags, 0);
47018 +
47019 +#ifdef CONFIG_X86
47020 + if (!ret) {
47021 + size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
47022 + ret = 0 != mmap_region(NULL, 0, size, flags, vm_flags, 0);
47023 + }
47024 +#endif
47025 +
47026 + }
47027 +#endif
47028 +
47029 if (ret)
47030 ret = -EFAULT;
47031
47032 @@ -771,6 +832,8 @@ struct file *open_exec(const char *name)
47033
47034 fsnotify_open(file);
47035
47036 + trace_open_exec(name);
47037 +
47038 err = deny_write_access(file);
47039 if (err)
47040 goto exit;
47041 @@ -794,7 +857,7 @@ int kernel_read(struct file *file, loff_t offset,
47042 old_fs = get_fs();
47043 set_fs(get_ds());
47044 /* The cast to a user pointer is valid due to the set_fs() */
47045 - result = vfs_read(file, (void __user *)addr, count, &pos);
47046 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
47047 set_fs(old_fs);
47048 return result;
47049 }
47050 @@ -1246,7 +1309,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
47051 }
47052 rcu_read_unlock();
47053
47054 - if (p->fs->users > n_fs) {
47055 + if (atomic_read(&p->fs->users) > n_fs) {
47056 bprm->unsafe |= LSM_UNSAFE_SHARE;
47057 } else {
47058 res = -EAGAIN;
47059 @@ -1449,6 +1512,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
47060
47061 EXPORT_SYMBOL(search_binary_handler);
47062
47063 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47064 +static DEFINE_PER_CPU(u64, exec_counter);
47065 +static int __init init_exec_counters(void)
47066 +{
47067 + unsigned int cpu;
47068 +
47069 + for_each_possible_cpu(cpu) {
47070 + per_cpu(exec_counter, cpu) = (u64)cpu;
47071 + }
47072 +
47073 + return 0;
47074 +}
47075 +early_initcall(init_exec_counters);
47076 +static inline void increment_exec_counter(void)
47077 +{
47078 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
47079 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
47080 +}
47081 +#else
47082 +static inline void increment_exec_counter(void) {}
47083 +#endif
47084 +
47085 /*
47086 * sys_execve() executes a new program.
47087 */
47088 @@ -1457,6 +1542,11 @@ static int do_execve_common(const char *filename,
47089 struct user_arg_ptr envp,
47090 struct pt_regs *regs)
47091 {
47092 +#ifdef CONFIG_GRKERNSEC
47093 + struct file *old_exec_file;
47094 + struct acl_subject_label *old_acl;
47095 + struct rlimit old_rlim[RLIM_NLIMITS];
47096 +#endif
47097 struct linux_binprm *bprm;
47098 struct file *file;
47099 struct files_struct *displaced;
47100 @@ -1464,6 +1554,8 @@ static int do_execve_common(const char *filename,
47101 int retval;
47102 const struct cred *cred = current_cred();
47103
47104 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
47105 +
47106 /*
47107 * We move the actual failure in case of RLIMIT_NPROC excess from
47108 * set*uid() to execve() because too many poorly written programs
47109 @@ -1504,12 +1596,27 @@ static int do_execve_common(const char *filename,
47110 if (IS_ERR(file))
47111 goto out_unmark;
47112
47113 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
47114 + retval = -EPERM;
47115 + goto out_file;
47116 + }
47117 +
47118 sched_exec();
47119
47120 bprm->file = file;
47121 bprm->filename = filename;
47122 bprm->interp = filename;
47123
47124 + if (gr_process_user_ban()) {
47125 + retval = -EPERM;
47126 + goto out_file;
47127 + }
47128 +
47129 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
47130 + retval = -EACCES;
47131 + goto out_file;
47132 + }
47133 +
47134 retval = bprm_mm_init(bprm);
47135 if (retval)
47136 goto out_file;
47137 @@ -1526,24 +1633,65 @@ static int do_execve_common(const char *filename,
47138 if (retval < 0)
47139 goto out;
47140
47141 +#ifdef CONFIG_GRKERNSEC
47142 + old_acl = current->acl;
47143 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
47144 + old_exec_file = current->exec_file;
47145 + get_file(file);
47146 + current->exec_file = file;
47147 +#endif
47148 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47149 + /* limit suid stack to 8MB
47150 + we saved the old limits above and will restore them if this exec fails
47151 + */
47152 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
47153 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
47154 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
47155 +#endif
47156 +
47157 + if (!gr_tpe_allow(file)) {
47158 + retval = -EACCES;
47159 + goto out_fail;
47160 + }
47161 +
47162 + if (gr_check_crash_exec(file)) {
47163 + retval = -EACCES;
47164 + goto out_fail;
47165 + }
47166 +
47167 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
47168 + bprm->unsafe);
47169 + if (retval < 0)
47170 + goto out_fail;
47171 +
47172 retval = copy_strings_kernel(1, &bprm->filename, bprm);
47173 if (retval < 0)
47174 - goto out;
47175 + goto out_fail;
47176
47177 bprm->exec = bprm->p;
47178 retval = copy_strings(bprm->envc, envp, bprm);
47179 if (retval < 0)
47180 - goto out;
47181 + goto out_fail;
47182
47183 retval = copy_strings(bprm->argc, argv, bprm);
47184 if (retval < 0)
47185 - goto out;
47186 + goto out_fail;
47187 +
47188 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
47189 +
47190 + gr_handle_exec_args(bprm, argv);
47191
47192 retval = search_binary_handler(bprm,regs);
47193 if (retval < 0)
47194 - goto out;
47195 + goto out_fail;
47196 +#ifdef CONFIG_GRKERNSEC
47197 + if (old_exec_file)
47198 + fput(old_exec_file);
47199 +#endif
47200
47201 /* execve succeeded */
47202 +
47203 + increment_exec_counter();
47204 current->fs->in_exec = 0;
47205 current->in_execve = 0;
47206 acct_update_integrals(current);
47207 @@ -1552,6 +1700,14 @@ static int do_execve_common(const char *filename,
47208 put_files_struct(displaced);
47209 return retval;
47210
47211 +out_fail:
47212 +#ifdef CONFIG_GRKERNSEC
47213 + current->acl = old_acl;
47214 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
47215 + fput(current->exec_file);
47216 + current->exec_file = old_exec_file;
47217 +#endif
47218 +
47219 out:
47220 if (bprm->mm) {
47221 acct_arg_size(bprm, 0);
47222 @@ -1727,3 +1883,253 @@ int kernel_execve(const char *filename,
47223 ret_from_kernel_execve(p);
47224 }
47225 #endif
47226 +
47227 +int pax_check_flags(unsigned long *flags)
47228 +{
47229 + int retval = 0;
47230 +
47231 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
47232 + if (*flags & MF_PAX_SEGMEXEC)
47233 + {
47234 + *flags &= ~MF_PAX_SEGMEXEC;
47235 + retval = -EINVAL;
47236 + }
47237 +#endif
47238 +
47239 + if ((*flags & MF_PAX_PAGEEXEC)
47240 +
47241 +#ifdef CONFIG_PAX_PAGEEXEC
47242 + && (*flags & MF_PAX_SEGMEXEC)
47243 +#endif
47244 +
47245 + )
47246 + {
47247 + *flags &= ~MF_PAX_PAGEEXEC;
47248 + retval = -EINVAL;
47249 + }
47250 +
47251 + if ((*flags & MF_PAX_MPROTECT)
47252 +
47253 +#ifdef CONFIG_PAX_MPROTECT
47254 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
47255 +#endif
47256 +
47257 + )
47258 + {
47259 + *flags &= ~MF_PAX_MPROTECT;
47260 + retval = -EINVAL;
47261 + }
47262 +
47263 + if ((*flags & MF_PAX_EMUTRAMP)
47264 +
47265 +#ifdef CONFIG_PAX_EMUTRAMP
47266 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
47267 +#endif
47268 +
47269 + )
47270 + {
47271 + *flags &= ~MF_PAX_EMUTRAMP;
47272 + retval = -EINVAL;
47273 + }
47274 +
47275 + return retval;
47276 +}
47277 +
47278 +EXPORT_SYMBOL(pax_check_flags);
47279 +
47280 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
47281 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
47282 +{
47283 + struct task_struct *tsk = current;
47284 + struct mm_struct *mm = current->mm;
47285 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
47286 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
47287 + char *path_exec = NULL;
47288 + char *path_fault = NULL;
47289 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
47290 + siginfo_t info = { };
47291 +
47292 + if (buffer_exec && buffer_fault) {
47293 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
47294 +
47295 + down_read(&mm->mmap_sem);
47296 + vma = mm->mmap;
47297 + while (vma && (!vma_exec || !vma_fault)) {
47298 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
47299 + vma_exec = vma;
47300 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
47301 + vma_fault = vma;
47302 + vma = vma->vm_next;
47303 + }
47304 + if (vma_exec) {
47305 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
47306 + if (IS_ERR(path_exec))
47307 + path_exec = "<path too long>";
47308 + else {
47309 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
47310 + if (path_exec) {
47311 + *path_exec = 0;
47312 + path_exec = buffer_exec;
47313 + } else
47314 + path_exec = "<path too long>";
47315 + }
47316 + }
47317 + if (vma_fault) {
47318 + start = vma_fault->vm_start;
47319 + end = vma_fault->vm_end;
47320 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
47321 + if (vma_fault->vm_file) {
47322 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
47323 + if (IS_ERR(path_fault))
47324 + path_fault = "<path too long>";
47325 + else {
47326 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
47327 + if (path_fault) {
47328 + *path_fault = 0;
47329 + path_fault = buffer_fault;
47330 + } else
47331 + path_fault = "<path too long>";
47332 + }
47333 + } else
47334 + path_fault = "<anonymous mapping>";
47335 + }
47336 + up_read(&mm->mmap_sem);
47337 + }
47338 + if (tsk->signal->curr_ip)
47339 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
47340 + else
47341 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
47342 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
47343 + from_kuid(&init_user_ns, task_uid(tsk)), from_kuid(&init_user_ns, task_euid(tsk)), pc, sp);
47344 + free_page((unsigned long)buffer_exec);
47345 + free_page((unsigned long)buffer_fault);
47346 + pax_report_insns(regs, pc, sp);
47347 + info.si_signo = SIGKILL;
47348 + info.si_errno = 0;
47349 + info.si_code = SI_KERNEL;
47350 + info.si_pid = 0;
47351 + info.si_uid = 0;
47352 + do_coredump(&info, regs);
47353 +}
47354 +#endif
47355 +
47356 +#ifdef CONFIG_PAX_REFCOUNT
47357 +void pax_report_refcount_overflow(struct pt_regs *regs)
47358 +{
47359 + if (current->signal->curr_ip)
47360 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
47361 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
47362 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
47363 + else
47364 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
47365 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
47366 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
47367 + show_regs(regs);
47368 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
47369 +}
47370 +#endif
47371 +
47372 +#ifdef CONFIG_PAX_USERCOPY
47373 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
47374 +static noinline int check_stack_object(const void *obj, unsigned long len)
47375 +{
47376 + const void * const stack = task_stack_page(current);
47377 + const void * const stackend = stack + THREAD_SIZE;
47378 +
47379 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
47380 + const void *frame = NULL;
47381 + const void *oldframe;
47382 +#endif
47383 +
47384 + if (obj + len < obj)
47385 + return -1;
47386 +
47387 + if (obj + len <= stack || stackend <= obj)
47388 + return 0;
47389 +
47390 + if (obj < stack || stackend < obj + len)
47391 + return -1;
47392 +
47393 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
47394 + oldframe = __builtin_frame_address(1);
47395 + if (oldframe)
47396 + frame = __builtin_frame_address(2);
47397 + /*
47398 + low ----------------------------------------------> high
47399 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
47400 + ^----------------^
47401 + allow copies only within here
47402 + */
47403 + while (stack <= frame && frame < stackend) {
47404 + /* if obj + len extends past the last frame, this
47405 + check won't pass and the next frame will be 0,
47406 + causing us to bail out and correctly report
47407 + the copy as invalid
47408 + */
47409 + if (obj + len <= frame)
47410 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
47411 + oldframe = frame;
47412 + frame = *(const void * const *)frame;
47413 + }
47414 + return -1;
47415 +#else
47416 + return 1;
47417 +#endif
47418 +}
47419 +
47420 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
47421 +{
47422 + if (current->signal->curr_ip)
47423 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
47424 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
47425 + else
47426 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
47427 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
47428 + dump_stack();
47429 + gr_handle_kernel_exploit();
47430 + do_group_exit(SIGKILL);
47431 +}
47432 +#endif
47433 +
47434 +void __check_object_size(const void *ptr, unsigned long n, bool to)
47435 +{
47436 +
47437 +#ifdef CONFIG_PAX_USERCOPY
47438 + const char *type;
47439 +
47440 + if (!n)
47441 + return;
47442 +
47443 + type = check_heap_object(ptr, n);
47444 + if (!type) {
47445 + if (check_stack_object(ptr, n) != -1)
47446 + return;
47447 + type = "<process stack>";
47448 + }
47449 +
47450 + pax_report_usercopy(ptr, n, to, type);
47451 +#endif
47452 +
47453 +}
47454 +EXPORT_SYMBOL(__check_object_size);
47455 +
47456 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
47457 +void pax_track_stack(void)
47458 +{
47459 + unsigned long sp = (unsigned long)&sp;
47460 + if (sp < current_thread_info()->lowest_stack &&
47461 + sp > (unsigned long)task_stack_page(current))
47462 + current_thread_info()->lowest_stack = sp;
47463 +}
47464 +EXPORT_SYMBOL(pax_track_stack);
47465 +#endif
47466 +
47467 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
47468 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
47469 +{
47470 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
47471 + dump_stack();
47472 + do_group_exit(SIGKILL);
47473 +}
47474 +EXPORT_SYMBOL(report_size_overflow);
47475 +#endif
47476 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
47477 index 2616d0e..2ffdec9 100644
47478 --- a/fs/ext2/balloc.c
47479 +++ b/fs/ext2/balloc.c
47480 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
47481
47482 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
47483 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
47484 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
47485 + if (free_blocks < root_blocks + 1 &&
47486 !uid_eq(sbi->s_resuid, current_fsuid()) &&
47487 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
47488 - !in_group_p (sbi->s_resgid))) {
47489 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
47490 return 0;
47491 }
47492 return 1;
47493 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
47494 index 22548f5..41521d8 100644
47495 --- a/fs/ext3/balloc.c
47496 +++ b/fs/ext3/balloc.c
47497 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
47498
47499 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
47500 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
47501 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
47502 + if (free_blocks < root_blocks + 1 &&
47503 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
47504 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
47505 - !in_group_p (sbi->s_resgid))) {
47506 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
47507 return 0;
47508 }
47509 return 1;
47510 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
47511 index cf18217..8f6b9c3 100644
47512 --- a/fs/ext4/balloc.c
47513 +++ b/fs/ext4/balloc.c
47514 @@ -498,8 +498,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
47515 /* Hm, nope. Are (enough) root reserved clusters available? */
47516 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
47517 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
47518 - capable(CAP_SYS_RESOURCE) ||
47519 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
47520 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
47521 + capable_nolog(CAP_SYS_RESOURCE)) {
47522
47523 if (free_clusters >= (nclusters + dirty_clusters))
47524 return 1;
47525 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
47526 index 3c20de1..6ff2460 100644
47527 --- a/fs/ext4/ext4.h
47528 +++ b/fs/ext4/ext4.h
47529 @@ -1247,19 +1247,19 @@ struct ext4_sb_info {
47530 unsigned long s_mb_last_start;
47531
47532 /* stats for buddy allocator */
47533 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
47534 - atomic_t s_bal_success; /* we found long enough chunks */
47535 - atomic_t s_bal_allocated; /* in blocks */
47536 - atomic_t s_bal_ex_scanned; /* total extents scanned */
47537 - atomic_t s_bal_goals; /* goal hits */
47538 - atomic_t s_bal_breaks; /* too long searches */
47539 - atomic_t s_bal_2orders; /* 2^order hits */
47540 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
47541 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
47542 + atomic_unchecked_t s_bal_allocated; /* in blocks */
47543 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
47544 + atomic_unchecked_t s_bal_goals; /* goal hits */
47545 + atomic_unchecked_t s_bal_breaks; /* too long searches */
47546 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
47547 spinlock_t s_bal_lock;
47548 unsigned long s_mb_buddies_generated;
47549 unsigned long long s_mb_generation_time;
47550 - atomic_t s_mb_lost_chunks;
47551 - atomic_t s_mb_preallocated;
47552 - atomic_t s_mb_discarded;
47553 + atomic_unchecked_t s_mb_lost_chunks;
47554 + atomic_unchecked_t s_mb_preallocated;
47555 + atomic_unchecked_t s_mb_discarded;
47556 atomic_t s_lock_busy;
47557
47558 /* locality groups */
47559 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
47560 index 526e553..3f2de85 100644
47561 --- a/fs/ext4/mballoc.c
47562 +++ b/fs/ext4/mballoc.c
47563 @@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
47564 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
47565
47566 if (EXT4_SB(sb)->s_mb_stats)
47567 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
47568 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
47569
47570 break;
47571 }
47572 @@ -2044,7 +2044,7 @@ repeat:
47573 ac->ac_status = AC_STATUS_CONTINUE;
47574 ac->ac_flags |= EXT4_MB_HINT_FIRST;
47575 cr = 3;
47576 - atomic_inc(&sbi->s_mb_lost_chunks);
47577 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
47578 goto repeat;
47579 }
47580 }
47581 @@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
47582 if (sbi->s_mb_stats) {
47583 ext4_msg(sb, KERN_INFO,
47584 "mballoc: %u blocks %u reqs (%u success)",
47585 - atomic_read(&sbi->s_bal_allocated),
47586 - atomic_read(&sbi->s_bal_reqs),
47587 - atomic_read(&sbi->s_bal_success));
47588 + atomic_read_unchecked(&sbi->s_bal_allocated),
47589 + atomic_read_unchecked(&sbi->s_bal_reqs),
47590 + atomic_read_unchecked(&sbi->s_bal_success));
47591 ext4_msg(sb, KERN_INFO,
47592 "mballoc: %u extents scanned, %u goal hits, "
47593 "%u 2^N hits, %u breaks, %u lost",
47594 - atomic_read(&sbi->s_bal_ex_scanned),
47595 - atomic_read(&sbi->s_bal_goals),
47596 - atomic_read(&sbi->s_bal_2orders),
47597 - atomic_read(&sbi->s_bal_breaks),
47598 - atomic_read(&sbi->s_mb_lost_chunks));
47599 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
47600 + atomic_read_unchecked(&sbi->s_bal_goals),
47601 + atomic_read_unchecked(&sbi->s_bal_2orders),
47602 + atomic_read_unchecked(&sbi->s_bal_breaks),
47603 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
47604 ext4_msg(sb, KERN_INFO,
47605 "mballoc: %lu generated and it took %Lu",
47606 sbi->s_mb_buddies_generated,
47607 sbi->s_mb_generation_time);
47608 ext4_msg(sb, KERN_INFO,
47609 "mballoc: %u preallocated, %u discarded",
47610 - atomic_read(&sbi->s_mb_preallocated),
47611 - atomic_read(&sbi->s_mb_discarded));
47612 + atomic_read_unchecked(&sbi->s_mb_preallocated),
47613 + atomic_read_unchecked(&sbi->s_mb_discarded));
47614 }
47615
47616 free_percpu(sbi->s_locality_groups);
47617 @@ -3052,16 +3052,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
47618 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
47619
47620 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
47621 - atomic_inc(&sbi->s_bal_reqs);
47622 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
47623 + atomic_inc_unchecked(&sbi->s_bal_reqs);
47624 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
47625 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
47626 - atomic_inc(&sbi->s_bal_success);
47627 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
47628 + atomic_inc_unchecked(&sbi->s_bal_success);
47629 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
47630 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
47631 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
47632 - atomic_inc(&sbi->s_bal_goals);
47633 + atomic_inc_unchecked(&sbi->s_bal_goals);
47634 if (ac->ac_found > sbi->s_mb_max_to_scan)
47635 - atomic_inc(&sbi->s_bal_breaks);
47636 + atomic_inc_unchecked(&sbi->s_bal_breaks);
47637 }
47638
47639 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
47640 @@ -3461,7 +3461,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
47641 trace_ext4_mb_new_inode_pa(ac, pa);
47642
47643 ext4_mb_use_inode_pa(ac, pa);
47644 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
47645 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
47646
47647 ei = EXT4_I(ac->ac_inode);
47648 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
47649 @@ -3521,7 +3521,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
47650 trace_ext4_mb_new_group_pa(ac, pa);
47651
47652 ext4_mb_use_group_pa(ac, pa);
47653 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
47654 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
47655
47656 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
47657 lg = ac->ac_lg;
47658 @@ -3610,7 +3610,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
47659 * from the bitmap and continue.
47660 */
47661 }
47662 - atomic_add(free, &sbi->s_mb_discarded);
47663 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
47664
47665 return err;
47666 }
47667 @@ -3628,7 +3628,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
47668 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
47669 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
47670 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
47671 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
47672 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
47673 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
47674
47675 return 0;
47676 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
47677 index d59b351..775f8c8 100644
47678 --- a/fs/ext4/super.c
47679 +++ b/fs/ext4/super.c
47680 @@ -3212,7 +3212,6 @@ int ext4_calculate_overhead(struct super_block *sb)
47681 ext4_fsblk_t overhead = 0;
47682 char *buf = (char *) get_zeroed_page(GFP_KERNEL);
47683
47684 - memset(buf, 0, PAGE_SIZE);
47685 if (!buf)
47686 return -ENOMEM;
47687
47688 diff --git a/fs/fcntl.c b/fs/fcntl.c
47689 index 71a600a..20d87b1 100644
47690 --- a/fs/fcntl.c
47691 +++ b/fs/fcntl.c
47692 @@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
47693 if (err)
47694 return err;
47695
47696 + if (gr_handle_chroot_fowner(pid, type))
47697 + return -ENOENT;
47698 + if (gr_check_protected_task_fowner(pid, type))
47699 + return -EACCES;
47700 +
47701 f_modown(filp, pid, type, force);
47702 return 0;
47703 }
47704 diff --git a/fs/fhandle.c b/fs/fhandle.c
47705 index f775bfd..629bd4c 100644
47706 --- a/fs/fhandle.c
47707 +++ b/fs/fhandle.c
47708 @@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
47709 } else
47710 retval = 0;
47711 /* copy the mount id */
47712 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
47713 - sizeof(*mnt_id)) ||
47714 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
47715 copy_to_user(ufh, handle,
47716 sizeof(struct file_handle) + handle_bytes))
47717 retval = -EFAULT;
47718 diff --git a/fs/fifo.c b/fs/fifo.c
47719 index cf6f434..3d7942c 100644
47720 --- a/fs/fifo.c
47721 +++ b/fs/fifo.c
47722 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
47723 */
47724 filp->f_op = &read_pipefifo_fops;
47725 pipe->r_counter++;
47726 - if (pipe->readers++ == 0)
47727 + if (atomic_inc_return(&pipe->readers) == 1)
47728 wake_up_partner(inode);
47729
47730 - if (!pipe->writers) {
47731 + if (!atomic_read(&pipe->writers)) {
47732 if ((filp->f_flags & O_NONBLOCK)) {
47733 /* suppress POLLHUP until we have
47734 * seen a writer */
47735 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
47736 * errno=ENXIO when there is no process reading the FIFO.
47737 */
47738 ret = -ENXIO;
47739 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
47740 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
47741 goto err;
47742
47743 filp->f_op = &write_pipefifo_fops;
47744 pipe->w_counter++;
47745 - if (!pipe->writers++)
47746 + if (atomic_inc_return(&pipe->writers) == 1)
47747 wake_up_partner(inode);
47748
47749 - if (!pipe->readers) {
47750 + if (!atomic_read(&pipe->readers)) {
47751 if (wait_for_partner(inode, &pipe->r_counter))
47752 goto err_wr;
47753 }
47754 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
47755 */
47756 filp->f_op = &rdwr_pipefifo_fops;
47757
47758 - pipe->readers++;
47759 - pipe->writers++;
47760 + atomic_inc(&pipe->readers);
47761 + atomic_inc(&pipe->writers);
47762 pipe->r_counter++;
47763 pipe->w_counter++;
47764 - if (pipe->readers == 1 || pipe->writers == 1)
47765 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
47766 wake_up_partner(inode);
47767 break;
47768
47769 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
47770 return 0;
47771
47772 err_rd:
47773 - if (!--pipe->readers)
47774 + if (atomic_dec_and_test(&pipe->readers))
47775 wake_up_interruptible(&pipe->wait);
47776 ret = -ERESTARTSYS;
47777 goto err;
47778
47779 err_wr:
47780 - if (!--pipe->writers)
47781 + if (atomic_dec_and_test(&pipe->writers))
47782 wake_up_interruptible(&pipe->wait);
47783 ret = -ERESTARTSYS;
47784 goto err;
47785
47786 err:
47787 - if (!pipe->readers && !pipe->writers)
47788 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
47789 free_pipe_info(inode);
47790
47791 err_nocleanup:
47792 diff --git a/fs/file.c b/fs/file.c
47793 index eff2316..8c8930c 100644
47794 --- a/fs/file.c
47795 +++ b/fs/file.c
47796 @@ -16,6 +16,7 @@
47797 #include <linux/slab.h>
47798 #include <linux/vmalloc.h>
47799 #include <linux/file.h>
47800 +#include <linux/security.h>
47801 #include <linux/fdtable.h>
47802 #include <linux/bitops.h>
47803 #include <linux/interrupt.h>
47804 @@ -898,6 +899,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
47805 if (!file)
47806 return __close_fd(files, fd);
47807
47808 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
47809 if (fd >= rlimit(RLIMIT_NOFILE))
47810 return -EBADF;
47811
47812 @@ -924,6 +926,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
47813 if (unlikely(oldfd == newfd))
47814 return -EINVAL;
47815
47816 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
47817 if (newfd >= rlimit(RLIMIT_NOFILE))
47818 return -EBADF;
47819
47820 @@ -979,6 +982,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
47821 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
47822 {
47823 int err;
47824 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
47825 if (from >= rlimit(RLIMIT_NOFILE))
47826 return -EINVAL;
47827 err = alloc_fd(from, flags);
47828 diff --git a/fs/filesystems.c b/fs/filesystems.c
47829 index da165f6..3671bdb 100644
47830 --- a/fs/filesystems.c
47831 +++ b/fs/filesystems.c
47832 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
47833 int len = dot ? dot - name : strlen(name);
47834
47835 fs = __get_fs_type(name, len);
47836 +
47837 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
47838 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
47839 +#else
47840 if (!fs && (request_module("%.*s", len, name) == 0))
47841 +#endif
47842 fs = __get_fs_type(name, len);
47843
47844 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
47845 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
47846 index 5df4775..9d9336f 100644
47847 --- a/fs/fs_struct.c
47848 +++ b/fs/fs_struct.c
47849 @@ -4,6 +4,7 @@
47850 #include <linux/path.h>
47851 #include <linux/slab.h>
47852 #include <linux/fs_struct.h>
47853 +#include <linux/grsecurity.h>
47854 #include "internal.h"
47855
47856 /*
47857 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
47858 write_seqcount_begin(&fs->seq);
47859 old_root = fs->root;
47860 fs->root = *path;
47861 + gr_set_chroot_entries(current, path);
47862 write_seqcount_end(&fs->seq);
47863 spin_unlock(&fs->lock);
47864 if (old_root.dentry)
47865 @@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
47866 return 1;
47867 }
47868
47869 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
47870 +{
47871 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
47872 + return 0;
47873 + *p = *new;
47874 +
47875 + /* This function is only called from pivot_root(). Leave our
47876 + gr_chroot_dentry and is_chrooted flags as-is, so that a
47877 + pivoted root isn't treated as a chroot
47878 + */
47879 + //gr_set_chroot_entries(task, new);
47880 +
47881 + return 1;
47882 +}
47883 +
47884 void chroot_fs_refs(struct path *old_root, struct path *new_root)
47885 {
47886 struct task_struct *g, *p;
47887 @@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
47888 int hits = 0;
47889 spin_lock(&fs->lock);
47890 write_seqcount_begin(&fs->seq);
47891 - hits += replace_path(&fs->root, old_root, new_root);
47892 + hits += replace_root_path(p, &fs->root, old_root, new_root);
47893 hits += replace_path(&fs->pwd, old_root, new_root);
47894 write_seqcount_end(&fs->seq);
47895 while (hits--) {
47896 @@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
47897 task_lock(tsk);
47898 spin_lock(&fs->lock);
47899 tsk->fs = NULL;
47900 - kill = !--fs->users;
47901 + gr_clear_chroot_entries(tsk);
47902 + kill = !atomic_dec_return(&fs->users);
47903 spin_unlock(&fs->lock);
47904 task_unlock(tsk);
47905 if (kill)
47906 @@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
47907 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
47908 /* We don't need to lock fs - think why ;-) */
47909 if (fs) {
47910 - fs->users = 1;
47911 + atomic_set(&fs->users, 1);
47912 fs->in_exec = 0;
47913 spin_lock_init(&fs->lock);
47914 seqcount_init(&fs->seq);
47915 @@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
47916 spin_lock(&old->lock);
47917 fs->root = old->root;
47918 path_get(&fs->root);
47919 + /* instead of calling gr_set_chroot_entries here,
47920 + we call it from every caller of this function
47921 + */
47922 fs->pwd = old->pwd;
47923 path_get(&fs->pwd);
47924 spin_unlock(&old->lock);
47925 @@ -139,8 +160,9 @@ int unshare_fs_struct(void)
47926
47927 task_lock(current);
47928 spin_lock(&fs->lock);
47929 - kill = !--fs->users;
47930 + kill = !atomic_dec_return(&fs->users);
47931 current->fs = new_fs;
47932 + gr_set_chroot_entries(current, &new_fs->root);
47933 spin_unlock(&fs->lock);
47934 task_unlock(current);
47935
47936 @@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
47937
47938 int current_umask(void)
47939 {
47940 - return current->fs->umask;
47941 + return current->fs->umask | gr_acl_umask();
47942 }
47943 EXPORT_SYMBOL(current_umask);
47944
47945 /* to be mentioned only in INIT_TASK */
47946 struct fs_struct init_fs = {
47947 - .users = 1,
47948 + .users = ATOMIC_INIT(1),
47949 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
47950 .seq = SEQCNT_ZERO,
47951 .umask = 0022,
47952 @@ -175,12 +197,13 @@ void daemonize_fs_struct(void)
47953 task_lock(current);
47954
47955 spin_lock(&init_fs.lock);
47956 - init_fs.users++;
47957 + atomic_inc(&init_fs.users);
47958 spin_unlock(&init_fs.lock);
47959
47960 spin_lock(&fs->lock);
47961 current->fs = &init_fs;
47962 - kill = !--fs->users;
47963 + gr_set_chroot_entries(current, &current->fs->root);
47964 + kill = !atomic_dec_return(&fs->users);
47965 spin_unlock(&fs->lock);
47966
47967 task_unlock(current);
47968 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
47969 index 9905350..02eaec4 100644
47970 --- a/fs/fscache/cookie.c
47971 +++ b/fs/fscache/cookie.c
47972 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
47973 parent ? (char *) parent->def->name : "<no-parent>",
47974 def->name, netfs_data);
47975
47976 - fscache_stat(&fscache_n_acquires);
47977 + fscache_stat_unchecked(&fscache_n_acquires);
47978
47979 /* if there's no parent cookie, then we don't create one here either */
47980 if (!parent) {
47981 - fscache_stat(&fscache_n_acquires_null);
47982 + fscache_stat_unchecked(&fscache_n_acquires_null);
47983 _leave(" [no parent]");
47984 return NULL;
47985 }
47986 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
47987 /* allocate and initialise a cookie */
47988 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
47989 if (!cookie) {
47990 - fscache_stat(&fscache_n_acquires_oom);
47991 + fscache_stat_unchecked(&fscache_n_acquires_oom);
47992 _leave(" [ENOMEM]");
47993 return NULL;
47994 }
47995 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
47996
47997 switch (cookie->def->type) {
47998 case FSCACHE_COOKIE_TYPE_INDEX:
47999 - fscache_stat(&fscache_n_cookie_index);
48000 + fscache_stat_unchecked(&fscache_n_cookie_index);
48001 break;
48002 case FSCACHE_COOKIE_TYPE_DATAFILE:
48003 - fscache_stat(&fscache_n_cookie_data);
48004 + fscache_stat_unchecked(&fscache_n_cookie_data);
48005 break;
48006 default:
48007 - fscache_stat(&fscache_n_cookie_special);
48008 + fscache_stat_unchecked(&fscache_n_cookie_special);
48009 break;
48010 }
48011
48012 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
48013 if (fscache_acquire_non_index_cookie(cookie) < 0) {
48014 atomic_dec(&parent->n_children);
48015 __fscache_cookie_put(cookie);
48016 - fscache_stat(&fscache_n_acquires_nobufs);
48017 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
48018 _leave(" = NULL");
48019 return NULL;
48020 }
48021 }
48022
48023 - fscache_stat(&fscache_n_acquires_ok);
48024 + fscache_stat_unchecked(&fscache_n_acquires_ok);
48025 _leave(" = %p", cookie);
48026 return cookie;
48027 }
48028 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
48029 cache = fscache_select_cache_for_object(cookie->parent);
48030 if (!cache) {
48031 up_read(&fscache_addremove_sem);
48032 - fscache_stat(&fscache_n_acquires_no_cache);
48033 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
48034 _leave(" = -ENOMEDIUM [no cache]");
48035 return -ENOMEDIUM;
48036 }
48037 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
48038 object = cache->ops->alloc_object(cache, cookie);
48039 fscache_stat_d(&fscache_n_cop_alloc_object);
48040 if (IS_ERR(object)) {
48041 - fscache_stat(&fscache_n_object_no_alloc);
48042 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
48043 ret = PTR_ERR(object);
48044 goto error;
48045 }
48046
48047 - fscache_stat(&fscache_n_object_alloc);
48048 + fscache_stat_unchecked(&fscache_n_object_alloc);
48049
48050 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
48051
48052 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
48053 struct fscache_object *object;
48054 struct hlist_node *_p;
48055
48056 - fscache_stat(&fscache_n_updates);
48057 + fscache_stat_unchecked(&fscache_n_updates);
48058
48059 if (!cookie) {
48060 - fscache_stat(&fscache_n_updates_null);
48061 + fscache_stat_unchecked(&fscache_n_updates_null);
48062 _leave(" [no cookie]");
48063 return;
48064 }
48065 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
48066 struct fscache_object *object;
48067 unsigned long event;
48068
48069 - fscache_stat(&fscache_n_relinquishes);
48070 + fscache_stat_unchecked(&fscache_n_relinquishes);
48071 if (retire)
48072 - fscache_stat(&fscache_n_relinquishes_retire);
48073 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
48074
48075 if (!cookie) {
48076 - fscache_stat(&fscache_n_relinquishes_null);
48077 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
48078 _leave(" [no cookie]");
48079 return;
48080 }
48081 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
48082
48083 /* wait for the cookie to finish being instantiated (or to fail) */
48084 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
48085 - fscache_stat(&fscache_n_relinquishes_waitcrt);
48086 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
48087 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
48088 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
48089 }
48090 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
48091 index f6aad48..88dcf26 100644
48092 --- a/fs/fscache/internal.h
48093 +++ b/fs/fscache/internal.h
48094 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
48095 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
48096 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
48097
48098 -extern atomic_t fscache_n_op_pend;
48099 -extern atomic_t fscache_n_op_run;
48100 -extern atomic_t fscache_n_op_enqueue;
48101 -extern atomic_t fscache_n_op_deferred_release;
48102 -extern atomic_t fscache_n_op_release;
48103 -extern atomic_t fscache_n_op_gc;
48104 -extern atomic_t fscache_n_op_cancelled;
48105 -extern atomic_t fscache_n_op_rejected;
48106 +extern atomic_unchecked_t fscache_n_op_pend;
48107 +extern atomic_unchecked_t fscache_n_op_run;
48108 +extern atomic_unchecked_t fscache_n_op_enqueue;
48109 +extern atomic_unchecked_t fscache_n_op_deferred_release;
48110 +extern atomic_unchecked_t fscache_n_op_release;
48111 +extern atomic_unchecked_t fscache_n_op_gc;
48112 +extern atomic_unchecked_t fscache_n_op_cancelled;
48113 +extern atomic_unchecked_t fscache_n_op_rejected;
48114
48115 -extern atomic_t fscache_n_attr_changed;
48116 -extern atomic_t fscache_n_attr_changed_ok;
48117 -extern atomic_t fscache_n_attr_changed_nobufs;
48118 -extern atomic_t fscache_n_attr_changed_nomem;
48119 -extern atomic_t fscache_n_attr_changed_calls;
48120 +extern atomic_unchecked_t fscache_n_attr_changed;
48121 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
48122 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
48123 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
48124 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
48125
48126 -extern atomic_t fscache_n_allocs;
48127 -extern atomic_t fscache_n_allocs_ok;
48128 -extern atomic_t fscache_n_allocs_wait;
48129 -extern atomic_t fscache_n_allocs_nobufs;
48130 -extern atomic_t fscache_n_allocs_intr;
48131 -extern atomic_t fscache_n_allocs_object_dead;
48132 -extern atomic_t fscache_n_alloc_ops;
48133 -extern atomic_t fscache_n_alloc_op_waits;
48134 +extern atomic_unchecked_t fscache_n_allocs;
48135 +extern atomic_unchecked_t fscache_n_allocs_ok;
48136 +extern atomic_unchecked_t fscache_n_allocs_wait;
48137 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
48138 +extern atomic_unchecked_t fscache_n_allocs_intr;
48139 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
48140 +extern atomic_unchecked_t fscache_n_alloc_ops;
48141 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
48142
48143 -extern atomic_t fscache_n_retrievals;
48144 -extern atomic_t fscache_n_retrievals_ok;
48145 -extern atomic_t fscache_n_retrievals_wait;
48146 -extern atomic_t fscache_n_retrievals_nodata;
48147 -extern atomic_t fscache_n_retrievals_nobufs;
48148 -extern atomic_t fscache_n_retrievals_intr;
48149 -extern atomic_t fscache_n_retrievals_nomem;
48150 -extern atomic_t fscache_n_retrievals_object_dead;
48151 -extern atomic_t fscache_n_retrieval_ops;
48152 -extern atomic_t fscache_n_retrieval_op_waits;
48153 +extern atomic_unchecked_t fscache_n_retrievals;
48154 +extern atomic_unchecked_t fscache_n_retrievals_ok;
48155 +extern atomic_unchecked_t fscache_n_retrievals_wait;
48156 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
48157 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
48158 +extern atomic_unchecked_t fscache_n_retrievals_intr;
48159 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
48160 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
48161 +extern atomic_unchecked_t fscache_n_retrieval_ops;
48162 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
48163
48164 -extern atomic_t fscache_n_stores;
48165 -extern atomic_t fscache_n_stores_ok;
48166 -extern atomic_t fscache_n_stores_again;
48167 -extern atomic_t fscache_n_stores_nobufs;
48168 -extern atomic_t fscache_n_stores_oom;
48169 -extern atomic_t fscache_n_store_ops;
48170 -extern atomic_t fscache_n_store_calls;
48171 -extern atomic_t fscache_n_store_pages;
48172 -extern atomic_t fscache_n_store_radix_deletes;
48173 -extern atomic_t fscache_n_store_pages_over_limit;
48174 +extern atomic_unchecked_t fscache_n_stores;
48175 +extern atomic_unchecked_t fscache_n_stores_ok;
48176 +extern atomic_unchecked_t fscache_n_stores_again;
48177 +extern atomic_unchecked_t fscache_n_stores_nobufs;
48178 +extern atomic_unchecked_t fscache_n_stores_oom;
48179 +extern atomic_unchecked_t fscache_n_store_ops;
48180 +extern atomic_unchecked_t fscache_n_store_calls;
48181 +extern atomic_unchecked_t fscache_n_store_pages;
48182 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
48183 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
48184
48185 -extern atomic_t fscache_n_store_vmscan_not_storing;
48186 -extern atomic_t fscache_n_store_vmscan_gone;
48187 -extern atomic_t fscache_n_store_vmscan_busy;
48188 -extern atomic_t fscache_n_store_vmscan_cancelled;
48189 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
48190 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
48191 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
48192 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
48193
48194 -extern atomic_t fscache_n_marks;
48195 -extern atomic_t fscache_n_uncaches;
48196 +extern atomic_unchecked_t fscache_n_marks;
48197 +extern atomic_unchecked_t fscache_n_uncaches;
48198
48199 -extern atomic_t fscache_n_acquires;
48200 -extern atomic_t fscache_n_acquires_null;
48201 -extern atomic_t fscache_n_acquires_no_cache;
48202 -extern atomic_t fscache_n_acquires_ok;
48203 -extern atomic_t fscache_n_acquires_nobufs;
48204 -extern atomic_t fscache_n_acquires_oom;
48205 +extern atomic_unchecked_t fscache_n_acquires;
48206 +extern atomic_unchecked_t fscache_n_acquires_null;
48207 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
48208 +extern atomic_unchecked_t fscache_n_acquires_ok;
48209 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
48210 +extern atomic_unchecked_t fscache_n_acquires_oom;
48211
48212 -extern atomic_t fscache_n_updates;
48213 -extern atomic_t fscache_n_updates_null;
48214 -extern atomic_t fscache_n_updates_run;
48215 +extern atomic_unchecked_t fscache_n_updates;
48216 +extern atomic_unchecked_t fscache_n_updates_null;
48217 +extern atomic_unchecked_t fscache_n_updates_run;
48218
48219 -extern atomic_t fscache_n_relinquishes;
48220 -extern atomic_t fscache_n_relinquishes_null;
48221 -extern atomic_t fscache_n_relinquishes_waitcrt;
48222 -extern atomic_t fscache_n_relinquishes_retire;
48223 +extern atomic_unchecked_t fscache_n_relinquishes;
48224 +extern atomic_unchecked_t fscache_n_relinquishes_null;
48225 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
48226 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
48227
48228 -extern atomic_t fscache_n_cookie_index;
48229 -extern atomic_t fscache_n_cookie_data;
48230 -extern atomic_t fscache_n_cookie_special;
48231 +extern atomic_unchecked_t fscache_n_cookie_index;
48232 +extern atomic_unchecked_t fscache_n_cookie_data;
48233 +extern atomic_unchecked_t fscache_n_cookie_special;
48234
48235 -extern atomic_t fscache_n_object_alloc;
48236 -extern atomic_t fscache_n_object_no_alloc;
48237 -extern atomic_t fscache_n_object_lookups;
48238 -extern atomic_t fscache_n_object_lookups_negative;
48239 -extern atomic_t fscache_n_object_lookups_positive;
48240 -extern atomic_t fscache_n_object_lookups_timed_out;
48241 -extern atomic_t fscache_n_object_created;
48242 -extern atomic_t fscache_n_object_avail;
48243 -extern atomic_t fscache_n_object_dead;
48244 +extern atomic_unchecked_t fscache_n_object_alloc;
48245 +extern atomic_unchecked_t fscache_n_object_no_alloc;
48246 +extern atomic_unchecked_t fscache_n_object_lookups;
48247 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
48248 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
48249 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
48250 +extern atomic_unchecked_t fscache_n_object_created;
48251 +extern atomic_unchecked_t fscache_n_object_avail;
48252 +extern atomic_unchecked_t fscache_n_object_dead;
48253
48254 -extern atomic_t fscache_n_checkaux_none;
48255 -extern atomic_t fscache_n_checkaux_okay;
48256 -extern atomic_t fscache_n_checkaux_update;
48257 -extern atomic_t fscache_n_checkaux_obsolete;
48258 +extern atomic_unchecked_t fscache_n_checkaux_none;
48259 +extern atomic_unchecked_t fscache_n_checkaux_okay;
48260 +extern atomic_unchecked_t fscache_n_checkaux_update;
48261 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
48262
48263 extern atomic_t fscache_n_cop_alloc_object;
48264 extern atomic_t fscache_n_cop_lookup_object;
48265 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
48266 atomic_inc(stat);
48267 }
48268
48269 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
48270 +{
48271 + atomic_inc_unchecked(stat);
48272 +}
48273 +
48274 static inline void fscache_stat_d(atomic_t *stat)
48275 {
48276 atomic_dec(stat);
48277 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
48278
48279 #define __fscache_stat(stat) (NULL)
48280 #define fscache_stat(stat) do {} while (0)
48281 +#define fscache_stat_unchecked(stat) do {} while (0)
48282 #define fscache_stat_d(stat) do {} while (0)
48283 #endif
48284
48285 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
48286 index b6b897c..0ffff9c 100644
48287 --- a/fs/fscache/object.c
48288 +++ b/fs/fscache/object.c
48289 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48290 /* update the object metadata on disk */
48291 case FSCACHE_OBJECT_UPDATING:
48292 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
48293 - fscache_stat(&fscache_n_updates_run);
48294 + fscache_stat_unchecked(&fscache_n_updates_run);
48295 fscache_stat(&fscache_n_cop_update_object);
48296 object->cache->ops->update_object(object);
48297 fscache_stat_d(&fscache_n_cop_update_object);
48298 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48299 spin_lock(&object->lock);
48300 object->state = FSCACHE_OBJECT_DEAD;
48301 spin_unlock(&object->lock);
48302 - fscache_stat(&fscache_n_object_dead);
48303 + fscache_stat_unchecked(&fscache_n_object_dead);
48304 goto terminal_transit;
48305
48306 /* handle the parent cache of this object being withdrawn from
48307 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48308 spin_lock(&object->lock);
48309 object->state = FSCACHE_OBJECT_DEAD;
48310 spin_unlock(&object->lock);
48311 - fscache_stat(&fscache_n_object_dead);
48312 + fscache_stat_unchecked(&fscache_n_object_dead);
48313 goto terminal_transit;
48314
48315 /* complain about the object being woken up once it is
48316 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
48317 parent->cookie->def->name, cookie->def->name,
48318 object->cache->tag->name);
48319
48320 - fscache_stat(&fscache_n_object_lookups);
48321 + fscache_stat_unchecked(&fscache_n_object_lookups);
48322 fscache_stat(&fscache_n_cop_lookup_object);
48323 ret = object->cache->ops->lookup_object(object);
48324 fscache_stat_d(&fscache_n_cop_lookup_object);
48325 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
48326 if (ret == -ETIMEDOUT) {
48327 /* probably stuck behind another object, so move this one to
48328 * the back of the queue */
48329 - fscache_stat(&fscache_n_object_lookups_timed_out);
48330 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
48331 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
48332 }
48333
48334 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
48335
48336 spin_lock(&object->lock);
48337 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
48338 - fscache_stat(&fscache_n_object_lookups_negative);
48339 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
48340
48341 /* transit here to allow write requests to begin stacking up
48342 * and read requests to begin returning ENODATA */
48343 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
48344 * result, in which case there may be data available */
48345 spin_lock(&object->lock);
48346 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
48347 - fscache_stat(&fscache_n_object_lookups_positive);
48348 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
48349
48350 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
48351
48352 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
48353 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
48354 } else {
48355 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
48356 - fscache_stat(&fscache_n_object_created);
48357 + fscache_stat_unchecked(&fscache_n_object_created);
48358
48359 object->state = FSCACHE_OBJECT_AVAILABLE;
48360 spin_unlock(&object->lock);
48361 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
48362 fscache_enqueue_dependents(object);
48363
48364 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
48365 - fscache_stat(&fscache_n_object_avail);
48366 + fscache_stat_unchecked(&fscache_n_object_avail);
48367
48368 _leave("");
48369 }
48370 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
48371 enum fscache_checkaux result;
48372
48373 if (!object->cookie->def->check_aux) {
48374 - fscache_stat(&fscache_n_checkaux_none);
48375 + fscache_stat_unchecked(&fscache_n_checkaux_none);
48376 return FSCACHE_CHECKAUX_OKAY;
48377 }
48378
48379 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
48380 switch (result) {
48381 /* entry okay as is */
48382 case FSCACHE_CHECKAUX_OKAY:
48383 - fscache_stat(&fscache_n_checkaux_okay);
48384 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
48385 break;
48386
48387 /* entry requires update */
48388 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
48389 - fscache_stat(&fscache_n_checkaux_update);
48390 + fscache_stat_unchecked(&fscache_n_checkaux_update);
48391 break;
48392
48393 /* entry requires deletion */
48394 case FSCACHE_CHECKAUX_OBSOLETE:
48395 - fscache_stat(&fscache_n_checkaux_obsolete);
48396 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
48397 break;
48398
48399 default:
48400 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
48401 index 30afdfa..2256596 100644
48402 --- a/fs/fscache/operation.c
48403 +++ b/fs/fscache/operation.c
48404 @@ -17,7 +17,7 @@
48405 #include <linux/slab.h>
48406 #include "internal.h"
48407
48408 -atomic_t fscache_op_debug_id;
48409 +atomic_unchecked_t fscache_op_debug_id;
48410 EXPORT_SYMBOL(fscache_op_debug_id);
48411
48412 /**
48413 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
48414 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
48415 ASSERTCMP(atomic_read(&op->usage), >, 0);
48416
48417 - fscache_stat(&fscache_n_op_enqueue);
48418 + fscache_stat_unchecked(&fscache_n_op_enqueue);
48419 switch (op->flags & FSCACHE_OP_TYPE) {
48420 case FSCACHE_OP_ASYNC:
48421 _debug("queue async");
48422 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
48423 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
48424 if (op->processor)
48425 fscache_enqueue_operation(op);
48426 - fscache_stat(&fscache_n_op_run);
48427 + fscache_stat_unchecked(&fscache_n_op_run);
48428 }
48429
48430 /*
48431 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
48432 if (object->n_ops > 1) {
48433 atomic_inc(&op->usage);
48434 list_add_tail(&op->pend_link, &object->pending_ops);
48435 - fscache_stat(&fscache_n_op_pend);
48436 + fscache_stat_unchecked(&fscache_n_op_pend);
48437 } else if (!list_empty(&object->pending_ops)) {
48438 atomic_inc(&op->usage);
48439 list_add_tail(&op->pend_link, &object->pending_ops);
48440 - fscache_stat(&fscache_n_op_pend);
48441 + fscache_stat_unchecked(&fscache_n_op_pend);
48442 fscache_start_operations(object);
48443 } else {
48444 ASSERTCMP(object->n_in_progress, ==, 0);
48445 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
48446 object->n_exclusive++; /* reads and writes must wait */
48447 atomic_inc(&op->usage);
48448 list_add_tail(&op->pend_link, &object->pending_ops);
48449 - fscache_stat(&fscache_n_op_pend);
48450 + fscache_stat_unchecked(&fscache_n_op_pend);
48451 ret = 0;
48452 } else {
48453 /* not allowed to submit ops in any other state */
48454 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
48455 if (object->n_exclusive > 0) {
48456 atomic_inc(&op->usage);
48457 list_add_tail(&op->pend_link, &object->pending_ops);
48458 - fscache_stat(&fscache_n_op_pend);
48459 + fscache_stat_unchecked(&fscache_n_op_pend);
48460 } else if (!list_empty(&object->pending_ops)) {
48461 atomic_inc(&op->usage);
48462 list_add_tail(&op->pend_link, &object->pending_ops);
48463 - fscache_stat(&fscache_n_op_pend);
48464 + fscache_stat_unchecked(&fscache_n_op_pend);
48465 fscache_start_operations(object);
48466 } else {
48467 ASSERTCMP(object->n_exclusive, ==, 0);
48468 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
48469 object->n_ops++;
48470 atomic_inc(&op->usage);
48471 list_add_tail(&op->pend_link, &object->pending_ops);
48472 - fscache_stat(&fscache_n_op_pend);
48473 + fscache_stat_unchecked(&fscache_n_op_pend);
48474 ret = 0;
48475 } else if (object->state == FSCACHE_OBJECT_DYING ||
48476 object->state == FSCACHE_OBJECT_LC_DYING ||
48477 object->state == FSCACHE_OBJECT_WITHDRAWING) {
48478 - fscache_stat(&fscache_n_op_rejected);
48479 + fscache_stat_unchecked(&fscache_n_op_rejected);
48480 ret = -ENOBUFS;
48481 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
48482 fscache_report_unexpected_submission(object, op, ostate);
48483 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
48484
48485 ret = -EBUSY;
48486 if (!list_empty(&op->pend_link)) {
48487 - fscache_stat(&fscache_n_op_cancelled);
48488 + fscache_stat_unchecked(&fscache_n_op_cancelled);
48489 list_del_init(&op->pend_link);
48490 object->n_ops--;
48491 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
48492 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
48493 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
48494 BUG();
48495
48496 - fscache_stat(&fscache_n_op_release);
48497 + fscache_stat_unchecked(&fscache_n_op_release);
48498
48499 if (op->release) {
48500 op->release(op);
48501 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
48502 * lock, and defer it otherwise */
48503 if (!spin_trylock(&object->lock)) {
48504 _debug("defer put");
48505 - fscache_stat(&fscache_n_op_deferred_release);
48506 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
48507
48508 cache = object->cache;
48509 spin_lock(&cache->op_gc_list_lock);
48510 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
48511
48512 _debug("GC DEFERRED REL OBJ%x OP%x",
48513 object->debug_id, op->debug_id);
48514 - fscache_stat(&fscache_n_op_gc);
48515 + fscache_stat_unchecked(&fscache_n_op_gc);
48516
48517 ASSERTCMP(atomic_read(&op->usage), ==, 0);
48518
48519 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
48520 index 3f7a59b..cf196cc 100644
48521 --- a/fs/fscache/page.c
48522 +++ b/fs/fscache/page.c
48523 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
48524 val = radix_tree_lookup(&cookie->stores, page->index);
48525 if (!val) {
48526 rcu_read_unlock();
48527 - fscache_stat(&fscache_n_store_vmscan_not_storing);
48528 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
48529 __fscache_uncache_page(cookie, page);
48530 return true;
48531 }
48532 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
48533 spin_unlock(&cookie->stores_lock);
48534
48535 if (xpage) {
48536 - fscache_stat(&fscache_n_store_vmscan_cancelled);
48537 - fscache_stat(&fscache_n_store_radix_deletes);
48538 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
48539 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
48540 ASSERTCMP(xpage, ==, page);
48541 } else {
48542 - fscache_stat(&fscache_n_store_vmscan_gone);
48543 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
48544 }
48545
48546 wake_up_bit(&cookie->flags, 0);
48547 @@ -107,7 +107,7 @@ page_busy:
48548 /* we might want to wait here, but that could deadlock the allocator as
48549 * the work threads writing to the cache may all end up sleeping
48550 * on memory allocation */
48551 - fscache_stat(&fscache_n_store_vmscan_busy);
48552 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
48553 return false;
48554 }
48555 EXPORT_SYMBOL(__fscache_maybe_release_page);
48556 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
48557 FSCACHE_COOKIE_STORING_TAG);
48558 if (!radix_tree_tag_get(&cookie->stores, page->index,
48559 FSCACHE_COOKIE_PENDING_TAG)) {
48560 - fscache_stat(&fscache_n_store_radix_deletes);
48561 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
48562 xpage = radix_tree_delete(&cookie->stores, page->index);
48563 }
48564 spin_unlock(&cookie->stores_lock);
48565 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
48566
48567 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
48568
48569 - fscache_stat(&fscache_n_attr_changed_calls);
48570 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
48571
48572 if (fscache_object_is_active(object)) {
48573 fscache_stat(&fscache_n_cop_attr_changed);
48574 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
48575
48576 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
48577
48578 - fscache_stat(&fscache_n_attr_changed);
48579 + fscache_stat_unchecked(&fscache_n_attr_changed);
48580
48581 op = kzalloc(sizeof(*op), GFP_KERNEL);
48582 if (!op) {
48583 - fscache_stat(&fscache_n_attr_changed_nomem);
48584 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
48585 _leave(" = -ENOMEM");
48586 return -ENOMEM;
48587 }
48588 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
48589 if (fscache_submit_exclusive_op(object, op) < 0)
48590 goto nobufs;
48591 spin_unlock(&cookie->lock);
48592 - fscache_stat(&fscache_n_attr_changed_ok);
48593 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
48594 fscache_put_operation(op);
48595 _leave(" = 0");
48596 return 0;
48597 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
48598 nobufs:
48599 spin_unlock(&cookie->lock);
48600 kfree(op);
48601 - fscache_stat(&fscache_n_attr_changed_nobufs);
48602 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
48603 _leave(" = %d", -ENOBUFS);
48604 return -ENOBUFS;
48605 }
48606 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
48607 /* allocate a retrieval operation and attempt to submit it */
48608 op = kzalloc(sizeof(*op), GFP_NOIO);
48609 if (!op) {
48610 - fscache_stat(&fscache_n_retrievals_nomem);
48611 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
48612 return NULL;
48613 }
48614
48615 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
48616 return 0;
48617 }
48618
48619 - fscache_stat(&fscache_n_retrievals_wait);
48620 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
48621
48622 jif = jiffies;
48623 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
48624 fscache_wait_bit_interruptible,
48625 TASK_INTERRUPTIBLE) != 0) {
48626 - fscache_stat(&fscache_n_retrievals_intr);
48627 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
48628 _leave(" = -ERESTARTSYS");
48629 return -ERESTARTSYS;
48630 }
48631 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
48632 */
48633 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
48634 struct fscache_retrieval *op,
48635 - atomic_t *stat_op_waits,
48636 - atomic_t *stat_object_dead)
48637 + atomic_unchecked_t *stat_op_waits,
48638 + atomic_unchecked_t *stat_object_dead)
48639 {
48640 int ret;
48641
48642 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
48643 goto check_if_dead;
48644
48645 _debug(">>> WT");
48646 - fscache_stat(stat_op_waits);
48647 + fscache_stat_unchecked(stat_op_waits);
48648 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
48649 fscache_wait_bit_interruptible,
48650 TASK_INTERRUPTIBLE) < 0) {
48651 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
48652
48653 check_if_dead:
48654 if (unlikely(fscache_object_is_dead(object))) {
48655 - fscache_stat(stat_object_dead);
48656 + fscache_stat_unchecked(stat_object_dead);
48657 return -ENOBUFS;
48658 }
48659 return 0;
48660 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
48661
48662 _enter("%p,%p,,,", cookie, page);
48663
48664 - fscache_stat(&fscache_n_retrievals);
48665 + fscache_stat_unchecked(&fscache_n_retrievals);
48666
48667 if (hlist_empty(&cookie->backing_objects))
48668 goto nobufs;
48669 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
48670 goto nobufs_unlock;
48671 spin_unlock(&cookie->lock);
48672
48673 - fscache_stat(&fscache_n_retrieval_ops);
48674 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
48675
48676 /* pin the netfs read context in case we need to do the actual netfs
48677 * read because we've encountered a cache read failure */
48678 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
48679
48680 error:
48681 if (ret == -ENOMEM)
48682 - fscache_stat(&fscache_n_retrievals_nomem);
48683 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
48684 else if (ret == -ERESTARTSYS)
48685 - fscache_stat(&fscache_n_retrievals_intr);
48686 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
48687 else if (ret == -ENODATA)
48688 - fscache_stat(&fscache_n_retrievals_nodata);
48689 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
48690 else if (ret < 0)
48691 - fscache_stat(&fscache_n_retrievals_nobufs);
48692 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48693 else
48694 - fscache_stat(&fscache_n_retrievals_ok);
48695 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
48696
48697 fscache_put_retrieval(op);
48698 _leave(" = %d", ret);
48699 @@ -429,7 +429,7 @@ nobufs_unlock:
48700 spin_unlock(&cookie->lock);
48701 kfree(op);
48702 nobufs:
48703 - fscache_stat(&fscache_n_retrievals_nobufs);
48704 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48705 _leave(" = -ENOBUFS");
48706 return -ENOBUFS;
48707 }
48708 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
48709
48710 _enter("%p,,%d,,,", cookie, *nr_pages);
48711
48712 - fscache_stat(&fscache_n_retrievals);
48713 + fscache_stat_unchecked(&fscache_n_retrievals);
48714
48715 if (hlist_empty(&cookie->backing_objects))
48716 goto nobufs;
48717 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
48718 goto nobufs_unlock;
48719 spin_unlock(&cookie->lock);
48720
48721 - fscache_stat(&fscache_n_retrieval_ops);
48722 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
48723
48724 /* pin the netfs read context in case we need to do the actual netfs
48725 * read because we've encountered a cache read failure */
48726 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
48727
48728 error:
48729 if (ret == -ENOMEM)
48730 - fscache_stat(&fscache_n_retrievals_nomem);
48731 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
48732 else if (ret == -ERESTARTSYS)
48733 - fscache_stat(&fscache_n_retrievals_intr);
48734 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
48735 else if (ret == -ENODATA)
48736 - fscache_stat(&fscache_n_retrievals_nodata);
48737 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
48738 else if (ret < 0)
48739 - fscache_stat(&fscache_n_retrievals_nobufs);
48740 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48741 else
48742 - fscache_stat(&fscache_n_retrievals_ok);
48743 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
48744
48745 fscache_put_retrieval(op);
48746 _leave(" = %d", ret);
48747 @@ -545,7 +545,7 @@ nobufs_unlock:
48748 spin_unlock(&cookie->lock);
48749 kfree(op);
48750 nobufs:
48751 - fscache_stat(&fscache_n_retrievals_nobufs);
48752 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48753 _leave(" = -ENOBUFS");
48754 return -ENOBUFS;
48755 }
48756 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
48757
48758 _enter("%p,%p,,,", cookie, page);
48759
48760 - fscache_stat(&fscache_n_allocs);
48761 + fscache_stat_unchecked(&fscache_n_allocs);
48762
48763 if (hlist_empty(&cookie->backing_objects))
48764 goto nobufs;
48765 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
48766 goto nobufs_unlock;
48767 spin_unlock(&cookie->lock);
48768
48769 - fscache_stat(&fscache_n_alloc_ops);
48770 + fscache_stat_unchecked(&fscache_n_alloc_ops);
48771
48772 ret = fscache_wait_for_retrieval_activation(
48773 object, op,
48774 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
48775
48776 error:
48777 if (ret == -ERESTARTSYS)
48778 - fscache_stat(&fscache_n_allocs_intr);
48779 + fscache_stat_unchecked(&fscache_n_allocs_intr);
48780 else if (ret < 0)
48781 - fscache_stat(&fscache_n_allocs_nobufs);
48782 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
48783 else
48784 - fscache_stat(&fscache_n_allocs_ok);
48785 + fscache_stat_unchecked(&fscache_n_allocs_ok);
48786
48787 fscache_put_retrieval(op);
48788 _leave(" = %d", ret);
48789 @@ -625,7 +625,7 @@ nobufs_unlock:
48790 spin_unlock(&cookie->lock);
48791 kfree(op);
48792 nobufs:
48793 - fscache_stat(&fscache_n_allocs_nobufs);
48794 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
48795 _leave(" = -ENOBUFS");
48796 return -ENOBUFS;
48797 }
48798 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
48799
48800 spin_lock(&cookie->stores_lock);
48801
48802 - fscache_stat(&fscache_n_store_calls);
48803 + fscache_stat_unchecked(&fscache_n_store_calls);
48804
48805 /* find a page to store */
48806 page = NULL;
48807 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
48808 page = results[0];
48809 _debug("gang %d [%lx]", n, page->index);
48810 if (page->index > op->store_limit) {
48811 - fscache_stat(&fscache_n_store_pages_over_limit);
48812 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
48813 goto superseded;
48814 }
48815
48816 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
48817 spin_unlock(&cookie->stores_lock);
48818 spin_unlock(&object->lock);
48819
48820 - fscache_stat(&fscache_n_store_pages);
48821 + fscache_stat_unchecked(&fscache_n_store_pages);
48822 fscache_stat(&fscache_n_cop_write_page);
48823 ret = object->cache->ops->write_page(op, page);
48824 fscache_stat_d(&fscache_n_cop_write_page);
48825 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48826 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
48827 ASSERT(PageFsCache(page));
48828
48829 - fscache_stat(&fscache_n_stores);
48830 + fscache_stat_unchecked(&fscache_n_stores);
48831
48832 op = kzalloc(sizeof(*op), GFP_NOIO);
48833 if (!op)
48834 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48835 spin_unlock(&cookie->stores_lock);
48836 spin_unlock(&object->lock);
48837
48838 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
48839 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
48840 op->store_limit = object->store_limit;
48841
48842 if (fscache_submit_op(object, &op->op) < 0)
48843 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48844
48845 spin_unlock(&cookie->lock);
48846 radix_tree_preload_end();
48847 - fscache_stat(&fscache_n_store_ops);
48848 - fscache_stat(&fscache_n_stores_ok);
48849 + fscache_stat_unchecked(&fscache_n_store_ops);
48850 + fscache_stat_unchecked(&fscache_n_stores_ok);
48851
48852 /* the work queue now carries its own ref on the object */
48853 fscache_put_operation(&op->op);
48854 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48855 return 0;
48856
48857 already_queued:
48858 - fscache_stat(&fscache_n_stores_again);
48859 + fscache_stat_unchecked(&fscache_n_stores_again);
48860 already_pending:
48861 spin_unlock(&cookie->stores_lock);
48862 spin_unlock(&object->lock);
48863 spin_unlock(&cookie->lock);
48864 radix_tree_preload_end();
48865 kfree(op);
48866 - fscache_stat(&fscache_n_stores_ok);
48867 + fscache_stat_unchecked(&fscache_n_stores_ok);
48868 _leave(" = 0");
48869 return 0;
48870
48871 @@ -851,14 +851,14 @@ nobufs:
48872 spin_unlock(&cookie->lock);
48873 radix_tree_preload_end();
48874 kfree(op);
48875 - fscache_stat(&fscache_n_stores_nobufs);
48876 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
48877 _leave(" = -ENOBUFS");
48878 return -ENOBUFS;
48879
48880 nomem_free:
48881 kfree(op);
48882 nomem:
48883 - fscache_stat(&fscache_n_stores_oom);
48884 + fscache_stat_unchecked(&fscache_n_stores_oom);
48885 _leave(" = -ENOMEM");
48886 return -ENOMEM;
48887 }
48888 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
48889 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
48890 ASSERTCMP(page, !=, NULL);
48891
48892 - fscache_stat(&fscache_n_uncaches);
48893 + fscache_stat_unchecked(&fscache_n_uncaches);
48894
48895 /* cache withdrawal may beat us to it */
48896 if (!PageFsCache(page))
48897 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
48898 unsigned long loop;
48899
48900 #ifdef CONFIG_FSCACHE_STATS
48901 - atomic_add(pagevec->nr, &fscache_n_marks);
48902 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
48903 #endif
48904
48905 for (loop = 0; loop < pagevec->nr; loop++) {
48906 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
48907 index 4765190..2a067f2 100644
48908 --- a/fs/fscache/stats.c
48909 +++ b/fs/fscache/stats.c
48910 @@ -18,95 +18,95 @@
48911 /*
48912 * operation counters
48913 */
48914 -atomic_t fscache_n_op_pend;
48915 -atomic_t fscache_n_op_run;
48916 -atomic_t fscache_n_op_enqueue;
48917 -atomic_t fscache_n_op_requeue;
48918 -atomic_t fscache_n_op_deferred_release;
48919 -atomic_t fscache_n_op_release;
48920 -atomic_t fscache_n_op_gc;
48921 -atomic_t fscache_n_op_cancelled;
48922 -atomic_t fscache_n_op_rejected;
48923 +atomic_unchecked_t fscache_n_op_pend;
48924 +atomic_unchecked_t fscache_n_op_run;
48925 +atomic_unchecked_t fscache_n_op_enqueue;
48926 +atomic_unchecked_t fscache_n_op_requeue;
48927 +atomic_unchecked_t fscache_n_op_deferred_release;
48928 +atomic_unchecked_t fscache_n_op_release;
48929 +atomic_unchecked_t fscache_n_op_gc;
48930 +atomic_unchecked_t fscache_n_op_cancelled;
48931 +atomic_unchecked_t fscache_n_op_rejected;
48932
48933 -atomic_t fscache_n_attr_changed;
48934 -atomic_t fscache_n_attr_changed_ok;
48935 -atomic_t fscache_n_attr_changed_nobufs;
48936 -atomic_t fscache_n_attr_changed_nomem;
48937 -atomic_t fscache_n_attr_changed_calls;
48938 +atomic_unchecked_t fscache_n_attr_changed;
48939 +atomic_unchecked_t fscache_n_attr_changed_ok;
48940 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
48941 +atomic_unchecked_t fscache_n_attr_changed_nomem;
48942 +atomic_unchecked_t fscache_n_attr_changed_calls;
48943
48944 -atomic_t fscache_n_allocs;
48945 -atomic_t fscache_n_allocs_ok;
48946 -atomic_t fscache_n_allocs_wait;
48947 -atomic_t fscache_n_allocs_nobufs;
48948 -atomic_t fscache_n_allocs_intr;
48949 -atomic_t fscache_n_allocs_object_dead;
48950 -atomic_t fscache_n_alloc_ops;
48951 -atomic_t fscache_n_alloc_op_waits;
48952 +atomic_unchecked_t fscache_n_allocs;
48953 +atomic_unchecked_t fscache_n_allocs_ok;
48954 +atomic_unchecked_t fscache_n_allocs_wait;
48955 +atomic_unchecked_t fscache_n_allocs_nobufs;
48956 +atomic_unchecked_t fscache_n_allocs_intr;
48957 +atomic_unchecked_t fscache_n_allocs_object_dead;
48958 +atomic_unchecked_t fscache_n_alloc_ops;
48959 +atomic_unchecked_t fscache_n_alloc_op_waits;
48960
48961 -atomic_t fscache_n_retrievals;
48962 -atomic_t fscache_n_retrievals_ok;
48963 -atomic_t fscache_n_retrievals_wait;
48964 -atomic_t fscache_n_retrievals_nodata;
48965 -atomic_t fscache_n_retrievals_nobufs;
48966 -atomic_t fscache_n_retrievals_intr;
48967 -atomic_t fscache_n_retrievals_nomem;
48968 -atomic_t fscache_n_retrievals_object_dead;
48969 -atomic_t fscache_n_retrieval_ops;
48970 -atomic_t fscache_n_retrieval_op_waits;
48971 +atomic_unchecked_t fscache_n_retrievals;
48972 +atomic_unchecked_t fscache_n_retrievals_ok;
48973 +atomic_unchecked_t fscache_n_retrievals_wait;
48974 +atomic_unchecked_t fscache_n_retrievals_nodata;
48975 +atomic_unchecked_t fscache_n_retrievals_nobufs;
48976 +atomic_unchecked_t fscache_n_retrievals_intr;
48977 +atomic_unchecked_t fscache_n_retrievals_nomem;
48978 +atomic_unchecked_t fscache_n_retrievals_object_dead;
48979 +atomic_unchecked_t fscache_n_retrieval_ops;
48980 +atomic_unchecked_t fscache_n_retrieval_op_waits;
48981
48982 -atomic_t fscache_n_stores;
48983 -atomic_t fscache_n_stores_ok;
48984 -atomic_t fscache_n_stores_again;
48985 -atomic_t fscache_n_stores_nobufs;
48986 -atomic_t fscache_n_stores_oom;
48987 -atomic_t fscache_n_store_ops;
48988 -atomic_t fscache_n_store_calls;
48989 -atomic_t fscache_n_store_pages;
48990 -atomic_t fscache_n_store_radix_deletes;
48991 -atomic_t fscache_n_store_pages_over_limit;
48992 +atomic_unchecked_t fscache_n_stores;
48993 +atomic_unchecked_t fscache_n_stores_ok;
48994 +atomic_unchecked_t fscache_n_stores_again;
48995 +atomic_unchecked_t fscache_n_stores_nobufs;
48996 +atomic_unchecked_t fscache_n_stores_oom;
48997 +atomic_unchecked_t fscache_n_store_ops;
48998 +atomic_unchecked_t fscache_n_store_calls;
48999 +atomic_unchecked_t fscache_n_store_pages;
49000 +atomic_unchecked_t fscache_n_store_radix_deletes;
49001 +atomic_unchecked_t fscache_n_store_pages_over_limit;
49002
49003 -atomic_t fscache_n_store_vmscan_not_storing;
49004 -atomic_t fscache_n_store_vmscan_gone;
49005 -atomic_t fscache_n_store_vmscan_busy;
49006 -atomic_t fscache_n_store_vmscan_cancelled;
49007 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
49008 +atomic_unchecked_t fscache_n_store_vmscan_gone;
49009 +atomic_unchecked_t fscache_n_store_vmscan_busy;
49010 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
49011
49012 -atomic_t fscache_n_marks;
49013 -atomic_t fscache_n_uncaches;
49014 +atomic_unchecked_t fscache_n_marks;
49015 +atomic_unchecked_t fscache_n_uncaches;
49016
49017 -atomic_t fscache_n_acquires;
49018 -atomic_t fscache_n_acquires_null;
49019 -atomic_t fscache_n_acquires_no_cache;
49020 -atomic_t fscache_n_acquires_ok;
49021 -atomic_t fscache_n_acquires_nobufs;
49022 -atomic_t fscache_n_acquires_oom;
49023 +atomic_unchecked_t fscache_n_acquires;
49024 +atomic_unchecked_t fscache_n_acquires_null;
49025 +atomic_unchecked_t fscache_n_acquires_no_cache;
49026 +atomic_unchecked_t fscache_n_acquires_ok;
49027 +atomic_unchecked_t fscache_n_acquires_nobufs;
49028 +atomic_unchecked_t fscache_n_acquires_oom;
49029
49030 -atomic_t fscache_n_updates;
49031 -atomic_t fscache_n_updates_null;
49032 -atomic_t fscache_n_updates_run;
49033 +atomic_unchecked_t fscache_n_updates;
49034 +atomic_unchecked_t fscache_n_updates_null;
49035 +atomic_unchecked_t fscache_n_updates_run;
49036
49037 -atomic_t fscache_n_relinquishes;
49038 -atomic_t fscache_n_relinquishes_null;
49039 -atomic_t fscache_n_relinquishes_waitcrt;
49040 -atomic_t fscache_n_relinquishes_retire;
49041 +atomic_unchecked_t fscache_n_relinquishes;
49042 +atomic_unchecked_t fscache_n_relinquishes_null;
49043 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
49044 +atomic_unchecked_t fscache_n_relinquishes_retire;
49045
49046 -atomic_t fscache_n_cookie_index;
49047 -atomic_t fscache_n_cookie_data;
49048 -atomic_t fscache_n_cookie_special;
49049 +atomic_unchecked_t fscache_n_cookie_index;
49050 +atomic_unchecked_t fscache_n_cookie_data;
49051 +atomic_unchecked_t fscache_n_cookie_special;
49052
49053 -atomic_t fscache_n_object_alloc;
49054 -atomic_t fscache_n_object_no_alloc;
49055 -atomic_t fscache_n_object_lookups;
49056 -atomic_t fscache_n_object_lookups_negative;
49057 -atomic_t fscache_n_object_lookups_positive;
49058 -atomic_t fscache_n_object_lookups_timed_out;
49059 -atomic_t fscache_n_object_created;
49060 -atomic_t fscache_n_object_avail;
49061 -atomic_t fscache_n_object_dead;
49062 +atomic_unchecked_t fscache_n_object_alloc;
49063 +atomic_unchecked_t fscache_n_object_no_alloc;
49064 +atomic_unchecked_t fscache_n_object_lookups;
49065 +atomic_unchecked_t fscache_n_object_lookups_negative;
49066 +atomic_unchecked_t fscache_n_object_lookups_positive;
49067 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
49068 +atomic_unchecked_t fscache_n_object_created;
49069 +atomic_unchecked_t fscache_n_object_avail;
49070 +atomic_unchecked_t fscache_n_object_dead;
49071
49072 -atomic_t fscache_n_checkaux_none;
49073 -atomic_t fscache_n_checkaux_okay;
49074 -atomic_t fscache_n_checkaux_update;
49075 -atomic_t fscache_n_checkaux_obsolete;
49076 +atomic_unchecked_t fscache_n_checkaux_none;
49077 +atomic_unchecked_t fscache_n_checkaux_okay;
49078 +atomic_unchecked_t fscache_n_checkaux_update;
49079 +atomic_unchecked_t fscache_n_checkaux_obsolete;
49080
49081 atomic_t fscache_n_cop_alloc_object;
49082 atomic_t fscache_n_cop_lookup_object;
49083 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
49084 seq_puts(m, "FS-Cache statistics\n");
49085
49086 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
49087 - atomic_read(&fscache_n_cookie_index),
49088 - atomic_read(&fscache_n_cookie_data),
49089 - atomic_read(&fscache_n_cookie_special));
49090 + atomic_read_unchecked(&fscache_n_cookie_index),
49091 + atomic_read_unchecked(&fscache_n_cookie_data),
49092 + atomic_read_unchecked(&fscache_n_cookie_special));
49093
49094 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
49095 - atomic_read(&fscache_n_object_alloc),
49096 - atomic_read(&fscache_n_object_no_alloc),
49097 - atomic_read(&fscache_n_object_avail),
49098 - atomic_read(&fscache_n_object_dead));
49099 + atomic_read_unchecked(&fscache_n_object_alloc),
49100 + atomic_read_unchecked(&fscache_n_object_no_alloc),
49101 + atomic_read_unchecked(&fscache_n_object_avail),
49102 + atomic_read_unchecked(&fscache_n_object_dead));
49103 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
49104 - atomic_read(&fscache_n_checkaux_none),
49105 - atomic_read(&fscache_n_checkaux_okay),
49106 - atomic_read(&fscache_n_checkaux_update),
49107 - atomic_read(&fscache_n_checkaux_obsolete));
49108 + atomic_read_unchecked(&fscache_n_checkaux_none),
49109 + atomic_read_unchecked(&fscache_n_checkaux_okay),
49110 + atomic_read_unchecked(&fscache_n_checkaux_update),
49111 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
49112
49113 seq_printf(m, "Pages : mrk=%u unc=%u\n",
49114 - atomic_read(&fscache_n_marks),
49115 - atomic_read(&fscache_n_uncaches));
49116 + atomic_read_unchecked(&fscache_n_marks),
49117 + atomic_read_unchecked(&fscache_n_uncaches));
49118
49119 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
49120 " oom=%u\n",
49121 - atomic_read(&fscache_n_acquires),
49122 - atomic_read(&fscache_n_acquires_null),
49123 - atomic_read(&fscache_n_acquires_no_cache),
49124 - atomic_read(&fscache_n_acquires_ok),
49125 - atomic_read(&fscache_n_acquires_nobufs),
49126 - atomic_read(&fscache_n_acquires_oom));
49127 + atomic_read_unchecked(&fscache_n_acquires),
49128 + atomic_read_unchecked(&fscache_n_acquires_null),
49129 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
49130 + atomic_read_unchecked(&fscache_n_acquires_ok),
49131 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
49132 + atomic_read_unchecked(&fscache_n_acquires_oom));
49133
49134 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
49135 - atomic_read(&fscache_n_object_lookups),
49136 - atomic_read(&fscache_n_object_lookups_negative),
49137 - atomic_read(&fscache_n_object_lookups_positive),
49138 - atomic_read(&fscache_n_object_created),
49139 - atomic_read(&fscache_n_object_lookups_timed_out));
49140 + atomic_read_unchecked(&fscache_n_object_lookups),
49141 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
49142 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
49143 + atomic_read_unchecked(&fscache_n_object_created),
49144 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
49145
49146 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
49147 - atomic_read(&fscache_n_updates),
49148 - atomic_read(&fscache_n_updates_null),
49149 - atomic_read(&fscache_n_updates_run));
49150 + atomic_read_unchecked(&fscache_n_updates),
49151 + atomic_read_unchecked(&fscache_n_updates_null),
49152 + atomic_read_unchecked(&fscache_n_updates_run));
49153
49154 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
49155 - atomic_read(&fscache_n_relinquishes),
49156 - atomic_read(&fscache_n_relinquishes_null),
49157 - atomic_read(&fscache_n_relinquishes_waitcrt),
49158 - atomic_read(&fscache_n_relinquishes_retire));
49159 + atomic_read_unchecked(&fscache_n_relinquishes),
49160 + atomic_read_unchecked(&fscache_n_relinquishes_null),
49161 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
49162 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
49163
49164 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
49165 - atomic_read(&fscache_n_attr_changed),
49166 - atomic_read(&fscache_n_attr_changed_ok),
49167 - atomic_read(&fscache_n_attr_changed_nobufs),
49168 - atomic_read(&fscache_n_attr_changed_nomem),
49169 - atomic_read(&fscache_n_attr_changed_calls));
49170 + atomic_read_unchecked(&fscache_n_attr_changed),
49171 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
49172 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
49173 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
49174 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
49175
49176 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
49177 - atomic_read(&fscache_n_allocs),
49178 - atomic_read(&fscache_n_allocs_ok),
49179 - atomic_read(&fscache_n_allocs_wait),
49180 - atomic_read(&fscache_n_allocs_nobufs),
49181 - atomic_read(&fscache_n_allocs_intr));
49182 + atomic_read_unchecked(&fscache_n_allocs),
49183 + atomic_read_unchecked(&fscache_n_allocs_ok),
49184 + atomic_read_unchecked(&fscache_n_allocs_wait),
49185 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
49186 + atomic_read_unchecked(&fscache_n_allocs_intr));
49187 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
49188 - atomic_read(&fscache_n_alloc_ops),
49189 - atomic_read(&fscache_n_alloc_op_waits),
49190 - atomic_read(&fscache_n_allocs_object_dead));
49191 + atomic_read_unchecked(&fscache_n_alloc_ops),
49192 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
49193 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
49194
49195 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
49196 " int=%u oom=%u\n",
49197 - atomic_read(&fscache_n_retrievals),
49198 - atomic_read(&fscache_n_retrievals_ok),
49199 - atomic_read(&fscache_n_retrievals_wait),
49200 - atomic_read(&fscache_n_retrievals_nodata),
49201 - atomic_read(&fscache_n_retrievals_nobufs),
49202 - atomic_read(&fscache_n_retrievals_intr),
49203 - atomic_read(&fscache_n_retrievals_nomem));
49204 + atomic_read_unchecked(&fscache_n_retrievals),
49205 + atomic_read_unchecked(&fscache_n_retrievals_ok),
49206 + atomic_read_unchecked(&fscache_n_retrievals_wait),
49207 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
49208 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
49209 + atomic_read_unchecked(&fscache_n_retrievals_intr),
49210 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
49211 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
49212 - atomic_read(&fscache_n_retrieval_ops),
49213 - atomic_read(&fscache_n_retrieval_op_waits),
49214 - atomic_read(&fscache_n_retrievals_object_dead));
49215 + atomic_read_unchecked(&fscache_n_retrieval_ops),
49216 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
49217 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
49218
49219 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
49220 - atomic_read(&fscache_n_stores),
49221 - atomic_read(&fscache_n_stores_ok),
49222 - atomic_read(&fscache_n_stores_again),
49223 - atomic_read(&fscache_n_stores_nobufs),
49224 - atomic_read(&fscache_n_stores_oom));
49225 + atomic_read_unchecked(&fscache_n_stores),
49226 + atomic_read_unchecked(&fscache_n_stores_ok),
49227 + atomic_read_unchecked(&fscache_n_stores_again),
49228 + atomic_read_unchecked(&fscache_n_stores_nobufs),
49229 + atomic_read_unchecked(&fscache_n_stores_oom));
49230 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
49231 - atomic_read(&fscache_n_store_ops),
49232 - atomic_read(&fscache_n_store_calls),
49233 - atomic_read(&fscache_n_store_pages),
49234 - atomic_read(&fscache_n_store_radix_deletes),
49235 - atomic_read(&fscache_n_store_pages_over_limit));
49236 + atomic_read_unchecked(&fscache_n_store_ops),
49237 + atomic_read_unchecked(&fscache_n_store_calls),
49238 + atomic_read_unchecked(&fscache_n_store_pages),
49239 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
49240 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
49241
49242 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
49243 - atomic_read(&fscache_n_store_vmscan_not_storing),
49244 - atomic_read(&fscache_n_store_vmscan_gone),
49245 - atomic_read(&fscache_n_store_vmscan_busy),
49246 - atomic_read(&fscache_n_store_vmscan_cancelled));
49247 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
49248 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
49249 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
49250 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
49251
49252 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
49253 - atomic_read(&fscache_n_op_pend),
49254 - atomic_read(&fscache_n_op_run),
49255 - atomic_read(&fscache_n_op_enqueue),
49256 - atomic_read(&fscache_n_op_cancelled),
49257 - atomic_read(&fscache_n_op_rejected));
49258 + atomic_read_unchecked(&fscache_n_op_pend),
49259 + atomic_read_unchecked(&fscache_n_op_run),
49260 + atomic_read_unchecked(&fscache_n_op_enqueue),
49261 + atomic_read_unchecked(&fscache_n_op_cancelled),
49262 + atomic_read_unchecked(&fscache_n_op_rejected));
49263 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
49264 - atomic_read(&fscache_n_op_deferred_release),
49265 - atomic_read(&fscache_n_op_release),
49266 - atomic_read(&fscache_n_op_gc));
49267 + atomic_read_unchecked(&fscache_n_op_deferred_release),
49268 + atomic_read_unchecked(&fscache_n_op_release),
49269 + atomic_read_unchecked(&fscache_n_op_gc));
49270
49271 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
49272 atomic_read(&fscache_n_cop_alloc_object),
49273 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
49274 index ee8d550..7189d8c 100644
49275 --- a/fs/fuse/cuse.c
49276 +++ b/fs/fuse/cuse.c
49277 @@ -585,10 +585,12 @@ static int __init cuse_init(void)
49278 INIT_LIST_HEAD(&cuse_conntbl[i]);
49279
49280 /* inherit and extend fuse_dev_operations */
49281 - cuse_channel_fops = fuse_dev_operations;
49282 - cuse_channel_fops.owner = THIS_MODULE;
49283 - cuse_channel_fops.open = cuse_channel_open;
49284 - cuse_channel_fops.release = cuse_channel_release;
49285 + pax_open_kernel();
49286 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
49287 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
49288 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
49289 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
49290 + pax_close_kernel();
49291
49292 cuse_class = class_create(THIS_MODULE, "cuse");
49293 if (IS_ERR(cuse_class))
49294 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
49295 index 8c23fa7..0e3aac7 100644
49296 --- a/fs/fuse/dev.c
49297 +++ b/fs/fuse/dev.c
49298 @@ -1241,7 +1241,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
49299 ret = 0;
49300 pipe_lock(pipe);
49301
49302 - if (!pipe->readers) {
49303 + if (!atomic_read(&pipe->readers)) {
49304 send_sig(SIGPIPE, current, 0);
49305 if (!ret)
49306 ret = -EPIPE;
49307 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
49308 index 324bc08..4fdd56e 100644
49309 --- a/fs/fuse/dir.c
49310 +++ b/fs/fuse/dir.c
49311 @@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
49312 return link;
49313 }
49314
49315 -static void free_link(char *link)
49316 +static void free_link(const char *link)
49317 {
49318 if (!IS_ERR(link))
49319 free_page((unsigned long) link);
49320 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
49321 index 381893c..3793318 100644
49322 --- a/fs/gfs2/inode.c
49323 +++ b/fs/gfs2/inode.c
49324 @@ -1490,7 +1490,7 @@ out:
49325
49326 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
49327 {
49328 - char *s = nd_get_link(nd);
49329 + const char *s = nd_get_link(nd);
49330 if (!IS_ERR(s))
49331 kfree(s);
49332 }
49333 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
49334 index c5bc355..163a13e 100644
49335 --- a/fs/hugetlbfs/inode.c
49336 +++ b/fs/hugetlbfs/inode.c
49337 @@ -153,6 +153,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
49338 struct vm_area_struct *vma;
49339 unsigned long start_addr;
49340 struct hstate *h = hstate_file(file);
49341 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
49342
49343 if (len & ~huge_page_mask(h))
49344 return -EINVAL;
49345 @@ -165,18 +166,21 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
49346 return addr;
49347 }
49348
49349 +#ifdef CONFIG_PAX_RANDMMAP
49350 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
49351 +#endif
49352 +
49353 if (addr) {
49354 addr = ALIGN(addr, huge_page_size(h));
49355 vma = find_vma(mm, addr);
49356 - if (TASK_SIZE - len >= addr &&
49357 - (!vma || addr + len <= vma->vm_start))
49358 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
49359 return addr;
49360 }
49361
49362 if (len > mm->cached_hole_size)
49363 start_addr = mm->free_area_cache;
49364 else {
49365 - start_addr = TASK_UNMAPPED_BASE;
49366 + start_addr = mm->mmap_base;
49367 mm->cached_hole_size = 0;
49368 }
49369
49370 @@ -190,15 +194,15 @@ full_search:
49371 * Start a new search - just in case we missed
49372 * some holes.
49373 */
49374 - if (start_addr != TASK_UNMAPPED_BASE) {
49375 - start_addr = TASK_UNMAPPED_BASE;
49376 + if (start_addr != mm->mmap_base) {
49377 + start_addr = mm->mmap_base;
49378 mm->cached_hole_size = 0;
49379 goto full_search;
49380 }
49381 return -ENOMEM;
49382 }
49383
49384 - if (!vma || addr + len <= vma->vm_start) {
49385 + if (check_heap_stack_gap(vma, addr, len, offset)) {
49386 mm->free_area_cache = addr + len;
49387 return addr;
49388 }
49389 @@ -923,7 +927,7 @@ static struct file_system_type hugetlbfs_fs_type = {
49390 .kill_sb = kill_litter_super,
49391 };
49392
49393 -static struct vfsmount *hugetlbfs_vfsmount;
49394 +struct vfsmount *hugetlbfs_vfsmount;
49395
49396 static int can_do_hugetlb_shm(void)
49397 {
49398 diff --git a/fs/inode.c b/fs/inode.c
49399 index 64999f1..8fad608 100644
49400 --- a/fs/inode.c
49401 +++ b/fs/inode.c
49402 @@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
49403
49404 #ifdef CONFIG_SMP
49405 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
49406 - static atomic_t shared_last_ino;
49407 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
49408 + static atomic_unchecked_t shared_last_ino;
49409 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
49410
49411 res = next - LAST_INO_BATCH;
49412 }
49413 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
49414 index 4a6cf28..d3a29d3 100644
49415 --- a/fs/jffs2/erase.c
49416 +++ b/fs/jffs2/erase.c
49417 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
49418 struct jffs2_unknown_node marker = {
49419 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
49420 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
49421 - .totlen = cpu_to_je32(c->cleanmarker_size)
49422 + .totlen = cpu_to_je32(c->cleanmarker_size),
49423 + .hdr_crc = cpu_to_je32(0)
49424 };
49425
49426 jffs2_prealloc_raw_node_refs(c, jeb, 1);
49427 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
49428 index a6597d6..41b30ec 100644
49429 --- a/fs/jffs2/wbuf.c
49430 +++ b/fs/jffs2/wbuf.c
49431 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
49432 {
49433 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
49434 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
49435 - .totlen = constant_cpu_to_je32(8)
49436 + .totlen = constant_cpu_to_je32(8),
49437 + .hdr_crc = constant_cpu_to_je32(0)
49438 };
49439
49440 /*
49441 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
49442 index 1a543be..d803c40 100644
49443 --- a/fs/jfs/super.c
49444 +++ b/fs/jfs/super.c
49445 @@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
49446
49447 jfs_inode_cachep =
49448 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
49449 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
49450 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
49451 init_once);
49452 if (jfs_inode_cachep == NULL)
49453 return -ENOMEM;
49454 diff --git a/fs/libfs.c b/fs/libfs.c
49455 index 7cc37ca..b3e3eec 100644
49456 --- a/fs/libfs.c
49457 +++ b/fs/libfs.c
49458 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
49459
49460 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
49461 struct dentry *next;
49462 + char d_name[sizeof(next->d_iname)];
49463 + const unsigned char *name;
49464 +
49465 next = list_entry(p, struct dentry, d_u.d_child);
49466 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
49467 if (!simple_positive(next)) {
49468 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
49469
49470 spin_unlock(&next->d_lock);
49471 spin_unlock(&dentry->d_lock);
49472 - if (filldir(dirent, next->d_name.name,
49473 + name = next->d_name.name;
49474 + if (name == next->d_iname) {
49475 + memcpy(d_name, name, next->d_name.len);
49476 + name = d_name;
49477 + }
49478 + if (filldir(dirent, name,
49479 next->d_name.len, filp->f_pos,
49480 next->d_inode->i_ino,
49481 dt_type(next->d_inode)) < 0)
49482 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
49483 index 05d2912..760abfa 100644
49484 --- a/fs/lockd/clntproc.c
49485 +++ b/fs/lockd/clntproc.c
49486 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
49487 /*
49488 * Cookie counter for NLM requests
49489 */
49490 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
49491 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
49492
49493 void nlmclnt_next_cookie(struct nlm_cookie *c)
49494 {
49495 - u32 cookie = atomic_inc_return(&nlm_cookie);
49496 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
49497
49498 memcpy(c->data, &cookie, 4);
49499 c->len=4;
49500 diff --git a/fs/locks.c b/fs/locks.c
49501 index a94e331..060bce3 100644
49502 --- a/fs/locks.c
49503 +++ b/fs/locks.c
49504 @@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
49505 return;
49506
49507 if (filp->f_op && filp->f_op->flock) {
49508 - struct file_lock fl = {
49509 + struct file_lock flock = {
49510 .fl_pid = current->tgid,
49511 .fl_file = filp,
49512 .fl_flags = FL_FLOCK,
49513 .fl_type = F_UNLCK,
49514 .fl_end = OFFSET_MAX,
49515 };
49516 - filp->f_op->flock(filp, F_SETLKW, &fl);
49517 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
49518 - fl.fl_ops->fl_release_private(&fl);
49519 + filp->f_op->flock(filp, F_SETLKW, &flock);
49520 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
49521 + flock.fl_ops->fl_release_private(&flock);
49522 }
49523
49524 lock_flocks();
49525 diff --git a/fs/namei.c b/fs/namei.c
49526 index 5f4cdf3..959a013 100644
49527 --- a/fs/namei.c
49528 +++ b/fs/namei.c
49529 @@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
49530 if (ret != -EACCES)
49531 return ret;
49532
49533 +#ifdef CONFIG_GRKERNSEC
49534 + /* we'll block if we have to log due to a denied capability use */
49535 + if (mask & MAY_NOT_BLOCK)
49536 + return -ECHILD;
49537 +#endif
49538 +
49539 if (S_ISDIR(inode->i_mode)) {
49540 /* DACs are overridable for directories */
49541 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
49542 - return 0;
49543 if (!(mask & MAY_WRITE))
49544 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
49545 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
49546 + inode_capable(inode, CAP_DAC_READ_SEARCH))
49547 return 0;
49548 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
49549 + return 0;
49550 return -EACCES;
49551 }
49552 /*
49553 + * Searching includes executable on directories, else just read.
49554 + */
49555 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
49556 + if (mask == MAY_READ)
49557 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
49558 + inode_capable(inode, CAP_DAC_READ_SEARCH))
49559 + return 0;
49560 +
49561 + /*
49562 * Read/write DACs are always overridable.
49563 * Executable DACs are overridable when there is
49564 * at least one exec bit set.
49565 @@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
49566 if (inode_capable(inode, CAP_DAC_OVERRIDE))
49567 return 0;
49568
49569 - /*
49570 - * Searching includes executable on directories, else just read.
49571 - */
49572 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
49573 - if (mask == MAY_READ)
49574 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
49575 - return 0;
49576 -
49577 return -EACCES;
49578 }
49579
49580 @@ -826,7 +834,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
49581 {
49582 struct dentry *dentry = link->dentry;
49583 int error;
49584 - char *s;
49585 + const char *s;
49586
49587 BUG_ON(nd->flags & LOOKUP_RCU);
49588
49589 @@ -847,6 +855,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
49590 if (error)
49591 goto out_put_nd_path;
49592
49593 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
49594 + dentry->d_inode, dentry, nd->path.mnt)) {
49595 + error = -EACCES;
49596 + goto out_put_nd_path;
49597 + }
49598 +
49599 nd->last_type = LAST_BIND;
49600 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
49601 error = PTR_ERR(*p);
49602 @@ -1605,6 +1619,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
49603 break;
49604 res = walk_component(nd, path, &nd->last,
49605 nd->last_type, LOOKUP_FOLLOW);
49606 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
49607 + res = -EACCES;
49608 put_link(nd, &link, cookie);
49609 } while (res > 0);
49610
49611 @@ -1703,7 +1719,7 @@ EXPORT_SYMBOL(full_name_hash);
49612 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
49613 {
49614 unsigned long a, b, adata, bdata, mask, hash, len;
49615 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
49616 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
49617
49618 hash = a = 0;
49619 len = -sizeof(unsigned long);
49620 @@ -1993,6 +2009,8 @@ static int path_lookupat(int dfd, const char *name,
49621 if (err)
49622 break;
49623 err = lookup_last(nd, &path);
49624 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
49625 + err = -EACCES;
49626 put_link(nd, &link, cookie);
49627 }
49628 }
49629 @@ -2000,6 +2018,21 @@ static int path_lookupat(int dfd, const char *name,
49630 if (!err)
49631 err = complete_walk(nd);
49632
49633 + if (!(nd->flags & LOOKUP_PARENT)) {
49634 +#ifdef CONFIG_GRKERNSEC
49635 + if (flags & LOOKUP_RCU) {
49636 + if (!err)
49637 + path_put(&nd->path);
49638 + err = -ECHILD;
49639 + } else
49640 +#endif
49641 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
49642 + if (!err)
49643 + path_put(&nd->path);
49644 + err = -ENOENT;
49645 + }
49646 + }
49647 +
49648 if (!err && nd->flags & LOOKUP_DIRECTORY) {
49649 if (!nd->inode->i_op->lookup) {
49650 path_put(&nd->path);
49651 @@ -2027,8 +2060,17 @@ static int filename_lookup(int dfd, struct filename *name,
49652 retval = path_lookupat(dfd, name->name,
49653 flags | LOOKUP_REVAL, nd);
49654
49655 - if (likely(!retval))
49656 + if (likely(!retval)) {
49657 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
49658 +#ifdef CONFIG_GRKERNSEC
49659 + if (flags & LOOKUP_RCU)
49660 + return -ECHILD;
49661 +#endif
49662 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
49663 + return -ENOENT;
49664 + }
49665 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
49666 + }
49667 return retval;
49668 }
49669
49670 @@ -2402,6 +2444,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
49671 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
49672 return -EPERM;
49673
49674 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
49675 + return -EPERM;
49676 + if (gr_handle_rawio(inode))
49677 + return -EPERM;
49678 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
49679 + return -EACCES;
49680 +
49681 return 0;
49682 }
49683
49684 @@ -2623,7 +2672,7 @@ looked_up:
49685 * cleared otherwise prior to returning.
49686 */
49687 static int lookup_open(struct nameidata *nd, struct path *path,
49688 - struct file *file,
49689 + struct path *link, struct file *file,
49690 const struct open_flags *op,
49691 bool got_write, int *opened)
49692 {
49693 @@ -2658,6 +2707,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
49694 /* Negative dentry, just create the file */
49695 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
49696 umode_t mode = op->mode;
49697 +
49698 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
49699 + error = -EACCES;
49700 + goto out_dput;
49701 + }
49702 +
49703 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
49704 + error = -EACCES;
49705 + goto out_dput;
49706 + }
49707 +
49708 if (!IS_POSIXACL(dir->d_inode))
49709 mode &= ~current_umask();
49710 /*
49711 @@ -2679,6 +2739,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
49712 nd->flags & LOOKUP_EXCL);
49713 if (error)
49714 goto out_dput;
49715 + else
49716 + gr_handle_create(dentry, nd->path.mnt);
49717 }
49718 out_no_open:
49719 path->dentry = dentry;
49720 @@ -2693,7 +2755,7 @@ out_dput:
49721 /*
49722 * Handle the last step of open()
49723 */
49724 -static int do_last(struct nameidata *nd, struct path *path,
49725 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
49726 struct file *file, const struct open_flags *op,
49727 int *opened, struct filename *name)
49728 {
49729 @@ -2722,16 +2784,44 @@ static int do_last(struct nameidata *nd, struct path *path,
49730 error = complete_walk(nd);
49731 if (error)
49732 return error;
49733 +#ifdef CONFIG_GRKERNSEC
49734 + if (nd->flags & LOOKUP_RCU) {
49735 + error = -ECHILD;
49736 + goto out;
49737 + }
49738 +#endif
49739 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
49740 + error = -ENOENT;
49741 + goto out;
49742 + }
49743 audit_inode(name, nd->path.dentry, 0);
49744 if (open_flag & O_CREAT) {
49745 error = -EISDIR;
49746 goto out;
49747 }
49748 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
49749 + error = -EACCES;
49750 + goto out;
49751 + }
49752 goto finish_open;
49753 case LAST_BIND:
49754 error = complete_walk(nd);
49755 if (error)
49756 return error;
49757 +#ifdef CONFIG_GRKERNSEC
49758 + if (nd->flags & LOOKUP_RCU) {
49759 + error = -ECHILD;
49760 + goto out;
49761 + }
49762 +#endif
49763 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
49764 + error = -ENOENT;
49765 + goto out;
49766 + }
49767 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
49768 + error = -EACCES;
49769 + goto out;
49770 + }
49771 audit_inode(name, dir, 0);
49772 goto finish_open;
49773 }
49774 @@ -2780,7 +2870,7 @@ retry_lookup:
49775 */
49776 }
49777 mutex_lock(&dir->d_inode->i_mutex);
49778 - error = lookup_open(nd, path, file, op, got_write, opened);
49779 + error = lookup_open(nd, path, link, file, op, got_write, opened);
49780 mutex_unlock(&dir->d_inode->i_mutex);
49781
49782 if (error <= 0) {
49783 @@ -2804,11 +2894,28 @@ retry_lookup:
49784 goto finish_open_created;
49785 }
49786
49787 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
49788 + error = -ENOENT;
49789 + goto exit_dput;
49790 + }
49791 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
49792 + error = -EACCES;
49793 + goto exit_dput;
49794 + }
49795 +
49796 /*
49797 * create/update audit record if it already exists.
49798 */
49799 - if (path->dentry->d_inode)
49800 + if (path->dentry->d_inode) {
49801 + /* only check if O_CREAT is specified, all other checks need to go
49802 + into may_open */
49803 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
49804 + error = -EACCES;
49805 + goto exit_dput;
49806 + }
49807 +
49808 audit_inode(name, path->dentry, 0);
49809 + }
49810
49811 /*
49812 * If atomic_open() acquired write access it is dropped now due to
49813 @@ -2849,6 +2956,11 @@ finish_lookup:
49814 }
49815 }
49816 BUG_ON(inode != path->dentry->d_inode);
49817 + /* if we're resolving a symlink to another symlink */
49818 + if (link && gr_handle_symlink_owner(link, inode)) {
49819 + error = -EACCES;
49820 + goto out;
49821 + }
49822 return 1;
49823 }
49824
49825 @@ -2858,7 +2970,6 @@ finish_lookup:
49826 save_parent.dentry = nd->path.dentry;
49827 save_parent.mnt = mntget(path->mnt);
49828 nd->path.dentry = path->dentry;
49829 -
49830 }
49831 nd->inode = inode;
49832 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
49833 @@ -2867,6 +2978,22 @@ finish_lookup:
49834 path_put(&save_parent);
49835 return error;
49836 }
49837 +
49838 +#ifdef CONFIG_GRKERNSEC
49839 + if (nd->flags & LOOKUP_RCU) {
49840 + error = -ECHILD;
49841 + goto out;
49842 + }
49843 +#endif
49844 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
49845 + error = -ENOENT;
49846 + goto out;
49847 + }
49848 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
49849 + error = -EACCES;
49850 + goto out;
49851 + }
49852 +
49853 error = -EISDIR;
49854 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
49855 goto out;
49856 @@ -2965,7 +3092,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
49857 if (unlikely(error))
49858 goto out;
49859
49860 - error = do_last(nd, &path, file, op, &opened, pathname);
49861 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
49862 while (unlikely(error > 0)) { /* trailing symlink */
49863 struct path link = path;
49864 void *cookie;
49865 @@ -2983,7 +3110,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
49866 error = follow_link(&link, nd, &cookie);
49867 if (unlikely(error))
49868 break;
49869 - error = do_last(nd, &path, file, op, &opened, pathname);
49870 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
49871 put_link(nd, &link, cookie);
49872 }
49873 out:
49874 @@ -3073,8 +3200,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
49875 goto unlock;
49876
49877 error = -EEXIST;
49878 - if (dentry->d_inode)
49879 + if (dentry->d_inode) {
49880 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
49881 + error = -ENOENT;
49882 + }
49883 goto fail;
49884 + }
49885 /*
49886 * Special case - lookup gave negative, but... we had foo/bar/
49887 * From the vfs_mknod() POV we just have a negative dentry -
49888 @@ -3125,6 +3256,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
49889 }
49890 EXPORT_SYMBOL(user_path_create);
49891
49892 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, int is_dir)
49893 +{
49894 + struct filename *tmp = getname(pathname);
49895 + struct dentry *res;
49896 + if (IS_ERR(tmp))
49897 + return ERR_CAST(tmp);
49898 + res = kern_path_create(dfd, tmp->name, path, is_dir);
49899 + if (IS_ERR(res))
49900 + putname(tmp);
49901 + else
49902 + *to = tmp;
49903 + return res;
49904 +}
49905 +
49906 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
49907 {
49908 int error = may_create(dir, dentry);
49909 @@ -3186,6 +3331,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
49910
49911 if (!IS_POSIXACL(path.dentry->d_inode))
49912 mode &= ~current_umask();
49913 +
49914 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
49915 + error = -EPERM;
49916 + goto out;
49917 + }
49918 +
49919 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
49920 + error = -EACCES;
49921 + goto out;
49922 + }
49923 +
49924 error = security_path_mknod(&path, dentry, mode, dev);
49925 if (error)
49926 goto out;
49927 @@ -3202,6 +3358,8 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
49928 break;
49929 }
49930 out:
49931 + if (!error)
49932 + gr_handle_create(dentry, path.mnt);
49933 done_path_create(&path, dentry);
49934 return error;
49935 }
49936 @@ -3248,9 +3406,18 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
49937
49938 if (!IS_POSIXACL(path.dentry->d_inode))
49939 mode &= ~current_umask();
49940 +
49941 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
49942 + error = -EACCES;
49943 + goto out;
49944 + }
49945 +
49946 error = security_path_mkdir(&path, dentry, mode);
49947 if (!error)
49948 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
49949 + if (!error)
49950 + gr_handle_create(dentry, path.mnt);
49951 +out:
49952 done_path_create(&path, dentry);
49953 return error;
49954 }
49955 @@ -3327,6 +3494,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
49956 struct filename *name;
49957 struct dentry *dentry;
49958 struct nameidata nd;
49959 + ino_t saved_ino = 0;
49960 + dev_t saved_dev = 0;
49961
49962 name = user_path_parent(dfd, pathname, &nd);
49963 if (IS_ERR(name))
49964 @@ -3358,10 +3527,21 @@ static long do_rmdir(int dfd, const char __user *pathname)
49965 error = -ENOENT;
49966 goto exit3;
49967 }
49968 +
49969 + saved_ino = dentry->d_inode->i_ino;
49970 + saved_dev = gr_get_dev_from_dentry(dentry);
49971 +
49972 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
49973 + error = -EACCES;
49974 + goto exit3;
49975 + }
49976 +
49977 error = security_path_rmdir(&nd.path, dentry);
49978 if (error)
49979 goto exit3;
49980 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
49981 + if (!error && (saved_dev || saved_ino))
49982 + gr_handle_delete(saved_ino, saved_dev);
49983 exit3:
49984 dput(dentry);
49985 exit2:
49986 @@ -3423,6 +3603,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
49987 struct dentry *dentry;
49988 struct nameidata nd;
49989 struct inode *inode = NULL;
49990 + ino_t saved_ino = 0;
49991 + dev_t saved_dev = 0;
49992
49993 name = user_path_parent(dfd, pathname, &nd);
49994 if (IS_ERR(name))
49995 @@ -3448,10 +3630,22 @@ static long do_unlinkat(int dfd, const char __user *pathname)
49996 if (!inode)
49997 goto slashes;
49998 ihold(inode);
49999 +
50000 + if (inode->i_nlink <= 1) {
50001 + saved_ino = inode->i_ino;
50002 + saved_dev = gr_get_dev_from_dentry(dentry);
50003 + }
50004 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
50005 + error = -EACCES;
50006 + goto exit2;
50007 + }
50008 +
50009 error = security_path_unlink(&nd.path, dentry);
50010 if (error)
50011 goto exit2;
50012 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
50013 + if (!error && (saved_ino || saved_dev))
50014 + gr_handle_delete(saved_ino, saved_dev);
50015 exit2:
50016 dput(dentry);
50017 }
50018 @@ -3523,9 +3717,17 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
50019 if (IS_ERR(dentry))
50020 goto out_putname;
50021
50022 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
50023 + error = -EACCES;
50024 + goto out;
50025 + }
50026 +
50027 error = security_path_symlink(&path, dentry, from->name);
50028 if (!error)
50029 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
50030 + if (!error)
50031 + gr_handle_create(dentry, path.mnt);
50032 +out:
50033 done_path_create(&path, dentry);
50034 out_putname:
50035 putname(from);
50036 @@ -3595,6 +3797,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
50037 {
50038 struct dentry *new_dentry;
50039 struct path old_path, new_path;
50040 + struct filename *to = NULL;
50041 int how = 0;
50042 int error;
50043
50044 @@ -3618,7 +3821,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
50045 if (error)
50046 return error;
50047
50048 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
50049 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
50050 error = PTR_ERR(new_dentry);
50051 if (IS_ERR(new_dentry))
50052 goto out;
50053 @@ -3629,11 +3832,28 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
50054 error = may_linkat(&old_path);
50055 if (unlikely(error))
50056 goto out_dput;
50057 +
50058 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
50059 + old_path.dentry->d_inode,
50060 + old_path.dentry->d_inode->i_mode, to)) {
50061 + error = -EACCES;
50062 + goto out_dput;
50063 + }
50064 +
50065 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
50066 + old_path.dentry, old_path.mnt, to)) {
50067 + error = -EACCES;
50068 + goto out_dput;
50069 + }
50070 +
50071 error = security_path_link(old_path.dentry, &new_path, new_dentry);
50072 if (error)
50073 goto out_dput;
50074 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
50075 + if (!error)
50076 + gr_handle_create(new_dentry, new_path.mnt);
50077 out_dput:
50078 + putname(to);
50079 done_path_create(&new_path, new_dentry);
50080 out:
50081 path_put(&old_path);
50082 @@ -3873,12 +4093,21 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
50083 if (new_dentry == trap)
50084 goto exit5;
50085
50086 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
50087 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
50088 + to);
50089 + if (error)
50090 + goto exit5;
50091 +
50092 error = security_path_rename(&oldnd.path, old_dentry,
50093 &newnd.path, new_dentry);
50094 if (error)
50095 goto exit5;
50096 error = vfs_rename(old_dir->d_inode, old_dentry,
50097 new_dir->d_inode, new_dentry);
50098 + if (!error)
50099 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
50100 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
50101 exit5:
50102 dput(new_dentry);
50103 exit4:
50104 @@ -3903,6 +4132,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
50105
50106 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
50107 {
50108 + char tmpbuf[64];
50109 + const char *newlink;
50110 int len;
50111
50112 len = PTR_ERR(link);
50113 @@ -3912,7 +4143,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
50114 len = strlen(link);
50115 if (len > (unsigned) buflen)
50116 len = buflen;
50117 - if (copy_to_user(buffer, link, len))
50118 +
50119 + if (len < sizeof(tmpbuf)) {
50120 + memcpy(tmpbuf, link, len);
50121 + newlink = tmpbuf;
50122 + } else
50123 + newlink = link;
50124 +
50125 + if (copy_to_user(buffer, newlink, len))
50126 len = -EFAULT;
50127 out:
50128 return len;
50129 diff --git a/fs/namespace.c b/fs/namespace.c
50130 index 2496062..e26f6d6 100644
50131 --- a/fs/namespace.c
50132 +++ b/fs/namespace.c
50133 @@ -1212,6 +1212,9 @@ static int do_umount(struct mount *mnt, int flags)
50134 if (!(sb->s_flags & MS_RDONLY))
50135 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
50136 up_write(&sb->s_umount);
50137 +
50138 + gr_log_remount(mnt->mnt_devname, retval);
50139 +
50140 return retval;
50141 }
50142
50143 @@ -1231,6 +1234,9 @@ static int do_umount(struct mount *mnt, int flags)
50144 br_write_unlock(&vfsmount_lock);
50145 up_write(&namespace_sem);
50146 release_mounts(&umount_list);
50147 +
50148 + gr_log_unmount(mnt->mnt_devname, retval);
50149 +
50150 return retval;
50151 }
50152
50153 @@ -2244,6 +2250,16 @@ long do_mount(const char *dev_name, const char *dir_name,
50154 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
50155 MS_STRICTATIME);
50156
50157 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
50158 + retval = -EPERM;
50159 + goto dput_out;
50160 + }
50161 +
50162 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
50163 + retval = -EPERM;
50164 + goto dput_out;
50165 + }
50166 +
50167 if (flags & MS_REMOUNT)
50168 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
50169 data_page);
50170 @@ -2258,6 +2274,9 @@ long do_mount(const char *dev_name, const char *dir_name,
50171 dev_name, data_page);
50172 dput_out:
50173 path_put(&path);
50174 +
50175 + gr_log_mount(dev_name, dir_name, retval);
50176 +
50177 return retval;
50178 }
50179
50180 @@ -2516,6 +2535,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
50181 if (error)
50182 goto out2;
50183
50184 + if (gr_handle_chroot_pivot()) {
50185 + error = -EPERM;
50186 + goto out2;
50187 + }
50188 +
50189 get_fs_root(current->fs, &root);
50190 error = lock_mount(&old);
50191 if (error)
50192 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
50193 index 6fa01ae..2790820 100644
50194 --- a/fs/nfs/inode.c
50195 +++ b/fs/nfs/inode.c
50196 @@ -1029,16 +1029,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
50197 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
50198 }
50199
50200 -static atomic_long_t nfs_attr_generation_counter;
50201 +static atomic_long_unchecked_t nfs_attr_generation_counter;
50202
50203 static unsigned long nfs_read_attr_generation_counter(void)
50204 {
50205 - return atomic_long_read(&nfs_attr_generation_counter);
50206 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
50207 }
50208
50209 unsigned long nfs_inc_attr_generation_counter(void)
50210 {
50211 - return atomic_long_inc_return(&nfs_attr_generation_counter);
50212 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
50213 }
50214
50215 void nfs_fattr_init(struct nfs_fattr *fattr)
50216 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
50217 index f59169e..fd7d359 100644
50218 --- a/fs/nfsd/vfs.c
50219 +++ b/fs/nfsd/vfs.c
50220 @@ -941,7 +941,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
50221 } else {
50222 oldfs = get_fs();
50223 set_fs(KERNEL_DS);
50224 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
50225 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
50226 set_fs(oldfs);
50227 }
50228
50229 @@ -1045,7 +1045,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
50230
50231 /* Write the data. */
50232 oldfs = get_fs(); set_fs(KERNEL_DS);
50233 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
50234 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
50235 set_fs(oldfs);
50236 if (host_err < 0)
50237 goto out_nfserr;
50238 @@ -1587,7 +1587,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
50239 */
50240
50241 oldfs = get_fs(); set_fs(KERNEL_DS);
50242 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
50243 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
50244 set_fs(oldfs);
50245
50246 if (host_err < 0)
50247 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
50248 index 6fcaeb8..9d16d04 100644
50249 --- a/fs/notify/fanotify/fanotify_user.c
50250 +++ b/fs/notify/fanotify/fanotify_user.c
50251 @@ -250,8 +250,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
50252
50253 fd = fanotify_event_metadata.fd;
50254 ret = -EFAULT;
50255 - if (copy_to_user(buf, &fanotify_event_metadata,
50256 - fanotify_event_metadata.event_len))
50257 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
50258 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
50259 goto out_close_fd;
50260
50261 ret = prepare_for_access_response(group, event, fd);
50262 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
50263 index c887b13..0fdf472 100644
50264 --- a/fs/notify/notification.c
50265 +++ b/fs/notify/notification.c
50266 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
50267 * get set to 0 so it will never get 'freed'
50268 */
50269 static struct fsnotify_event *q_overflow_event;
50270 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
50271 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
50272
50273 /**
50274 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
50275 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
50276 */
50277 u32 fsnotify_get_cookie(void)
50278 {
50279 - return atomic_inc_return(&fsnotify_sync_cookie);
50280 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
50281 }
50282 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
50283
50284 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
50285 index 99e3610..02c1068 100644
50286 --- a/fs/ntfs/dir.c
50287 +++ b/fs/ntfs/dir.c
50288 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
50289 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
50290 ~(s64)(ndir->itype.index.block_size - 1)));
50291 /* Bounds checks. */
50292 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
50293 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
50294 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
50295 "inode 0x%lx or driver bug.", vdir->i_ino);
50296 goto err_out;
50297 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
50298 index 1ecf464..e1ff8bf 100644
50299 --- a/fs/ntfs/file.c
50300 +++ b/fs/ntfs/file.c
50301 @@ -2232,6 +2232,6 @@ const struct inode_operations ntfs_file_inode_ops = {
50302 #endif /* NTFS_RW */
50303 };
50304
50305 -const struct file_operations ntfs_empty_file_ops = {};
50306 +const struct file_operations ntfs_empty_file_ops __read_only;
50307
50308 -const struct inode_operations ntfs_empty_inode_ops = {};
50309 +const struct inode_operations ntfs_empty_inode_ops __read_only;
50310 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
50311 index a9f78c7..ed8a381 100644
50312 --- a/fs/ocfs2/localalloc.c
50313 +++ b/fs/ocfs2/localalloc.c
50314 @@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
50315 goto bail;
50316 }
50317
50318 - atomic_inc(&osb->alloc_stats.moves);
50319 + atomic_inc_unchecked(&osb->alloc_stats.moves);
50320
50321 bail:
50322 if (handle)
50323 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
50324 index d355e6e..578d905 100644
50325 --- a/fs/ocfs2/ocfs2.h
50326 +++ b/fs/ocfs2/ocfs2.h
50327 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
50328
50329 struct ocfs2_alloc_stats
50330 {
50331 - atomic_t moves;
50332 - atomic_t local_data;
50333 - atomic_t bitmap_data;
50334 - atomic_t bg_allocs;
50335 - atomic_t bg_extends;
50336 + atomic_unchecked_t moves;
50337 + atomic_unchecked_t local_data;
50338 + atomic_unchecked_t bitmap_data;
50339 + atomic_unchecked_t bg_allocs;
50340 + atomic_unchecked_t bg_extends;
50341 };
50342
50343 enum ocfs2_local_alloc_state
50344 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
50345 index f169da4..9112253 100644
50346 --- a/fs/ocfs2/suballoc.c
50347 +++ b/fs/ocfs2/suballoc.c
50348 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
50349 mlog_errno(status);
50350 goto bail;
50351 }
50352 - atomic_inc(&osb->alloc_stats.bg_extends);
50353 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
50354
50355 /* You should never ask for this much metadata */
50356 BUG_ON(bits_wanted >
50357 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
50358 mlog_errno(status);
50359 goto bail;
50360 }
50361 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50362 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50363
50364 *suballoc_loc = res.sr_bg_blkno;
50365 *suballoc_bit_start = res.sr_bit_offset;
50366 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
50367 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
50368 res->sr_bits);
50369
50370 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50371 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50372
50373 BUG_ON(res->sr_bits != 1);
50374
50375 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
50376 mlog_errno(status);
50377 goto bail;
50378 }
50379 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50380 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50381
50382 BUG_ON(res.sr_bits != 1);
50383
50384 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
50385 cluster_start,
50386 num_clusters);
50387 if (!status)
50388 - atomic_inc(&osb->alloc_stats.local_data);
50389 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
50390 } else {
50391 if (min_clusters > (osb->bitmap_cpg - 1)) {
50392 /* The only paths asking for contiguousness
50393 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
50394 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
50395 res.sr_bg_blkno,
50396 res.sr_bit_offset);
50397 - atomic_inc(&osb->alloc_stats.bitmap_data);
50398 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
50399 *num_clusters = res.sr_bits;
50400 }
50401 }
50402 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
50403 index 0e91ec2..f4b3fc6 100644
50404 --- a/fs/ocfs2/super.c
50405 +++ b/fs/ocfs2/super.c
50406 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
50407 "%10s => GlobalAllocs: %d LocalAllocs: %d "
50408 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
50409 "Stats",
50410 - atomic_read(&osb->alloc_stats.bitmap_data),
50411 - atomic_read(&osb->alloc_stats.local_data),
50412 - atomic_read(&osb->alloc_stats.bg_allocs),
50413 - atomic_read(&osb->alloc_stats.moves),
50414 - atomic_read(&osb->alloc_stats.bg_extends));
50415 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
50416 + atomic_read_unchecked(&osb->alloc_stats.local_data),
50417 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
50418 + atomic_read_unchecked(&osb->alloc_stats.moves),
50419 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
50420
50421 out += snprintf(buf + out, len - out,
50422 "%10s => State: %u Descriptor: %llu Size: %u bits "
50423 @@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
50424 spin_lock_init(&osb->osb_xattr_lock);
50425 ocfs2_init_steal_slots(osb);
50426
50427 - atomic_set(&osb->alloc_stats.moves, 0);
50428 - atomic_set(&osb->alloc_stats.local_data, 0);
50429 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
50430 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
50431 - atomic_set(&osb->alloc_stats.bg_extends, 0);
50432 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
50433 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
50434 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
50435 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
50436 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
50437
50438 /* Copy the blockcheck stats from the superblock probe */
50439 osb->osb_ecc_stats = *stats;
50440 diff --git a/fs/open.c b/fs/open.c
50441 index 59071f5..c6229a0 100644
50442 --- a/fs/open.c
50443 +++ b/fs/open.c
50444 @@ -31,6 +31,8 @@
50445 #include <linux/ima.h>
50446 #include <linux/dnotify.h>
50447
50448 +#define CREATE_TRACE_POINTS
50449 +#include <trace/events/fs.h>
50450 #include "internal.h"
50451
50452 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
50453 @@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
50454 error = locks_verify_truncate(inode, NULL, length);
50455 if (!error)
50456 error = security_path_truncate(&path);
50457 +
50458 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
50459 + error = -EACCES;
50460 +
50461 if (!error)
50462 error = do_truncate(path.dentry, length, 0, NULL);
50463
50464 @@ -362,6 +368,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
50465 if (__mnt_is_readonly(path.mnt))
50466 res = -EROFS;
50467
50468 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
50469 + res = -EACCES;
50470 +
50471 out_path_release:
50472 path_put(&path);
50473 out:
50474 @@ -388,6 +397,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
50475 if (error)
50476 goto dput_and_out;
50477
50478 + gr_log_chdir(path.dentry, path.mnt);
50479 +
50480 set_fs_pwd(current->fs, &path);
50481
50482 dput_and_out:
50483 @@ -413,6 +424,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
50484 goto out_putf;
50485
50486 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
50487 +
50488 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
50489 + error = -EPERM;
50490 +
50491 + if (!error)
50492 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
50493 +
50494 if (!error)
50495 set_fs_pwd(current->fs, &f.file->f_path);
50496 out_putf:
50497 @@ -441,7 +459,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
50498 if (error)
50499 goto dput_and_out;
50500
50501 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
50502 + goto dput_and_out;
50503 +
50504 set_fs_root(current->fs, &path);
50505 +
50506 + gr_handle_chroot_chdir(&path);
50507 +
50508 error = 0;
50509 dput_and_out:
50510 path_put(&path);
50511 @@ -459,6 +483,16 @@ static int chmod_common(struct path *path, umode_t mode)
50512 if (error)
50513 return error;
50514 mutex_lock(&inode->i_mutex);
50515 +
50516 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
50517 + error = -EACCES;
50518 + goto out_unlock;
50519 + }
50520 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
50521 + error = -EACCES;
50522 + goto out_unlock;
50523 + }
50524 +
50525 error = security_path_chmod(path, mode);
50526 if (error)
50527 goto out_unlock;
50528 @@ -514,6 +548,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
50529 uid = make_kuid(current_user_ns(), user);
50530 gid = make_kgid(current_user_ns(), group);
50531
50532 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
50533 + return -EACCES;
50534 +
50535 newattrs.ia_valid = ATTR_CTIME;
50536 if (user != (uid_t) -1) {
50537 if (!uid_valid(uid))
50538 @@ -925,6 +962,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
50539 } else {
50540 fsnotify_open(f);
50541 fd_install(fd, f);
50542 + trace_do_sys_open(tmp->name, flags, mode);
50543 }
50544 }
50545 putname(tmp);
50546 diff --git a/fs/pipe.c b/fs/pipe.c
50547 index bd3479d..fb92c4d 100644
50548 --- a/fs/pipe.c
50549 +++ b/fs/pipe.c
50550 @@ -438,9 +438,9 @@ redo:
50551 }
50552 if (bufs) /* More to do? */
50553 continue;
50554 - if (!pipe->writers)
50555 + if (!atomic_read(&pipe->writers))
50556 break;
50557 - if (!pipe->waiting_writers) {
50558 + if (!atomic_read(&pipe->waiting_writers)) {
50559 /* syscall merging: Usually we must not sleep
50560 * if O_NONBLOCK is set, or if we got some data.
50561 * But if a writer sleeps in kernel space, then
50562 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
50563 mutex_lock(&inode->i_mutex);
50564 pipe = inode->i_pipe;
50565
50566 - if (!pipe->readers) {
50567 + if (!atomic_read(&pipe->readers)) {
50568 send_sig(SIGPIPE, current, 0);
50569 ret = -EPIPE;
50570 goto out;
50571 @@ -553,7 +553,7 @@ redo1:
50572 for (;;) {
50573 int bufs;
50574
50575 - if (!pipe->readers) {
50576 + if (!atomic_read(&pipe->readers)) {
50577 send_sig(SIGPIPE, current, 0);
50578 if (!ret)
50579 ret = -EPIPE;
50580 @@ -644,9 +644,9 @@ redo2:
50581 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
50582 do_wakeup = 0;
50583 }
50584 - pipe->waiting_writers++;
50585 + atomic_inc(&pipe->waiting_writers);
50586 pipe_wait(pipe);
50587 - pipe->waiting_writers--;
50588 + atomic_dec(&pipe->waiting_writers);
50589 }
50590 out:
50591 mutex_unlock(&inode->i_mutex);
50592 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
50593 mask = 0;
50594 if (filp->f_mode & FMODE_READ) {
50595 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
50596 - if (!pipe->writers && filp->f_version != pipe->w_counter)
50597 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
50598 mask |= POLLHUP;
50599 }
50600
50601 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
50602 * Most Unices do not set POLLERR for FIFOs but on Linux they
50603 * behave exactly like pipes for poll().
50604 */
50605 - if (!pipe->readers)
50606 + if (!atomic_read(&pipe->readers))
50607 mask |= POLLERR;
50608 }
50609
50610 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
50611
50612 mutex_lock(&inode->i_mutex);
50613 pipe = inode->i_pipe;
50614 - pipe->readers -= decr;
50615 - pipe->writers -= decw;
50616 + atomic_sub(decr, &pipe->readers);
50617 + atomic_sub(decw, &pipe->writers);
50618
50619 - if (!pipe->readers && !pipe->writers) {
50620 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
50621 free_pipe_info(inode);
50622 } else {
50623 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
50624 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
50625
50626 if (inode->i_pipe) {
50627 ret = 0;
50628 - inode->i_pipe->readers++;
50629 + atomic_inc(&inode->i_pipe->readers);
50630 }
50631
50632 mutex_unlock(&inode->i_mutex);
50633 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
50634
50635 if (inode->i_pipe) {
50636 ret = 0;
50637 - inode->i_pipe->writers++;
50638 + atomic_inc(&inode->i_pipe->writers);
50639 }
50640
50641 mutex_unlock(&inode->i_mutex);
50642 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
50643 if (inode->i_pipe) {
50644 ret = 0;
50645 if (filp->f_mode & FMODE_READ)
50646 - inode->i_pipe->readers++;
50647 + atomic_inc(&inode->i_pipe->readers);
50648 if (filp->f_mode & FMODE_WRITE)
50649 - inode->i_pipe->writers++;
50650 + atomic_inc(&inode->i_pipe->writers);
50651 }
50652
50653 mutex_unlock(&inode->i_mutex);
50654 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
50655 inode->i_pipe = NULL;
50656 }
50657
50658 -static struct vfsmount *pipe_mnt __read_mostly;
50659 +struct vfsmount *pipe_mnt __read_mostly;
50660
50661 /*
50662 * pipefs_dname() is called from d_path().
50663 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
50664 goto fail_iput;
50665 inode->i_pipe = pipe;
50666
50667 - pipe->readers = pipe->writers = 1;
50668 + atomic_set(&pipe->readers, 1);
50669 + atomic_set(&pipe->writers, 1);
50670 inode->i_fop = &rdwr_pipefifo_fops;
50671
50672 /*
50673 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
50674 index 15af622..0e9f4467 100644
50675 --- a/fs/proc/Kconfig
50676 +++ b/fs/proc/Kconfig
50677 @@ -30,12 +30,12 @@ config PROC_FS
50678
50679 config PROC_KCORE
50680 bool "/proc/kcore support" if !ARM
50681 - depends on PROC_FS && MMU
50682 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
50683
50684 config PROC_VMCORE
50685 bool "/proc/vmcore support"
50686 - depends on PROC_FS && CRASH_DUMP
50687 - default y
50688 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
50689 + default n
50690 help
50691 Exports the dump image of crashed kernel in ELF format.
50692
50693 @@ -59,8 +59,8 @@ config PROC_SYSCTL
50694 limited in memory.
50695
50696 config PROC_PAGE_MONITOR
50697 - default y
50698 - depends on PROC_FS && MMU
50699 + default n
50700 + depends on PROC_FS && MMU && !GRKERNSEC
50701 bool "Enable /proc page monitoring" if EXPERT
50702 help
50703 Various /proc files exist to monitor process memory utilization:
50704 diff --git a/fs/proc/array.c b/fs/proc/array.c
50705 index bd31e02..15cae71 100644
50706 --- a/fs/proc/array.c
50707 +++ b/fs/proc/array.c
50708 @@ -60,6 +60,7 @@
50709 #include <linux/tty.h>
50710 #include <linux/string.h>
50711 #include <linux/mman.h>
50712 +#include <linux/grsecurity.h>
50713 #include <linux/proc_fs.h>
50714 #include <linux/ioport.h>
50715 #include <linux/uaccess.h>
50716 @@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
50717 seq_putc(m, '\n');
50718 }
50719
50720 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
50721 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
50722 +{
50723 + if (p->mm)
50724 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
50725 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
50726 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
50727 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
50728 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
50729 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
50730 + else
50731 + seq_printf(m, "PaX:\t-----\n");
50732 +}
50733 +#endif
50734 +
50735 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
50736 struct pid *pid, struct task_struct *task)
50737 {
50738 @@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
50739 task_cpus_allowed(m, task);
50740 cpuset_task_status_allowed(m, task);
50741 task_context_switch_counts(m, task);
50742 +
50743 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
50744 + task_pax(m, task);
50745 +#endif
50746 +
50747 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
50748 + task_grsec_rbac(m, task);
50749 +#endif
50750 +
50751 return 0;
50752 }
50753
50754 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50755 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
50756 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
50757 + _mm->pax_flags & MF_PAX_SEGMEXEC))
50758 +#endif
50759 +
50760 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50761 struct pid *pid, struct task_struct *task, int whole)
50762 {
50763 @@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50764 char tcomm[sizeof(task->comm)];
50765 unsigned long flags;
50766
50767 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50768 + if (current->exec_id != m->exec_id) {
50769 + gr_log_badprocpid("stat");
50770 + return 0;
50771 + }
50772 +#endif
50773 +
50774 state = *get_task_state(task);
50775 vsize = eip = esp = 0;
50776 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
50777 @@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50778 gtime = task->gtime;
50779 }
50780
50781 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50782 + if (PAX_RAND_FLAGS(mm)) {
50783 + eip = 0;
50784 + esp = 0;
50785 + wchan = 0;
50786 + }
50787 +#endif
50788 +#ifdef CONFIG_GRKERNSEC_HIDESYM
50789 + wchan = 0;
50790 + eip =0;
50791 + esp =0;
50792 +#endif
50793 +
50794 /* scale priority and nice values from timeslices to -20..20 */
50795 /* to make it look like a "normal" Unix priority/nice value */
50796 priority = task_prio(task);
50797 @@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50798 seq_put_decimal_ull(m, ' ', vsize);
50799 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
50800 seq_put_decimal_ull(m, ' ', rsslim);
50801 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50802 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
50803 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
50804 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
50805 +#else
50806 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
50807 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
50808 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
50809 +#endif
50810 seq_put_decimal_ull(m, ' ', esp);
50811 seq_put_decimal_ull(m, ' ', eip);
50812 /* The signal information here is obsolete.
50813 @@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50814 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
50815 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
50816
50817 - if (mm && permitted) {
50818 + if (mm && permitted
50819 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50820 + && !PAX_RAND_FLAGS(mm)
50821 +#endif
50822 + ) {
50823 seq_put_decimal_ull(m, ' ', mm->start_data);
50824 seq_put_decimal_ull(m, ' ', mm->end_data);
50825 seq_put_decimal_ull(m, ' ', mm->start_brk);
50826 @@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
50827 struct pid *pid, struct task_struct *task)
50828 {
50829 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
50830 - struct mm_struct *mm = get_task_mm(task);
50831 + struct mm_struct *mm;
50832
50833 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50834 + if (current->exec_id != m->exec_id) {
50835 + gr_log_badprocpid("statm");
50836 + return 0;
50837 + }
50838 +#endif
50839 + mm = get_task_mm(task);
50840 if (mm) {
50841 size = task_statm(mm, &shared, &text, &data, &resident);
50842 mmput(mm);
50843 @@ -580,6 +648,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
50844 return 0;
50845 }
50846
50847 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
50848 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
50849 +{
50850 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
50851 +}
50852 +#endif
50853 +
50854 #ifdef CONFIG_CHECKPOINT_RESTORE
50855 static struct pid *
50856 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
50857 diff --git a/fs/proc/base.c b/fs/proc/base.c
50858 index 9e28356..c485b3c 100644
50859 --- a/fs/proc/base.c
50860 +++ b/fs/proc/base.c
50861 @@ -111,6 +111,14 @@ struct pid_entry {
50862 union proc_op op;
50863 };
50864
50865 +struct getdents_callback {
50866 + struct linux_dirent __user * current_dir;
50867 + struct linux_dirent __user * previous;
50868 + struct file * file;
50869 + int count;
50870 + int error;
50871 +};
50872 +
50873 #define NOD(NAME, MODE, IOP, FOP, OP) { \
50874 .name = (NAME), \
50875 .len = sizeof(NAME) - 1, \
50876 @@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
50877 if (!mm->arg_end)
50878 goto out_mm; /* Shh! No looking before we're done */
50879
50880 + if (gr_acl_handle_procpidmem(task))
50881 + goto out_mm;
50882 +
50883 len = mm->arg_end - mm->arg_start;
50884
50885 if (len > PAGE_SIZE)
50886 @@ -235,12 +246,28 @@ out:
50887 return res;
50888 }
50889
50890 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50891 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
50892 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
50893 + _mm->pax_flags & MF_PAX_SEGMEXEC))
50894 +#endif
50895 +
50896 static int proc_pid_auxv(struct task_struct *task, char *buffer)
50897 {
50898 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
50899 int res = PTR_ERR(mm);
50900 if (mm && !IS_ERR(mm)) {
50901 unsigned int nwords = 0;
50902 +
50903 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50904 + /* allow if we're currently ptracing this task */
50905 + if (PAX_RAND_FLAGS(mm) &&
50906 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
50907 + mmput(mm);
50908 + return 0;
50909 + }
50910 +#endif
50911 +
50912 do {
50913 nwords += 2;
50914 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
50915 @@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
50916 }
50917
50918
50919 -#ifdef CONFIG_KALLSYMS
50920 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50921 /*
50922 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
50923 * Returns the resolved symbol. If that fails, simply return the address.
50924 @@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
50925 mutex_unlock(&task->signal->cred_guard_mutex);
50926 }
50927
50928 -#ifdef CONFIG_STACKTRACE
50929 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50930
50931 #define MAX_STACK_TRACE_DEPTH 64
50932
50933 @@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
50934 return count;
50935 }
50936
50937 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
50938 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
50939 static int proc_pid_syscall(struct task_struct *task, char *buffer)
50940 {
50941 long nr;
50942 @@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
50943 /************************************************************************/
50944
50945 /* permission checks */
50946 -static int proc_fd_access_allowed(struct inode *inode)
50947 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
50948 {
50949 struct task_struct *task;
50950 int allowed = 0;
50951 @@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
50952 */
50953 task = get_proc_task(inode);
50954 if (task) {
50955 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
50956 + if (log)
50957 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
50958 + else
50959 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
50960 put_task_struct(task);
50961 }
50962 return allowed;
50963 @@ -562,10 +592,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
50964 struct task_struct *task,
50965 int hide_pid_min)
50966 {
50967 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
50968 + return false;
50969 +
50970 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50971 + rcu_read_lock();
50972 + {
50973 + const struct cred *tmpcred = current_cred();
50974 + const struct cred *cred = __task_cred(task);
50975 +
50976 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
50977 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50978 + || in_group_p(grsec_proc_gid)
50979 +#endif
50980 + ) {
50981 + rcu_read_unlock();
50982 + return true;
50983 + }
50984 + }
50985 + rcu_read_unlock();
50986 +
50987 + if (!pid->hide_pid)
50988 + return false;
50989 +#endif
50990 +
50991 if (pid->hide_pid < hide_pid_min)
50992 return true;
50993 if (in_group_p(pid->pid_gid))
50994 return true;
50995 +
50996 return ptrace_may_access(task, PTRACE_MODE_READ);
50997 }
50998
50999 @@ -583,7 +638,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
51000 put_task_struct(task);
51001
51002 if (!has_perms) {
51003 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51004 + {
51005 +#else
51006 if (pid->hide_pid == 2) {
51007 +#endif
51008 /*
51009 * Let's make getdents(), stat(), and open()
51010 * consistent with each other. If a process
51011 @@ -681,6 +740,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
51012 if (!task)
51013 return -ESRCH;
51014
51015 + if (gr_acl_handle_procpidmem(task)) {
51016 + put_task_struct(task);
51017 + return -EPERM;
51018 + }
51019 +
51020 mm = mm_access(task, mode);
51021 put_task_struct(task);
51022
51023 @@ -696,6 +760,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
51024
51025 file->private_data = mm;
51026
51027 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51028 + file->f_version = current->exec_id;
51029 +#endif
51030 +
51031 return 0;
51032 }
51033
51034 @@ -717,6 +785,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
51035 ssize_t copied;
51036 char *page;
51037
51038 +#ifdef CONFIG_GRKERNSEC
51039 + if (write)
51040 + return -EPERM;
51041 +#endif
51042 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51043 + if (file->f_version != current->exec_id) {
51044 + gr_log_badprocpid("mem");
51045 + return 0;
51046 + }
51047 +#endif
51048 +
51049 if (!mm)
51050 return 0;
51051
51052 @@ -821,6 +900,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
51053 if (!mm)
51054 return 0;
51055
51056 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51057 + if (file->f_version != current->exec_id) {
51058 + gr_log_badprocpid("environ");
51059 + return 0;
51060 + }
51061 +#endif
51062 +
51063 page = (char *)__get_free_page(GFP_TEMPORARY);
51064 if (!page)
51065 return -ENOMEM;
51066 @@ -1436,7 +1522,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
51067 int error = -EACCES;
51068
51069 /* Are we allowed to snoop on the tasks file descriptors? */
51070 - if (!proc_fd_access_allowed(inode))
51071 + if (!proc_fd_access_allowed(inode, 0))
51072 goto out;
51073
51074 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
51075 @@ -1480,8 +1566,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
51076 struct path path;
51077
51078 /* Are we allowed to snoop on the tasks file descriptors? */
51079 - if (!proc_fd_access_allowed(inode))
51080 - goto out;
51081 + /* logging this is needed for learning on chromium to work properly,
51082 + but we don't want to flood the logs from 'ps' which does a readlink
51083 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
51084 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
51085 + */
51086 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
51087 + if (!proc_fd_access_allowed(inode,0))
51088 + goto out;
51089 + } else {
51090 + if (!proc_fd_access_allowed(inode,1))
51091 + goto out;
51092 + }
51093
51094 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
51095 if (error)
51096 @@ -1531,7 +1627,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
51097 rcu_read_lock();
51098 cred = __task_cred(task);
51099 inode->i_uid = cred->euid;
51100 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51101 + inode->i_gid = grsec_proc_gid;
51102 +#else
51103 inode->i_gid = cred->egid;
51104 +#endif
51105 rcu_read_unlock();
51106 }
51107 security_task_to_inode(task, inode);
51108 @@ -1567,10 +1667,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
51109 return -ENOENT;
51110 }
51111 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
51112 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51113 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
51114 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51115 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
51116 +#endif
51117 task_dumpable(task)) {
51118 cred = __task_cred(task);
51119 stat->uid = cred->euid;
51120 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51121 + stat->gid = grsec_proc_gid;
51122 +#else
51123 stat->gid = cred->egid;
51124 +#endif
51125 }
51126 }
51127 rcu_read_unlock();
51128 @@ -1608,11 +1717,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
51129
51130 if (task) {
51131 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
51132 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51133 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
51134 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51135 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
51136 +#endif
51137 task_dumpable(task)) {
51138 rcu_read_lock();
51139 cred = __task_cred(task);
51140 inode->i_uid = cred->euid;
51141 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51142 + inode->i_gid = grsec_proc_gid;
51143 +#else
51144 inode->i_gid = cred->egid;
51145 +#endif
51146 rcu_read_unlock();
51147 } else {
51148 inode->i_uid = GLOBAL_ROOT_UID;
51149 @@ -2065,6 +2183,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
51150 if (!task)
51151 goto out_no_task;
51152
51153 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51154 + goto out;
51155 +
51156 /*
51157 * Yes, it does not scale. And it should not. Don't add
51158 * new entries into /proc/<tgid>/ without very good reasons.
51159 @@ -2109,6 +2230,9 @@ static int proc_pident_readdir(struct file *filp,
51160 if (!task)
51161 goto out_no_task;
51162
51163 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51164 + goto out;
51165 +
51166 ret = 0;
51167 i = filp->f_pos;
51168 switch (i) {
51169 @@ -2380,7 +2504,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
51170 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
51171 void *cookie)
51172 {
51173 - char *s = nd_get_link(nd);
51174 + const char *s = nd_get_link(nd);
51175 if (!IS_ERR(s))
51176 kfree(s);
51177 }
51178 @@ -2662,7 +2786,7 @@ static const struct pid_entry tgid_base_stuff[] = {
51179 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
51180 #endif
51181 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
51182 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
51183 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51184 INF("syscall", S_IRUGO, proc_pid_syscall),
51185 #endif
51186 INF("cmdline", S_IRUGO, proc_pid_cmdline),
51187 @@ -2687,10 +2811,10 @@ static const struct pid_entry tgid_base_stuff[] = {
51188 #ifdef CONFIG_SECURITY
51189 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
51190 #endif
51191 -#ifdef CONFIG_KALLSYMS
51192 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51193 INF("wchan", S_IRUGO, proc_pid_wchan),
51194 #endif
51195 -#ifdef CONFIG_STACKTRACE
51196 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51197 ONE("stack", S_IRUGO, proc_pid_stack),
51198 #endif
51199 #ifdef CONFIG_SCHEDSTATS
51200 @@ -2724,6 +2848,9 @@ static const struct pid_entry tgid_base_stuff[] = {
51201 #ifdef CONFIG_HARDWALL
51202 INF("hardwall", S_IRUGO, proc_pid_hardwall),
51203 #endif
51204 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
51205 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
51206 +#endif
51207 #ifdef CONFIG_USER_NS
51208 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
51209 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
51210 @@ -2856,7 +2983,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
51211 if (!inode)
51212 goto out;
51213
51214 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51215 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
51216 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51217 + inode->i_gid = grsec_proc_gid;
51218 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
51219 +#else
51220 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
51221 +#endif
51222 inode->i_op = &proc_tgid_base_inode_operations;
51223 inode->i_fop = &proc_tgid_base_operations;
51224 inode->i_flags|=S_IMMUTABLE;
51225 @@ -2898,7 +3032,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
51226 if (!task)
51227 goto out;
51228
51229 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51230 + goto out_put_task;
51231 +
51232 result = proc_pid_instantiate(dir, dentry, task, NULL);
51233 +out_put_task:
51234 put_task_struct(task);
51235 out:
51236 return result;
51237 @@ -2961,6 +3099,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
51238 static int fake_filldir(void *buf, const char *name, int namelen,
51239 loff_t offset, u64 ino, unsigned d_type)
51240 {
51241 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
51242 + __buf->error = -EINVAL;
51243 return 0;
51244 }
51245
51246 @@ -3027,7 +3167,7 @@ static const struct pid_entry tid_base_stuff[] = {
51247 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
51248 #endif
51249 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
51250 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
51251 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51252 INF("syscall", S_IRUGO, proc_pid_syscall),
51253 #endif
51254 INF("cmdline", S_IRUGO, proc_pid_cmdline),
51255 @@ -3054,10 +3194,10 @@ static const struct pid_entry tid_base_stuff[] = {
51256 #ifdef CONFIG_SECURITY
51257 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
51258 #endif
51259 -#ifdef CONFIG_KALLSYMS
51260 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51261 INF("wchan", S_IRUGO, proc_pid_wchan),
51262 #endif
51263 -#ifdef CONFIG_STACKTRACE
51264 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51265 ONE("stack", S_IRUGO, proc_pid_stack),
51266 #endif
51267 #ifdef CONFIG_SCHEDSTATS
51268 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
51269 index 82676e3..5f8518a 100644
51270 --- a/fs/proc/cmdline.c
51271 +++ b/fs/proc/cmdline.c
51272 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
51273
51274 static int __init proc_cmdline_init(void)
51275 {
51276 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
51277 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
51278 +#else
51279 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
51280 +#endif
51281 return 0;
51282 }
51283 module_init(proc_cmdline_init);
51284 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
51285 index b143471..bb105e5 100644
51286 --- a/fs/proc/devices.c
51287 +++ b/fs/proc/devices.c
51288 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
51289
51290 static int __init proc_devices_init(void)
51291 {
51292 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
51293 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
51294 +#else
51295 proc_create("devices", 0, NULL, &proc_devinfo_operations);
51296 +#endif
51297 return 0;
51298 }
51299 module_init(proc_devices_init);
51300 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
51301 index f28a875..c467953 100644
51302 --- a/fs/proc/fd.c
51303 +++ b/fs/proc/fd.c
51304 @@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
51305 if (!task)
51306 return -ENOENT;
51307
51308 - files = get_files_struct(task);
51309 + if (!gr_acl_handle_procpidmem(task))
51310 + files = get_files_struct(task);
51311 put_task_struct(task);
51312
51313 if (files) {
51314 @@ -300,11 +301,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
51315 */
51316 int proc_fd_permission(struct inode *inode, int mask)
51317 {
51318 + struct task_struct *task;
51319 int rv = generic_permission(inode, mask);
51320 - if (rv == 0)
51321 - return 0;
51322 +
51323 if (task_pid(current) == proc_pid(inode))
51324 rv = 0;
51325 +
51326 + task = get_proc_task(inode);
51327 + if (task == NULL)
51328 + return rv;
51329 +
51330 + if (gr_acl_handle_procpidmem(task))
51331 + rv = -EACCES;
51332 +
51333 + put_task_struct(task);
51334 +
51335 return rv;
51336 }
51337
51338 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
51339 index 3b22bbd..895b58c 100644
51340 --- a/fs/proc/inode.c
51341 +++ b/fs/proc/inode.c
51342 @@ -21,11 +21,17 @@
51343 #include <linux/seq_file.h>
51344 #include <linux/slab.h>
51345 #include <linux/mount.h>
51346 +#include <linux/grsecurity.h>
51347
51348 #include <asm/uaccess.h>
51349
51350 #include "internal.h"
51351
51352 +#ifdef CONFIG_PROC_SYSCTL
51353 +extern const struct inode_operations proc_sys_inode_operations;
51354 +extern const struct inode_operations proc_sys_dir_operations;
51355 +#endif
51356 +
51357 static void proc_evict_inode(struct inode *inode)
51358 {
51359 struct proc_dir_entry *de;
51360 @@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
51361 ns_ops = PROC_I(inode)->ns_ops;
51362 if (ns_ops && ns_ops->put)
51363 ns_ops->put(PROC_I(inode)->ns);
51364 +
51365 +#ifdef CONFIG_PROC_SYSCTL
51366 + if (inode->i_op == &proc_sys_inode_operations ||
51367 + inode->i_op == &proc_sys_dir_operations)
51368 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
51369 +#endif
51370 +
51371 }
51372
51373 static struct kmem_cache * proc_inode_cachep;
51374 @@ -455,7 +468,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
51375 if (de->mode) {
51376 inode->i_mode = de->mode;
51377 inode->i_uid = de->uid;
51378 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51379 + inode->i_gid = grsec_proc_gid;
51380 +#else
51381 inode->i_gid = de->gid;
51382 +#endif
51383 }
51384 if (de->size)
51385 inode->i_size = de->size;
51386 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
51387 index 43973b0..a20e704 100644
51388 --- a/fs/proc/internal.h
51389 +++ b/fs/proc/internal.h
51390 @@ -54,6 +54,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
51391 struct pid *pid, struct task_struct *task);
51392 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
51393 struct pid *pid, struct task_struct *task);
51394 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
51395 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
51396 +#endif
51397 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
51398
51399 extern const struct file_operations proc_tid_children_operations;
51400 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
51401 index 86c67ee..cdca321 100644
51402 --- a/fs/proc/kcore.c
51403 +++ b/fs/proc/kcore.c
51404 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
51405 * the addresses in the elf_phdr on our list.
51406 */
51407 start = kc_offset_to_vaddr(*fpos - elf_buflen);
51408 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
51409 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
51410 + if (tsz > buflen)
51411 tsz = buflen;
51412 -
51413 +
51414 while (buflen) {
51415 struct kcore_list *m;
51416
51417 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
51418 kfree(elf_buf);
51419 } else {
51420 if (kern_addr_valid(start)) {
51421 - unsigned long n;
51422 + char *elf_buf;
51423 + mm_segment_t oldfs;
51424
51425 - n = copy_to_user(buffer, (char *)start, tsz);
51426 - /*
51427 - * We cannot distinguish between fault on source
51428 - * and fault on destination. When this happens
51429 - * we clear too and hope it will trigger the
51430 - * EFAULT again.
51431 - */
51432 - if (n) {
51433 - if (clear_user(buffer + tsz - n,
51434 - n))
51435 + elf_buf = kmalloc(tsz, GFP_KERNEL);
51436 + if (!elf_buf)
51437 + return -ENOMEM;
51438 + oldfs = get_fs();
51439 + set_fs(KERNEL_DS);
51440 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
51441 + set_fs(oldfs);
51442 + if (copy_to_user(buffer, elf_buf, tsz)) {
51443 + kfree(elf_buf);
51444 return -EFAULT;
51445 + }
51446 }
51447 + set_fs(oldfs);
51448 + kfree(elf_buf);
51449 } else {
51450 if (clear_user(buffer, tsz))
51451 return -EFAULT;
51452 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
51453
51454 static int open_kcore(struct inode *inode, struct file *filp)
51455 {
51456 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
51457 + return -EPERM;
51458 +#endif
51459 if (!capable(CAP_SYS_RAWIO))
51460 return -EPERM;
51461 if (kcore_need_update)
51462 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
51463 index 80e4645..53e5fcf 100644
51464 --- a/fs/proc/meminfo.c
51465 +++ b/fs/proc/meminfo.c
51466 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
51467 vmi.used >> 10,
51468 vmi.largest_chunk >> 10
51469 #ifdef CONFIG_MEMORY_FAILURE
51470 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
51471 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
51472 #endif
51473 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
51474 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
51475 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
51476 index b1822dd..df622cb 100644
51477 --- a/fs/proc/nommu.c
51478 +++ b/fs/proc/nommu.c
51479 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
51480 if (len < 1)
51481 len = 1;
51482 seq_printf(m, "%*c", len, ' ');
51483 - seq_path(m, &file->f_path, "");
51484 + seq_path(m, &file->f_path, "\n\\");
51485 }
51486
51487 seq_putc(m, '\n');
51488 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
51489 index fe72cd0..cb9b67d 100644
51490 --- a/fs/proc/proc_net.c
51491 +++ b/fs/proc/proc_net.c
51492 @@ -23,6 +23,7 @@
51493 #include <linux/nsproxy.h>
51494 #include <net/net_namespace.h>
51495 #include <linux/seq_file.h>
51496 +#include <linux/grsecurity.h>
51497
51498 #include "internal.h"
51499
51500 @@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
51501 struct task_struct *task;
51502 struct nsproxy *ns;
51503 struct net *net = NULL;
51504 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51505 + const struct cred *cred = current_cred();
51506 +#endif
51507 +
51508 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51509 + if (cred->fsuid)
51510 + return net;
51511 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51512 + if (cred->fsuid && !in_group_p(grsec_proc_gid))
51513 + return net;
51514 +#endif
51515
51516 rcu_read_lock();
51517 task = pid_task(proc_pid(dir), PIDTYPE_PID);
51518 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
51519 index a781bdf..6665284 100644
51520 --- a/fs/proc/proc_sysctl.c
51521 +++ b/fs/proc/proc_sysctl.c
51522 @@ -12,11 +12,15 @@
51523 #include <linux/module.h>
51524 #include "internal.h"
51525
51526 +extern int gr_handle_chroot_sysctl(const int op);
51527 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
51528 + const int op);
51529 +
51530 static const struct dentry_operations proc_sys_dentry_operations;
51531 static const struct file_operations proc_sys_file_operations;
51532 -static const struct inode_operations proc_sys_inode_operations;
51533 +const struct inode_operations proc_sys_inode_operations;
51534 static const struct file_operations proc_sys_dir_file_operations;
51535 -static const struct inode_operations proc_sys_dir_operations;
51536 +const struct inode_operations proc_sys_dir_operations;
51537
51538 void proc_sys_poll_notify(struct ctl_table_poll *poll)
51539 {
51540 @@ -465,6 +469,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
51541
51542 err = NULL;
51543 d_set_d_op(dentry, &proc_sys_dentry_operations);
51544 +
51545 + gr_handle_proc_create(dentry, inode);
51546 +
51547 d_add(dentry, inode);
51548
51549 out:
51550 @@ -480,18 +487,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
51551 struct inode *inode = filp->f_path.dentry->d_inode;
51552 struct ctl_table_header *head = grab_header(inode);
51553 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
51554 + int op = write ? MAY_WRITE : MAY_READ;
51555 ssize_t error;
51556 size_t res;
51557
51558 if (IS_ERR(head))
51559 return PTR_ERR(head);
51560
51561 +
51562 /*
51563 * At this point we know that the sysctl was not unregistered
51564 * and won't be until we finish.
51565 */
51566 error = -EPERM;
51567 - if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
51568 + if (sysctl_perm(head->root, table, op))
51569 goto out;
51570
51571 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
51572 @@ -499,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
51573 if (!table->proc_handler)
51574 goto out;
51575
51576 +#ifdef CONFIG_GRKERNSEC
51577 + error = -EPERM;
51578 + if (gr_handle_chroot_sysctl(op))
51579 + goto out;
51580 + dget(filp->f_path.dentry);
51581 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
51582 + dput(filp->f_path.dentry);
51583 + goto out;
51584 + }
51585 + dput(filp->f_path.dentry);
51586 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
51587 + goto out;
51588 + if (write && !capable(CAP_SYS_ADMIN))
51589 + goto out;
51590 +#endif
51591 +
51592 /* careful: calling conventions are nasty here */
51593 res = count;
51594 error = table->proc_handler(table, write, buf, &res, ppos);
51595 @@ -596,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
51596 return -ENOMEM;
51597 } else {
51598 d_set_d_op(child, &proc_sys_dentry_operations);
51599 +
51600 + gr_handle_proc_create(child, inode);
51601 +
51602 d_add(child, inode);
51603 }
51604 } else {
51605 @@ -639,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
51606 if ((*pos)++ < file->f_pos)
51607 return 0;
51608
51609 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
51610 + return 0;
51611 +
51612 if (unlikely(S_ISLNK(table->mode)))
51613 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
51614 else
51615 @@ -756,6 +787,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
51616 if (IS_ERR(head))
51617 return PTR_ERR(head);
51618
51619 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
51620 + return -ENOENT;
51621 +
51622 generic_fillattr(inode, stat);
51623 if (table)
51624 stat->mode = (stat->mode & S_IFMT) | table->mode;
51625 @@ -778,13 +812,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
51626 .llseek = generic_file_llseek,
51627 };
51628
51629 -static const struct inode_operations proc_sys_inode_operations = {
51630 +const struct inode_operations proc_sys_inode_operations = {
51631 .permission = proc_sys_permission,
51632 .setattr = proc_sys_setattr,
51633 .getattr = proc_sys_getattr,
51634 };
51635
51636 -static const struct inode_operations proc_sys_dir_operations = {
51637 +const struct inode_operations proc_sys_dir_operations = {
51638 .lookup = proc_sys_lookup,
51639 .permission = proc_sys_permission,
51640 .setattr = proc_sys_setattr,
51641 diff --git a/fs/proc/root.c b/fs/proc/root.c
51642 index 9889a92..2613b48 100644
51643 --- a/fs/proc/root.c
51644 +++ b/fs/proc/root.c
51645 @@ -187,7 +187,15 @@ void __init proc_root_init(void)
51646 #ifdef CONFIG_PROC_DEVICETREE
51647 proc_device_tree_init();
51648 #endif
51649 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
51650 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51651 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
51652 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51653 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
51654 +#endif
51655 +#else
51656 proc_mkdir("bus", NULL);
51657 +#endif
51658 proc_sys_init();
51659 }
51660
51661 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
51662 index 90c63f9..e662cfc 100644
51663 --- a/fs/proc/task_mmu.c
51664 +++ b/fs/proc/task_mmu.c
51665 @@ -11,12 +11,19 @@
51666 #include <linux/rmap.h>
51667 #include <linux/swap.h>
51668 #include <linux/swapops.h>
51669 +#include <linux/grsecurity.h>
51670
51671 #include <asm/elf.h>
51672 #include <asm/uaccess.h>
51673 #include <asm/tlbflush.h>
51674 #include "internal.h"
51675
51676 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51677 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
51678 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
51679 + _mm->pax_flags & MF_PAX_SEGMEXEC))
51680 +#endif
51681 +
51682 void task_mem(struct seq_file *m, struct mm_struct *mm)
51683 {
51684 unsigned long data, text, lib, swap;
51685 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
51686 "VmExe:\t%8lu kB\n"
51687 "VmLib:\t%8lu kB\n"
51688 "VmPTE:\t%8lu kB\n"
51689 - "VmSwap:\t%8lu kB\n",
51690 - hiwater_vm << (PAGE_SHIFT-10),
51691 + "VmSwap:\t%8lu kB\n"
51692 +
51693 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
51694 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
51695 +#endif
51696 +
51697 + ,hiwater_vm << (PAGE_SHIFT-10),
51698 total_vm << (PAGE_SHIFT-10),
51699 mm->locked_vm << (PAGE_SHIFT-10),
51700 mm->pinned_vm << (PAGE_SHIFT-10),
51701 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
51702 data << (PAGE_SHIFT-10),
51703 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
51704 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
51705 - swap << (PAGE_SHIFT-10));
51706 + swap << (PAGE_SHIFT-10)
51707 +
51708 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
51709 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51710 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
51711 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
51712 +#else
51713 + , mm->context.user_cs_base
51714 + , mm->context.user_cs_limit
51715 +#endif
51716 +#endif
51717 +
51718 + );
51719 }
51720
51721 unsigned long task_vsize(struct mm_struct *mm)
51722 @@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51723 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
51724 }
51725
51726 - /* We don't show the stack guard page in /proc/maps */
51727 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51728 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
51729 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
51730 +#else
51731 start = vma->vm_start;
51732 - if (stack_guard_page_start(vma, start))
51733 - start += PAGE_SIZE;
51734 end = vma->vm_end;
51735 - if (stack_guard_page_end(vma, end))
51736 - end -= PAGE_SIZE;
51737 +#endif
51738
51739 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
51740 start,
51741 @@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51742 flags & VM_WRITE ? 'w' : '-',
51743 flags & VM_EXEC ? 'x' : '-',
51744 flags & VM_MAYSHARE ? 's' : 'p',
51745 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51746 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
51747 +#else
51748 pgoff,
51749 +#endif
51750 MAJOR(dev), MINOR(dev), ino, &len);
51751
51752 /*
51753 @@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51754 */
51755 if (file) {
51756 pad_len_spaces(m, len);
51757 - seq_path(m, &file->f_path, "\n");
51758 + seq_path(m, &file->f_path, "\n\\");
51759 goto done;
51760 }
51761
51762 @@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51763 * Thread stack in /proc/PID/task/TID/maps or
51764 * the main process stack.
51765 */
51766 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
51767 - vma->vm_end >= mm->start_stack)) {
51768 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
51769 + (vma->vm_start <= mm->start_stack &&
51770 + vma->vm_end >= mm->start_stack)) {
51771 name = "[stack]";
51772 } else {
51773 /* Thread stack in /proc/PID/maps */
51774 @@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
51775 struct proc_maps_private *priv = m->private;
51776 struct task_struct *task = priv->task;
51777
51778 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51779 + if (current->exec_id != m->exec_id) {
51780 + gr_log_badprocpid("maps");
51781 + return 0;
51782 + }
51783 +#endif
51784 +
51785 show_map_vma(m, vma, is_pid);
51786
51787 if (m->count < m->size) /* vma is copied successfully */
51788 @@ -538,12 +574,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
51789 .private = &mss,
51790 };
51791
51792 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51793 + if (current->exec_id != m->exec_id) {
51794 + gr_log_badprocpid("smaps");
51795 + return 0;
51796 + }
51797 +#endif
51798 memset(&mss, 0, sizeof mss);
51799 - mss.vma = vma;
51800 - /* mmap_sem is held in m_start */
51801 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
51802 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
51803 -
51804 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51805 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
51806 +#endif
51807 + mss.vma = vma;
51808 + /* mmap_sem is held in m_start */
51809 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
51810 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
51811 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51812 + }
51813 +#endif
51814 show_map_vma(m, vma, is_pid);
51815
51816 seq_printf(m,
51817 @@ -561,7 +608,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
51818 "KernelPageSize: %8lu kB\n"
51819 "MMUPageSize: %8lu kB\n"
51820 "Locked: %8lu kB\n",
51821 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51822 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
51823 +#else
51824 (vma->vm_end - vma->vm_start) >> 10,
51825 +#endif
51826 mss.resident >> 10,
51827 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
51828 mss.shared_clean >> 10,
51829 @@ -1211,6 +1262,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
51830 int n;
51831 char buffer[50];
51832
51833 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51834 + if (current->exec_id != m->exec_id) {
51835 + gr_log_badprocpid("numa_maps");
51836 + return 0;
51837 + }
51838 +#endif
51839 +
51840 if (!mm)
51841 return 0;
51842
51843 @@ -1228,11 +1286,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
51844 mpol_to_str(buffer, sizeof(buffer), pol, 0);
51845 mpol_cond_put(pol);
51846
51847 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51848 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
51849 +#else
51850 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
51851 +#endif
51852
51853 if (file) {
51854 seq_printf(m, " file=");
51855 - seq_path(m, &file->f_path, "\n\t= ");
51856 + seq_path(m, &file->f_path, "\n\t\\= ");
51857 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
51858 seq_printf(m, " heap");
51859 } else {
51860 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
51861 index 1ccfa53..0848f95 100644
51862 --- a/fs/proc/task_nommu.c
51863 +++ b/fs/proc/task_nommu.c
51864 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
51865 else
51866 bytes += kobjsize(mm);
51867
51868 - if (current->fs && current->fs->users > 1)
51869 + if (current->fs && atomic_read(&current->fs->users) > 1)
51870 sbytes += kobjsize(current->fs);
51871 else
51872 bytes += kobjsize(current->fs);
51873 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
51874
51875 if (file) {
51876 pad_len_spaces(m, len);
51877 - seq_path(m, &file->f_path, "");
51878 + seq_path(m, &file->f_path, "\n\\");
51879 } else if (mm) {
51880 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
51881
51882 diff --git a/fs/pstore/ftrace.c b/fs/pstore/ftrace.c
51883 index 2d57e1a..43b1280 100644
51884 --- a/fs/pstore/ftrace.c
51885 +++ b/fs/pstore/ftrace.c
51886 @@ -28,7 +28,9 @@
51887 #include "internal.h"
51888
51889 static void notrace pstore_ftrace_call(unsigned long ip,
51890 - unsigned long parent_ip)
51891 + unsigned long parent_ip,
51892 + struct ftrace_ops *op,
51893 + struct pt_regs *regs)
51894 {
51895 unsigned long flags;
51896 struct pstore_ftrace_record rec = {};
51897 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
51898 index 16e8abb..2dcf914 100644
51899 --- a/fs/quota/netlink.c
51900 +++ b/fs/quota/netlink.c
51901 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
51902 void quota_send_warning(struct kqid qid, dev_t dev,
51903 const char warntype)
51904 {
51905 - static atomic_t seq;
51906 + static atomic_unchecked_t seq;
51907 struct sk_buff *skb;
51908 void *msg_head;
51909 int ret;
51910 @@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
51911 "VFS: Not enough memory to send quota warning.\n");
51912 return;
51913 }
51914 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
51915 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
51916 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
51917 if (!msg_head) {
51918 printk(KERN_ERR
51919 diff --git a/fs/read_write.c b/fs/read_write.c
51920 index d065348..8e2b43d 100644
51921 --- a/fs/read_write.c
51922 +++ b/fs/read_write.c
51923 @@ -935,6 +935,8 @@ ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos, size_t count,
51924 if (retval > 0) {
51925 add_rchar(current, retval);
51926 add_wchar(current, retval);
51927 + fsnotify_access(in.file);
51928 + fsnotify_modify(out.file);
51929 }
51930
51931 inc_syscr(current);
51932 diff --git a/fs/readdir.c b/fs/readdir.c
51933 index 5e69ef5..e5d9099 100644
51934 --- a/fs/readdir.c
51935 +++ b/fs/readdir.c
51936 @@ -17,6 +17,7 @@
51937 #include <linux/security.h>
51938 #include <linux/syscalls.h>
51939 #include <linux/unistd.h>
51940 +#include <linux/namei.h>
51941
51942 #include <asm/uaccess.h>
51943
51944 @@ -67,6 +68,7 @@ struct old_linux_dirent {
51945
51946 struct readdir_callback {
51947 struct old_linux_dirent __user * dirent;
51948 + struct file * file;
51949 int result;
51950 };
51951
51952 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
51953 buf->result = -EOVERFLOW;
51954 return -EOVERFLOW;
51955 }
51956 +
51957 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
51958 + return 0;
51959 +
51960 buf->result++;
51961 dirent = buf->dirent;
51962 if (!access_ok(VERIFY_WRITE, dirent,
51963 @@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
51964
51965 buf.result = 0;
51966 buf.dirent = dirent;
51967 + buf.file = f.file;
51968
51969 error = vfs_readdir(f.file, fillonedir, &buf);
51970 if (buf.result)
51971 @@ -139,6 +146,7 @@ struct linux_dirent {
51972 struct getdents_callback {
51973 struct linux_dirent __user * current_dir;
51974 struct linux_dirent __user * previous;
51975 + struct file * file;
51976 int count;
51977 int error;
51978 };
51979 @@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
51980 buf->error = -EOVERFLOW;
51981 return -EOVERFLOW;
51982 }
51983 +
51984 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
51985 + return 0;
51986 +
51987 dirent = buf->previous;
51988 if (dirent) {
51989 if (__put_user(offset, &dirent->d_off))
51990 @@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
51991 buf.previous = NULL;
51992 buf.count = count;
51993 buf.error = 0;
51994 + buf.file = f.file;
51995
51996 error = vfs_readdir(f.file, filldir, &buf);
51997 if (error >= 0)
51998 @@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
51999 struct getdents_callback64 {
52000 struct linux_dirent64 __user * current_dir;
52001 struct linux_dirent64 __user * previous;
52002 + struct file *file;
52003 int count;
52004 int error;
52005 };
52006 @@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
52007 buf->error = -EINVAL; /* only used if we fail.. */
52008 if (reclen > buf->count)
52009 return -EINVAL;
52010 +
52011 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
52012 + return 0;
52013 +
52014 dirent = buf->previous;
52015 if (dirent) {
52016 if (__put_user(offset, &dirent->d_off))
52017 @@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
52018
52019 buf.current_dir = dirent;
52020 buf.previous = NULL;
52021 + buf.file = f.file;
52022 buf.count = count;
52023 buf.error = 0;
52024
52025 @@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
52026 error = buf.error;
52027 lastdirent = buf.previous;
52028 if (lastdirent) {
52029 - typeof(lastdirent->d_off) d_off = f.file->f_pos;
52030 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
52031 if (__put_user(d_off, &lastdirent->d_off))
52032 error = -EFAULT;
52033 else
52034 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
52035 index 2b7882b..1c5ef48 100644
52036 --- a/fs/reiserfs/do_balan.c
52037 +++ b/fs/reiserfs/do_balan.c
52038 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
52039 return;
52040 }
52041
52042 - atomic_inc(&(fs_generation(tb->tb_sb)));
52043 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
52044 do_balance_starts(tb);
52045
52046 /* balance leaf returns 0 except if combining L R and S into
52047 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
52048 index e60e870..f40ac16 100644
52049 --- a/fs/reiserfs/procfs.c
52050 +++ b/fs/reiserfs/procfs.c
52051 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
52052 "SMALL_TAILS " : "NO_TAILS ",
52053 replay_only(sb) ? "REPLAY_ONLY " : "",
52054 convert_reiserfs(sb) ? "CONV " : "",
52055 - atomic_read(&r->s_generation_counter),
52056 + atomic_read_unchecked(&r->s_generation_counter),
52057 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
52058 SF(s_do_balance), SF(s_unneeded_left_neighbor),
52059 SF(s_good_search_by_key_reada), SF(s_bmaps),
52060 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
52061 index 33215f5..c5d427a 100644
52062 --- a/fs/reiserfs/reiserfs.h
52063 +++ b/fs/reiserfs/reiserfs.h
52064 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
52065 /* Comment? -Hans */
52066 wait_queue_head_t s_wait;
52067 /* To be obsoleted soon by per buffer seals.. -Hans */
52068 - atomic_t s_generation_counter; // increased by one every time the
52069 + atomic_unchecked_t s_generation_counter; // increased by one every time the
52070 // tree gets re-balanced
52071 unsigned long s_properties; /* File system properties. Currently holds
52072 on-disk FS format */
52073 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
52074 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
52075
52076 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
52077 -#define get_generation(s) atomic_read (&fs_generation(s))
52078 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
52079 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
52080 #define __fs_changed(gen,s) (gen != get_generation (s))
52081 #define fs_changed(gen,s) \
52082 diff --git a/fs/select.c b/fs/select.c
52083 index 2ef72d9..f213b17 100644
52084 --- a/fs/select.c
52085 +++ b/fs/select.c
52086 @@ -20,6 +20,7 @@
52087 #include <linux/export.h>
52088 #include <linux/slab.h>
52089 #include <linux/poll.h>
52090 +#include <linux/security.h>
52091 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
52092 #include <linux/file.h>
52093 #include <linux/fdtable.h>
52094 @@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
52095 struct poll_list *walk = head;
52096 unsigned long todo = nfds;
52097
52098 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
52099 if (nfds > rlimit(RLIMIT_NOFILE))
52100 return -EINVAL;
52101
52102 diff --git a/fs/seq_file.c b/fs/seq_file.c
52103 index 99dffab..e4fcb71 100644
52104 --- a/fs/seq_file.c
52105 +++ b/fs/seq_file.c
52106 @@ -10,6 +10,7 @@
52107 #include <linux/seq_file.h>
52108 #include <linux/slab.h>
52109 #include <linux/cred.h>
52110 +#include <linux/sched.h>
52111
52112 #include <asm/uaccess.h>
52113 #include <asm/page.h>
52114 @@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
52115 #ifdef CONFIG_USER_NS
52116 p->user_ns = file->f_cred->user_ns;
52117 #endif
52118 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52119 + p->exec_id = current->exec_id;
52120 +#endif
52121
52122 /*
52123 * Wrappers around seq_open(e.g. swaps_open) need to be
52124 @@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
52125 return 0;
52126 }
52127 if (!m->buf) {
52128 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
52129 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
52130 if (!m->buf)
52131 return -ENOMEM;
52132 }
52133 @@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
52134 Eoverflow:
52135 m->op->stop(m, p);
52136 kfree(m->buf);
52137 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
52138 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
52139 return !m->buf ? -ENOMEM : -EAGAIN;
52140 }
52141
52142 @@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
52143
52144 /* grab buffer if we didn't have one */
52145 if (!m->buf) {
52146 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
52147 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
52148 if (!m->buf)
52149 goto Enomem;
52150 }
52151 @@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
52152 goto Fill;
52153 m->op->stop(m, p);
52154 kfree(m->buf);
52155 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
52156 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
52157 if (!m->buf)
52158 goto Enomem;
52159 m->count = 0;
52160 @@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
52161 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
52162 void *data)
52163 {
52164 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
52165 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
52166 int res = -ENOMEM;
52167
52168 if (op) {
52169 diff --git a/fs/splice.c b/fs/splice.c
52170 index 48c7bd1..d0740e4 100644
52171 --- a/fs/splice.c
52172 +++ b/fs/splice.c
52173 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
52174 pipe_lock(pipe);
52175
52176 for (;;) {
52177 - if (!pipe->readers) {
52178 + if (!atomic_read(&pipe->readers)) {
52179 send_sig(SIGPIPE, current, 0);
52180 if (!ret)
52181 ret = -EPIPE;
52182 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
52183 do_wakeup = 0;
52184 }
52185
52186 - pipe->waiting_writers++;
52187 + atomic_inc(&pipe->waiting_writers);
52188 pipe_wait(pipe);
52189 - pipe->waiting_writers--;
52190 + atomic_dec(&pipe->waiting_writers);
52191 }
52192
52193 pipe_unlock(pipe);
52194 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
52195 old_fs = get_fs();
52196 set_fs(get_ds());
52197 /* The cast to a user pointer is valid due to the set_fs() */
52198 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
52199 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
52200 set_fs(old_fs);
52201
52202 return res;
52203 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
52204 old_fs = get_fs();
52205 set_fs(get_ds());
52206 /* The cast to a user pointer is valid due to the set_fs() */
52207 - res = vfs_write(file, (const char __user *)buf, count, &pos);
52208 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
52209 set_fs(old_fs);
52210
52211 return res;
52212 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
52213 goto err;
52214
52215 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
52216 - vec[i].iov_base = (void __user *) page_address(page);
52217 + vec[i].iov_base = (void __force_user *) page_address(page);
52218 vec[i].iov_len = this_len;
52219 spd.pages[i] = page;
52220 spd.nr_pages++;
52221 @@ -851,10 +851,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
52222 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
52223 {
52224 while (!pipe->nrbufs) {
52225 - if (!pipe->writers)
52226 + if (!atomic_read(&pipe->writers))
52227 return 0;
52228
52229 - if (!pipe->waiting_writers && sd->num_spliced)
52230 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
52231 return 0;
52232
52233 if (sd->flags & SPLICE_F_NONBLOCK)
52234 @@ -1192,7 +1192,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
52235 * out of the pipe right after the splice_to_pipe(). So set
52236 * PIPE_READERS appropriately.
52237 */
52238 - pipe->readers = 1;
52239 + atomic_set(&pipe->readers, 1);
52240
52241 current->splice_pipe = pipe;
52242 }
52243 @@ -1741,9 +1741,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
52244 ret = -ERESTARTSYS;
52245 break;
52246 }
52247 - if (!pipe->writers)
52248 + if (!atomic_read(&pipe->writers))
52249 break;
52250 - if (!pipe->waiting_writers) {
52251 + if (!atomic_read(&pipe->waiting_writers)) {
52252 if (flags & SPLICE_F_NONBLOCK) {
52253 ret = -EAGAIN;
52254 break;
52255 @@ -1775,7 +1775,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
52256 pipe_lock(pipe);
52257
52258 while (pipe->nrbufs >= pipe->buffers) {
52259 - if (!pipe->readers) {
52260 + if (!atomic_read(&pipe->readers)) {
52261 send_sig(SIGPIPE, current, 0);
52262 ret = -EPIPE;
52263 break;
52264 @@ -1788,9 +1788,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
52265 ret = -ERESTARTSYS;
52266 break;
52267 }
52268 - pipe->waiting_writers++;
52269 + atomic_inc(&pipe->waiting_writers);
52270 pipe_wait(pipe);
52271 - pipe->waiting_writers--;
52272 + atomic_dec(&pipe->waiting_writers);
52273 }
52274
52275 pipe_unlock(pipe);
52276 @@ -1826,14 +1826,14 @@ retry:
52277 pipe_double_lock(ipipe, opipe);
52278
52279 do {
52280 - if (!opipe->readers) {
52281 + if (!atomic_read(&opipe->readers)) {
52282 send_sig(SIGPIPE, current, 0);
52283 if (!ret)
52284 ret = -EPIPE;
52285 break;
52286 }
52287
52288 - if (!ipipe->nrbufs && !ipipe->writers)
52289 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
52290 break;
52291
52292 /*
52293 @@ -1930,7 +1930,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
52294 pipe_double_lock(ipipe, opipe);
52295
52296 do {
52297 - if (!opipe->readers) {
52298 + if (!atomic_read(&opipe->readers)) {
52299 send_sig(SIGPIPE, current, 0);
52300 if (!ret)
52301 ret = -EPIPE;
52302 @@ -1975,7 +1975,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
52303 * return EAGAIN if we have the potential of some data in the
52304 * future, otherwise just return 0
52305 */
52306 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
52307 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
52308 ret = -EAGAIN;
52309
52310 pipe_unlock(ipipe);
52311 diff --git a/fs/stat.c b/fs/stat.c
52312 index eae4946..6198f55 100644
52313 --- a/fs/stat.c
52314 +++ b/fs/stat.c
52315 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
52316 stat->gid = inode->i_gid;
52317 stat->rdev = inode->i_rdev;
52318 stat->size = i_size_read(inode);
52319 - stat->atime = inode->i_atime;
52320 - stat->mtime = inode->i_mtime;
52321 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
52322 + stat->atime = inode->i_ctime;
52323 + stat->mtime = inode->i_ctime;
52324 + } else {
52325 + stat->atime = inode->i_atime;
52326 + stat->mtime = inode->i_mtime;
52327 + }
52328 stat->ctime = inode->i_ctime;
52329 stat->blksize = (1 << inode->i_blkbits);
52330 stat->blocks = inode->i_blocks;
52331 @@ -46,8 +51,14 @@ int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
52332 if (retval)
52333 return retval;
52334
52335 - if (inode->i_op->getattr)
52336 - return inode->i_op->getattr(mnt, dentry, stat);
52337 + if (inode->i_op->getattr) {
52338 + retval = inode->i_op->getattr(mnt, dentry, stat);
52339 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
52340 + stat->atime = stat->ctime;
52341 + stat->mtime = stat->ctime;
52342 + }
52343 + return retval;
52344 + }
52345
52346 generic_fillattr(inode, stat);
52347 return 0;
52348 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
52349 index 2fbdff6..5530a61 100644
52350 --- a/fs/sysfs/dir.c
52351 +++ b/fs/sysfs/dir.c
52352 @@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
52353 struct sysfs_dirent *sd;
52354 int rc;
52355
52356 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
52357 + const char *parent_name = parent_sd->s_name;
52358 +
52359 + mode = S_IFDIR | S_IRWXU;
52360 +
52361 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
52362 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
52363 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
52364 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
52365 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
52366 +#endif
52367 +
52368 /* allocate */
52369 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
52370 if (!sd)
52371 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
52372 index 00012e3..8392349 100644
52373 --- a/fs/sysfs/file.c
52374 +++ b/fs/sysfs/file.c
52375 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
52376
52377 struct sysfs_open_dirent {
52378 atomic_t refcnt;
52379 - atomic_t event;
52380 + atomic_unchecked_t event;
52381 wait_queue_head_t poll;
52382 struct list_head buffers; /* goes through sysfs_buffer.list */
52383 };
52384 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
52385 if (!sysfs_get_active(attr_sd))
52386 return -ENODEV;
52387
52388 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
52389 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
52390 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
52391
52392 sysfs_put_active(attr_sd);
52393 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
52394 return -ENOMEM;
52395
52396 atomic_set(&new_od->refcnt, 0);
52397 - atomic_set(&new_od->event, 1);
52398 + atomic_set_unchecked(&new_od->event, 1);
52399 init_waitqueue_head(&new_od->poll);
52400 INIT_LIST_HEAD(&new_od->buffers);
52401 goto retry;
52402 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
52403
52404 sysfs_put_active(attr_sd);
52405
52406 - if (buffer->event != atomic_read(&od->event))
52407 + if (buffer->event != atomic_read_unchecked(&od->event))
52408 goto trigger;
52409
52410 return DEFAULT_POLLMASK;
52411 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
52412
52413 od = sd->s_attr.open;
52414 if (od) {
52415 - atomic_inc(&od->event);
52416 + atomic_inc_unchecked(&od->event);
52417 wake_up_interruptible(&od->poll);
52418 }
52419
52420 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
52421 index 3c9eb56..9dea5be 100644
52422 --- a/fs/sysfs/symlink.c
52423 +++ b/fs/sysfs/symlink.c
52424 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
52425
52426 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
52427 {
52428 - char *page = nd_get_link(nd);
52429 + const char *page = nd_get_link(nd);
52430 if (!IS_ERR(page))
52431 free_page((unsigned long)page);
52432 }
52433 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
52434 index c175b4d..8f36a16 100644
52435 --- a/fs/udf/misc.c
52436 +++ b/fs/udf/misc.c
52437 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
52438
52439 u8 udf_tag_checksum(const struct tag *t)
52440 {
52441 - u8 *data = (u8 *)t;
52442 + const u8 *data = (const u8 *)t;
52443 u8 checksum = 0;
52444 int i;
52445 for (i = 0; i < sizeof(struct tag); ++i)
52446 diff --git a/fs/utimes.c b/fs/utimes.c
52447 index bb0696a..552054b 100644
52448 --- a/fs/utimes.c
52449 +++ b/fs/utimes.c
52450 @@ -1,6 +1,7 @@
52451 #include <linux/compiler.h>
52452 #include <linux/file.h>
52453 #include <linux/fs.h>
52454 +#include <linux/security.h>
52455 #include <linux/linkage.h>
52456 #include <linux/mount.h>
52457 #include <linux/namei.h>
52458 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
52459 goto mnt_drop_write_and_out;
52460 }
52461 }
52462 +
52463 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
52464 + error = -EACCES;
52465 + goto mnt_drop_write_and_out;
52466 + }
52467 +
52468 mutex_lock(&inode->i_mutex);
52469 error = notify_change(path->dentry, &newattrs);
52470 mutex_unlock(&inode->i_mutex);
52471 diff --git a/fs/xattr.c b/fs/xattr.c
52472 index e21c119..21dfc7c 100644
52473 --- a/fs/xattr.c
52474 +++ b/fs/xattr.c
52475 @@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
52476 * Extended attribute SET operations
52477 */
52478 static long
52479 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
52480 +setxattr(struct path *path, const char __user *name, const void __user *value,
52481 size_t size, int flags)
52482 {
52483 int error;
52484 @@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
52485 posix_acl_fix_xattr_from_user(kvalue, size);
52486 }
52487
52488 - error = vfs_setxattr(d, kname, kvalue, size, flags);
52489 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
52490 + error = -EACCES;
52491 + goto out;
52492 + }
52493 +
52494 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
52495 out:
52496 if (vvalue)
52497 vfree(vvalue);
52498 @@ -376,7 +381,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
52499 return error;
52500 error = mnt_want_write(path.mnt);
52501 if (!error) {
52502 - error = setxattr(path.dentry, name, value, size, flags);
52503 + error = setxattr(&path, name, value, size, flags);
52504 mnt_drop_write(path.mnt);
52505 }
52506 path_put(&path);
52507 @@ -395,7 +400,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
52508 return error;
52509 error = mnt_want_write(path.mnt);
52510 if (!error) {
52511 - error = setxattr(path.dentry, name, value, size, flags);
52512 + error = setxattr(&path, name, value, size, flags);
52513 mnt_drop_write(path.mnt);
52514 }
52515 path_put(&path);
52516 @@ -406,16 +411,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
52517 const void __user *,value, size_t, size, int, flags)
52518 {
52519 struct fd f = fdget(fd);
52520 - struct dentry *dentry;
52521 int error = -EBADF;
52522
52523 if (!f.file)
52524 return error;
52525 - dentry = f.file->f_path.dentry;
52526 - audit_inode(NULL, dentry, 0);
52527 + audit_inode(NULL, f.file->f_path.dentry, 0);
52528 error = mnt_want_write_file(f.file);
52529 if (!error) {
52530 - error = setxattr(dentry, name, value, size, flags);
52531 + error = setxattr(&f.file->f_path, name, value, size, flags);
52532 mnt_drop_write_file(f.file);
52533 }
52534 fdput(f);
52535 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
52536 index 9fbea87..6b19972 100644
52537 --- a/fs/xattr_acl.c
52538 +++ b/fs/xattr_acl.c
52539 @@ -76,8 +76,8 @@ struct posix_acl *
52540 posix_acl_from_xattr(struct user_namespace *user_ns,
52541 const void *value, size_t size)
52542 {
52543 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
52544 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
52545 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
52546 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
52547 int count;
52548 struct posix_acl *acl;
52549 struct posix_acl_entry *acl_e;
52550 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
52551 index 83d0cf3..2ef526b 100644
52552 --- a/fs/xfs/xfs_bmap.c
52553 +++ b/fs/xfs/xfs_bmap.c
52554 @@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
52555 int nmap,
52556 int ret_nmap);
52557 #else
52558 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
52559 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
52560 #endif /* DEBUG */
52561
52562 STATIC int
52563 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
52564 index 1b9fc3e..e1bdde0 100644
52565 --- a/fs/xfs/xfs_dir2_sf.c
52566 +++ b/fs/xfs/xfs_dir2_sf.c
52567 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
52568 }
52569
52570 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
52571 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
52572 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
52573 + char name[sfep->namelen];
52574 + memcpy(name, sfep->name, sfep->namelen);
52575 + if (filldir(dirent, name, sfep->namelen,
52576 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
52577 + *offset = off & 0x7fffffff;
52578 + return 0;
52579 + }
52580 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
52581 off & 0x7fffffff, ino, DT_UNKNOWN)) {
52582 *offset = off & 0x7fffffff;
52583 return 0;
52584 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
52585 index c1df3c6..f987db6 100644
52586 --- a/fs/xfs/xfs_ioctl.c
52587 +++ b/fs/xfs/xfs_ioctl.c
52588 @@ -126,7 +126,7 @@ xfs_find_handle(
52589 }
52590
52591 error = -EFAULT;
52592 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
52593 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
52594 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
52595 goto out_put;
52596
52597 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
52598 index 4e00cf0..3374374 100644
52599 --- a/fs/xfs/xfs_iops.c
52600 +++ b/fs/xfs/xfs_iops.c
52601 @@ -394,7 +394,7 @@ xfs_vn_put_link(
52602 struct nameidata *nd,
52603 void *p)
52604 {
52605 - char *s = nd_get_link(nd);
52606 + const char *s = nd_get_link(nd);
52607
52608 if (!IS_ERR(s))
52609 kfree(s);
52610 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
52611 new file mode 100644
52612 index 0000000..92247e4
52613 --- /dev/null
52614 +++ b/grsecurity/Kconfig
52615 @@ -0,0 +1,1021 @@
52616 +#
52617 +# grecurity configuration
52618 +#
52619 +menu "Memory Protections"
52620 +depends on GRKERNSEC
52621 +
52622 +config GRKERNSEC_KMEM
52623 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
52624 + default y if GRKERNSEC_CONFIG_AUTO
52625 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
52626 + help
52627 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
52628 + be written to or read from to modify or leak the contents of the running
52629 + kernel. /dev/port will also not be allowed to be opened and support
52630 + for /dev/cpu/*/msr will be removed. If you have module
52631 + support disabled, enabling this will close up five ways that are
52632 + currently used to insert malicious code into the running kernel.
52633 +
52634 + Even with all these features enabled, we still highly recommend that
52635 + you use the RBAC system, as it is still possible for an attacker to
52636 + modify the running kernel through privileged I/O granted by ioperm/iopl.
52637 +
52638 + If you are not using XFree86, you may be able to stop this additional
52639 + case by enabling the 'Disable privileged I/O' option. Though nothing
52640 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
52641 + but only to video memory, which is the only writing we allow in this
52642 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
52643 + not be allowed to mprotect it with PROT_WRITE later.
52644 + Enabling this feature will prevent the "cpupower" and "powertop" tools
52645 + from working.
52646 +
52647 + It is highly recommended that you say Y here if you meet all the
52648 + conditions above.
52649 +
52650 +config GRKERNSEC_VM86
52651 + bool "Restrict VM86 mode"
52652 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
52653 + depends on X86_32
52654 +
52655 + help
52656 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
52657 + make use of a special execution mode on 32bit x86 processors called
52658 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
52659 + video cards and will still work with this option enabled. The purpose
52660 + of the option is to prevent exploitation of emulation errors in
52661 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
52662 + Nearly all users should be able to enable this option.
52663 +
52664 +config GRKERNSEC_IO
52665 + bool "Disable privileged I/O"
52666 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
52667 + depends on X86
52668 + select RTC_CLASS
52669 + select RTC_INTF_DEV
52670 + select RTC_DRV_CMOS
52671 +
52672 + help
52673 + If you say Y here, all ioperm and iopl calls will return an error.
52674 + Ioperm and iopl can be used to modify the running kernel.
52675 + Unfortunately, some programs need this access to operate properly,
52676 + the most notable of which are XFree86 and hwclock. hwclock can be
52677 + remedied by having RTC support in the kernel, so real-time
52678 + clock support is enabled if this option is enabled, to ensure
52679 + that hwclock operates correctly. XFree86 still will not
52680 + operate correctly with this option enabled, so DO NOT CHOOSE Y
52681 + IF YOU USE XFree86. If you use XFree86 and you still want to
52682 + protect your kernel against modification, use the RBAC system.
52683 +
52684 +config GRKERNSEC_JIT_HARDEN
52685 + bool "Harden BPF JIT against spray attacks"
52686 + default y if GRKERNSEC_CONFIG_AUTO
52687 + depends on BPF_JIT
52688 + help
52689 + If you say Y here, the native code generated by the kernel's Berkeley
52690 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
52691 + attacks that attempt to fit attacker-beneficial instructions in
52692 + 32bit immediate fields of JIT-generated native instructions. The
52693 + attacker will generally aim to cause an unintended instruction sequence
52694 + of JIT-generated native code to execute by jumping into the middle of
52695 + a generated instruction. This feature effectively randomizes the 32bit
52696 + immediate constants present in the generated code to thwart such attacks.
52697 +
52698 + If you're using KERNEXEC, it's recommended that you enable this option
52699 + to supplement the hardening of the kernel.
52700 +
52701 +config GRKERNSEC_RAND_THREADSTACK
52702 + bool "Insert random gaps between thread stacks"
52703 + default y if GRKERNSEC_CONFIG_AUTO
52704 + depends on PAX_RANDMMAP && !PPC
52705 + help
52706 + If you say Y here, a random-sized gap will be enforced between allocated
52707 + thread stacks. Glibc's NPTL and other threading libraries that
52708 + pass MAP_STACK to the kernel for thread stack allocation are supported.
52709 + The implementation currently provides 8 bits of entropy for the gap.
52710 +
52711 + Many distributions do not compile threaded remote services with the
52712 + -fstack-check argument to GCC, causing the variable-sized stack-based
52713 + allocator, alloca(), to not probe the stack on allocation. This
52714 + permits an unbounded alloca() to skip over any guard page and potentially
52715 + modify another thread's stack reliably. An enforced random gap
52716 + reduces the reliability of such an attack and increases the chance
52717 + that such a read/write to another thread's stack instead lands in
52718 + an unmapped area, causing a crash and triggering grsecurity's
52719 + anti-bruteforcing logic.
52720 +
52721 +config GRKERNSEC_PROC_MEMMAP
52722 + bool "Harden ASLR against information leaks and entropy reduction"
52723 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
52724 + depends on PAX_NOEXEC || PAX_ASLR
52725 + help
52726 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
52727 + give no information about the addresses of its mappings if
52728 + PaX features that rely on random addresses are enabled on the task.
52729 + In addition to sanitizing this information and disabling other
52730 + dangerous sources of information, this option causes reads of sensitive
52731 + /proc/<pid> entries where the file descriptor was opened in a different
52732 + task than the one performing the read. Such attempts are logged.
52733 + This option also limits argv/env strings for suid/sgid binaries
52734 + to 512KB to prevent a complete exhaustion of the stack entropy provided
52735 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
52736 + binaries to prevent alternative mmap layouts from being abused.
52737 +
52738 + If you use PaX it is essential that you say Y here as it closes up
52739 + several holes that make full ASLR useless locally.
52740 +
52741 +config GRKERNSEC_BRUTE
52742 + bool "Deter exploit bruteforcing"
52743 + default y if GRKERNSEC_CONFIG_AUTO
52744 + help
52745 + If you say Y here, attempts to bruteforce exploits against forking
52746 + daemons such as apache or sshd, as well as against suid/sgid binaries
52747 + will be deterred. When a child of a forking daemon is killed by PaX
52748 + or crashes due to an illegal instruction or other suspicious signal,
52749 + the parent process will be delayed 30 seconds upon every subsequent
52750 + fork until the administrator is able to assess the situation and
52751 + restart the daemon.
52752 + In the suid/sgid case, the attempt is logged, the user has all their
52753 + processes terminated, and they are prevented from executing any further
52754 + processes for 15 minutes.
52755 + It is recommended that you also enable signal logging in the auditing
52756 + section so that logs are generated when a process triggers a suspicious
52757 + signal.
52758 + If the sysctl option is enabled, a sysctl option with name
52759 + "deter_bruteforce" is created.
52760 +
52761 +
52762 +config GRKERNSEC_MODHARDEN
52763 + bool "Harden module auto-loading"
52764 + default y if GRKERNSEC_CONFIG_AUTO
52765 + depends on MODULES
52766 + help
52767 + If you say Y here, module auto-loading in response to use of some
52768 + feature implemented by an unloaded module will be restricted to
52769 + root users. Enabling this option helps defend against attacks
52770 + by unprivileged users who abuse the auto-loading behavior to
52771 + cause a vulnerable module to load that is then exploited.
52772 +
52773 + If this option prevents a legitimate use of auto-loading for a
52774 + non-root user, the administrator can execute modprobe manually
52775 + with the exact name of the module mentioned in the alert log.
52776 + Alternatively, the administrator can add the module to the list
52777 + of modules loaded at boot by modifying init scripts.
52778 +
52779 + Modification of init scripts will most likely be needed on
52780 + Ubuntu servers with encrypted home directory support enabled,
52781 + as the first non-root user logging in will cause the ecb(aes),
52782 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
52783 +
52784 +config GRKERNSEC_HIDESYM
52785 + bool "Hide kernel symbols"
52786 + default y if GRKERNSEC_CONFIG_AUTO
52787 + select PAX_USERCOPY_SLABS
52788 + help
52789 + If you say Y here, getting information on loaded modules, and
52790 + displaying all kernel symbols through a syscall will be restricted
52791 + to users with CAP_SYS_MODULE. For software compatibility reasons,
52792 + /proc/kallsyms will be restricted to the root user. The RBAC
52793 + system can hide that entry even from root.
52794 +
52795 + This option also prevents leaking of kernel addresses through
52796 + several /proc entries.
52797 +
52798 + Note that this option is only effective provided the following
52799 + conditions are met:
52800 + 1) The kernel using grsecurity is not precompiled by some distribution
52801 + 2) You have also enabled GRKERNSEC_DMESG
52802 + 3) You are using the RBAC system and hiding other files such as your
52803 + kernel image and System.map. Alternatively, enabling this option
52804 + causes the permissions on /boot, /lib/modules, and the kernel
52805 + source directory to change at compile time to prevent
52806 + reading by non-root users.
52807 + If the above conditions are met, this option will aid in providing a
52808 + useful protection against local kernel exploitation of overflows
52809 + and arbitrary read/write vulnerabilities.
52810 +
52811 +config GRKERNSEC_KERN_LOCKOUT
52812 + bool "Active kernel exploit response"
52813 + default y if GRKERNSEC_CONFIG_AUTO
52814 + depends on X86 || ARM || PPC || SPARC
52815 + help
52816 + If you say Y here, when a PaX alert is triggered due to suspicious
52817 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
52818 + or an OOPS occurs due to bad memory accesses, instead of just
52819 + terminating the offending process (and potentially allowing
52820 + a subsequent exploit from the same user), we will take one of two
52821 + actions:
52822 + If the user was root, we will panic the system
52823 + If the user was non-root, we will log the attempt, terminate
52824 + all processes owned by the user, then prevent them from creating
52825 + any new processes until the system is restarted
52826 + This deters repeated kernel exploitation/bruteforcing attempts
52827 + and is useful for later forensics.
52828 +
52829 +endmenu
52830 +menu "Role Based Access Control Options"
52831 +depends on GRKERNSEC
52832 +
52833 +config GRKERNSEC_RBAC_DEBUG
52834 + bool
52835 +
52836 +config GRKERNSEC_NO_RBAC
52837 + bool "Disable RBAC system"
52838 + help
52839 + If you say Y here, the /dev/grsec device will be removed from the kernel,
52840 + preventing the RBAC system from being enabled. You should only say Y
52841 + here if you have no intention of using the RBAC system, so as to prevent
52842 + an attacker with root access from misusing the RBAC system to hide files
52843 + and processes when loadable module support and /dev/[k]mem have been
52844 + locked down.
52845 +
52846 +config GRKERNSEC_ACL_HIDEKERN
52847 + bool "Hide kernel processes"
52848 + help
52849 + If you say Y here, all kernel threads will be hidden to all
52850 + processes but those whose subject has the "view hidden processes"
52851 + flag.
52852 +
52853 +config GRKERNSEC_ACL_MAXTRIES
52854 + int "Maximum tries before password lockout"
52855 + default 3
52856 + help
52857 + This option enforces the maximum number of times a user can attempt
52858 + to authorize themselves with the grsecurity RBAC system before being
52859 + denied the ability to attempt authorization again for a specified time.
52860 + The lower the number, the harder it will be to brute-force a password.
52861 +
52862 +config GRKERNSEC_ACL_TIMEOUT
52863 + int "Time to wait after max password tries, in seconds"
52864 + default 30
52865 + help
52866 + This option specifies the time the user must wait after attempting to
52867 + authorize to the RBAC system with the maximum number of invalid
52868 + passwords. The higher the number, the harder it will be to brute-force
52869 + a password.
52870 +
52871 +endmenu
52872 +menu "Filesystem Protections"
52873 +depends on GRKERNSEC
52874 +
52875 +config GRKERNSEC_PROC
52876 + bool "Proc restrictions"
52877 + default y if GRKERNSEC_CONFIG_AUTO
52878 + help
52879 + If you say Y here, the permissions of the /proc filesystem
52880 + will be altered to enhance system security and privacy. You MUST
52881 + choose either a user only restriction or a user and group restriction.
52882 + Depending upon the option you choose, you can either restrict users to
52883 + see only the processes they themselves run, or choose a group that can
52884 + view all processes and files normally restricted to root if you choose
52885 + the "restrict to user only" option. NOTE: If you're running identd or
52886 + ntpd as a non-root user, you will have to run it as the group you
52887 + specify here.
52888 +
52889 +config GRKERNSEC_PROC_USER
52890 + bool "Restrict /proc to user only"
52891 + depends on GRKERNSEC_PROC
52892 + help
52893 + If you say Y here, non-root users will only be able to view their own
52894 + processes, and restricts them from viewing network-related information,
52895 + and viewing kernel symbol and module information.
52896 +
52897 +config GRKERNSEC_PROC_USERGROUP
52898 + bool "Allow special group"
52899 + default y if GRKERNSEC_CONFIG_AUTO
52900 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
52901 + help
52902 + If you say Y here, you will be able to select a group that will be
52903 + able to view all processes and network-related information. If you've
52904 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
52905 + remain hidden. This option is useful if you want to run identd as
52906 + a non-root user. The group you select may also be chosen at boot time
52907 + via "grsec_proc_gid=" on the kernel commandline.
52908 +
52909 +config GRKERNSEC_PROC_GID
52910 + int "GID for special group"
52911 + depends on GRKERNSEC_PROC_USERGROUP
52912 + default 1001
52913 +
52914 +config GRKERNSEC_PROC_ADD
52915 + bool "Additional restrictions"
52916 + default y if GRKERNSEC_CONFIG_AUTO
52917 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
52918 + help
52919 + If you say Y here, additional restrictions will be placed on
52920 + /proc that keep normal users from viewing device information and
52921 + slabinfo information that could be useful for exploits.
52922 +
52923 +config GRKERNSEC_LINK
52924 + bool "Linking restrictions"
52925 + default y if GRKERNSEC_CONFIG_AUTO
52926 + help
52927 + If you say Y here, /tmp race exploits will be prevented, since users
52928 + will no longer be able to follow symlinks owned by other users in
52929 + world-writable +t directories (e.g. /tmp), unless the owner of the
52930 + symlink is the owner of the directory. users will also not be
52931 + able to hardlink to files they do not own. If the sysctl option is
52932 + enabled, a sysctl option with name "linking_restrictions" is created.
52933 +
52934 +config GRKERNSEC_SYMLINKOWN
52935 + bool "Kernel-enforced SymlinksIfOwnerMatch"
52936 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
52937 + help
52938 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
52939 + that prevents it from being used as a security feature. As Apache
52940 + verifies the symlink by performing a stat() against the target of
52941 + the symlink before it is followed, an attacker can setup a symlink
52942 + to point to a same-owned file, then replace the symlink with one
52943 + that targets another user's file just after Apache "validates" the
52944 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
52945 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
52946 + will be in place for the group you specify. If the sysctl option
52947 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
52948 + created.
52949 +
52950 +config GRKERNSEC_SYMLINKOWN_GID
52951 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
52952 + depends on GRKERNSEC_SYMLINKOWN
52953 + default 1006
52954 + help
52955 + Setting this GID determines what group kernel-enforced
52956 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
52957 + is enabled, a sysctl option with name "symlinkown_gid" is created.
52958 +
52959 +config GRKERNSEC_FIFO
52960 + bool "FIFO restrictions"
52961 + default y if GRKERNSEC_CONFIG_AUTO
52962 + help
52963 + If you say Y here, users will not be able to write to FIFOs they don't
52964 + own in world-writable +t directories (e.g. /tmp), unless the owner of
52965 + the FIFO is the same owner of the directory it's held in. If the sysctl
52966 + option is enabled, a sysctl option with name "fifo_restrictions" is
52967 + created.
52968 +
52969 +config GRKERNSEC_SYSFS_RESTRICT
52970 + bool "Sysfs/debugfs restriction"
52971 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
52972 + depends on SYSFS
52973 + help
52974 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
52975 + any filesystem normally mounted under it (e.g. debugfs) will be
52976 + mostly accessible only by root. These filesystems generally provide access
52977 + to hardware and debug information that isn't appropriate for unprivileged
52978 + users of the system. Sysfs and debugfs have also become a large source
52979 + of new vulnerabilities, ranging from infoleaks to local compromise.
52980 + There has been very little oversight with an eye toward security involved
52981 + in adding new exporters of information to these filesystems, so their
52982 + use is discouraged.
52983 + For reasons of compatibility, a few directories have been whitelisted
52984 + for access by non-root users:
52985 + /sys/fs/selinux
52986 + /sys/fs/fuse
52987 + /sys/devices/system/cpu
52988 +
52989 +config GRKERNSEC_ROFS
52990 + bool "Runtime read-only mount protection"
52991 + help
52992 + If you say Y here, a sysctl option with name "romount_protect" will
52993 + be created. By setting this option to 1 at runtime, filesystems
52994 + will be protected in the following ways:
52995 + * No new writable mounts will be allowed
52996 + * Existing read-only mounts won't be able to be remounted read/write
52997 + * Write operations will be denied on all block devices
52998 + This option acts independently of grsec_lock: once it is set to 1,
52999 + it cannot be turned off. Therefore, please be mindful of the resulting
53000 + behavior if this option is enabled in an init script on a read-only
53001 + filesystem. This feature is mainly intended for secure embedded systems.
53002 +
53003 +config GRKERNSEC_DEVICE_SIDECHANNEL
53004 + bool "Eliminate stat/notify-based device sidechannels"
53005 + default y if GRKERNSEC_CONFIG_AUTO
53006 + help
53007 + If you say Y here, timing analyses on block or character
53008 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
53009 + will be thwarted for unprivileged users. If a process without
53010 + CAP_MKNOD stats such a device, the last access and last modify times
53011 + will match the device's create time. No access or modify events
53012 + will be triggered through inotify/dnotify/fanotify for such devices.
53013 + This feature will prevent attacks that may at a minimum
53014 + allow an attacker to determine the administrator's password length.
53015 +
53016 +config GRKERNSEC_CHROOT
53017 + bool "Chroot jail restrictions"
53018 + default y if GRKERNSEC_CONFIG_AUTO
53019 + help
53020 + If you say Y here, you will be able to choose several options that will
53021 + make breaking out of a chrooted jail much more difficult. If you
53022 + encounter no software incompatibilities with the following options, it
53023 + is recommended that you enable each one.
53024 +
53025 +config GRKERNSEC_CHROOT_MOUNT
53026 + bool "Deny mounts"
53027 + default y if GRKERNSEC_CONFIG_AUTO
53028 + depends on GRKERNSEC_CHROOT
53029 + help
53030 + If you say Y here, processes inside a chroot will not be able to
53031 + mount or remount filesystems. If the sysctl option is enabled, a
53032 + sysctl option with name "chroot_deny_mount" is created.
53033 +
53034 +config GRKERNSEC_CHROOT_DOUBLE
53035 + bool "Deny double-chroots"
53036 + default y if GRKERNSEC_CONFIG_AUTO
53037 + depends on GRKERNSEC_CHROOT
53038 + help
53039 + If you say Y here, processes inside a chroot will not be able to chroot
53040 + again outside the chroot. This is a widely used method of breaking
53041 + out of a chroot jail and should not be allowed. If the sysctl
53042 + option is enabled, a sysctl option with name
53043 + "chroot_deny_chroot" is created.
53044 +
53045 +config GRKERNSEC_CHROOT_PIVOT
53046 + bool "Deny pivot_root in chroot"
53047 + default y if GRKERNSEC_CONFIG_AUTO
53048 + depends on GRKERNSEC_CHROOT
53049 + help
53050 + If you say Y here, processes inside a chroot will not be able to use
53051 + a function called pivot_root() that was introduced in Linux 2.3.41. It
53052 + works similar to chroot in that it changes the root filesystem. This
53053 + function could be misused in a chrooted process to attempt to break out
53054 + of the chroot, and therefore should not be allowed. If the sysctl
53055 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
53056 + created.
53057 +
53058 +config GRKERNSEC_CHROOT_CHDIR
53059 + bool "Enforce chdir(\"/\") on all chroots"
53060 + default y if GRKERNSEC_CONFIG_AUTO
53061 + depends on GRKERNSEC_CHROOT
53062 + help
53063 + If you say Y here, the current working directory of all newly-chrooted
53064 + applications will be set to the the root directory of the chroot.
53065 + The man page on chroot(2) states:
53066 + Note that this call does not change the current working
53067 + directory, so that `.' can be outside the tree rooted at
53068 + `/'. In particular, the super-user can escape from a
53069 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
53070 +
53071 + It is recommended that you say Y here, since it's not known to break
53072 + any software. If the sysctl option is enabled, a sysctl option with
53073 + name "chroot_enforce_chdir" is created.
53074 +
53075 +config GRKERNSEC_CHROOT_CHMOD
53076 + bool "Deny (f)chmod +s"
53077 + default y if GRKERNSEC_CONFIG_AUTO
53078 + depends on GRKERNSEC_CHROOT
53079 + help
53080 + If you say Y here, processes inside a chroot will not be able to chmod
53081 + or fchmod files to make them have suid or sgid bits. This protects
53082 + against another published method of breaking a chroot. If the sysctl
53083 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
53084 + created.
53085 +
53086 +config GRKERNSEC_CHROOT_FCHDIR
53087 + bool "Deny fchdir out of chroot"
53088 + default y if GRKERNSEC_CONFIG_AUTO
53089 + depends on GRKERNSEC_CHROOT
53090 + help
53091 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
53092 + to a file descriptor of the chrooting process that points to a directory
53093 + outside the filesystem will be stopped. If the sysctl option
53094 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
53095 +
53096 +config GRKERNSEC_CHROOT_MKNOD
53097 + bool "Deny mknod"
53098 + default y if GRKERNSEC_CONFIG_AUTO
53099 + depends on GRKERNSEC_CHROOT
53100 + help
53101 + If you say Y here, processes inside a chroot will not be allowed to
53102 + mknod. The problem with using mknod inside a chroot is that it
53103 + would allow an attacker to create a device entry that is the same
53104 + as one on the physical root of your system, which could range from
53105 + anything from the console device to a device for your harddrive (which
53106 + they could then use to wipe the drive or steal data). It is recommended
53107 + that you say Y here, unless you run into software incompatibilities.
53108 + If the sysctl option is enabled, a sysctl option with name
53109 + "chroot_deny_mknod" is created.
53110 +
53111 +config GRKERNSEC_CHROOT_SHMAT
53112 + bool "Deny shmat() out of chroot"
53113 + default y if GRKERNSEC_CONFIG_AUTO
53114 + depends on GRKERNSEC_CHROOT
53115 + help
53116 + If you say Y here, processes inside a chroot will not be able to attach
53117 + to shared memory segments that were created outside of the chroot jail.
53118 + It is recommended that you say Y here. If the sysctl option is enabled,
53119 + a sysctl option with name "chroot_deny_shmat" is created.
53120 +
53121 +config GRKERNSEC_CHROOT_UNIX
53122 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
53123 + default y if GRKERNSEC_CONFIG_AUTO
53124 + depends on GRKERNSEC_CHROOT
53125 + help
53126 + If you say Y here, processes inside a chroot will not be able to
53127 + connect to abstract (meaning not belonging to a filesystem) Unix
53128 + domain sockets that were bound outside of a chroot. It is recommended
53129 + that you say Y here. If the sysctl option is enabled, a sysctl option
53130 + with name "chroot_deny_unix" is created.
53131 +
53132 +config GRKERNSEC_CHROOT_FINDTASK
53133 + bool "Protect outside processes"
53134 + default y if GRKERNSEC_CONFIG_AUTO
53135 + depends on GRKERNSEC_CHROOT
53136 + help
53137 + If you say Y here, processes inside a chroot will not be able to
53138 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
53139 + getsid, or view any process outside of the chroot. If the sysctl
53140 + option is enabled, a sysctl option with name "chroot_findtask" is
53141 + created.
53142 +
53143 +config GRKERNSEC_CHROOT_NICE
53144 + bool "Restrict priority changes"
53145 + default y if GRKERNSEC_CONFIG_AUTO
53146 + depends on GRKERNSEC_CHROOT
53147 + help
53148 + If you say Y here, processes inside a chroot will not be able to raise
53149 + the priority of processes in the chroot, or alter the priority of
53150 + processes outside the chroot. This provides more security than simply
53151 + removing CAP_SYS_NICE from the process' capability set. If the
53152 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
53153 + is created.
53154 +
53155 +config GRKERNSEC_CHROOT_SYSCTL
53156 + bool "Deny sysctl writes"
53157 + default y if GRKERNSEC_CONFIG_AUTO
53158 + depends on GRKERNSEC_CHROOT
53159 + help
53160 + If you say Y here, an attacker in a chroot will not be able to
53161 + write to sysctl entries, either by sysctl(2) or through a /proc
53162 + interface. It is strongly recommended that you say Y here. If the
53163 + sysctl option is enabled, a sysctl option with name
53164 + "chroot_deny_sysctl" is created.
53165 +
53166 +config GRKERNSEC_CHROOT_CAPS
53167 + bool "Capability restrictions"
53168 + default y if GRKERNSEC_CONFIG_AUTO
53169 + depends on GRKERNSEC_CHROOT
53170 + help
53171 + If you say Y here, the capabilities on all processes within a
53172 + chroot jail will be lowered to stop module insertion, raw i/o,
53173 + system and net admin tasks, rebooting the system, modifying immutable
53174 + files, modifying IPC owned by another, and changing the system time.
53175 + This is left an option because it can break some apps. Disable this
53176 + if your chrooted apps are having problems performing those kinds of
53177 + tasks. If the sysctl option is enabled, a sysctl option with
53178 + name "chroot_caps" is created.
53179 +
53180 +endmenu
53181 +menu "Kernel Auditing"
53182 +depends on GRKERNSEC
53183 +
53184 +config GRKERNSEC_AUDIT_GROUP
53185 + bool "Single group for auditing"
53186 + help
53187 + If you say Y here, the exec and chdir logging features will only operate
53188 + on a group you specify. This option is recommended if you only want to
53189 + watch certain users instead of having a large amount of logs from the
53190 + entire system. If the sysctl option is enabled, a sysctl option with
53191 + name "audit_group" is created.
53192 +
53193 +config GRKERNSEC_AUDIT_GID
53194 + int "GID for auditing"
53195 + depends on GRKERNSEC_AUDIT_GROUP
53196 + default 1007
53197 +
53198 +config GRKERNSEC_EXECLOG
53199 + bool "Exec logging"
53200 + help
53201 + If you say Y here, all execve() calls will be logged (since the
53202 + other exec*() calls are frontends to execve(), all execution
53203 + will be logged). Useful for shell-servers that like to keep track
53204 + of their users. If the sysctl option is enabled, a sysctl option with
53205 + name "exec_logging" is created.
53206 + WARNING: This option when enabled will produce a LOT of logs, especially
53207 + on an active system.
53208 +
53209 +config GRKERNSEC_RESLOG
53210 + bool "Resource logging"
53211 + default y if GRKERNSEC_CONFIG_AUTO
53212 + help
53213 + If you say Y here, all attempts to overstep resource limits will
53214 + be logged with the resource name, the requested size, and the current
53215 + limit. It is highly recommended that you say Y here. If the sysctl
53216 + option is enabled, a sysctl option with name "resource_logging" is
53217 + created. If the RBAC system is enabled, the sysctl value is ignored.
53218 +
53219 +config GRKERNSEC_CHROOT_EXECLOG
53220 + bool "Log execs within chroot"
53221 + help
53222 + If you say Y here, all executions inside a chroot jail will be logged
53223 + to syslog. This can cause a large amount of logs if certain
53224 + applications (eg. djb's daemontools) are installed on the system, and
53225 + is therefore left as an option. If the sysctl option is enabled, a
53226 + sysctl option with name "chroot_execlog" is created.
53227 +
53228 +config GRKERNSEC_AUDIT_PTRACE
53229 + bool "Ptrace logging"
53230 + help
53231 + If you say Y here, all attempts to attach to a process via ptrace
53232 + will be logged. If the sysctl option is enabled, a sysctl option
53233 + with name "audit_ptrace" is created.
53234 +
53235 +config GRKERNSEC_AUDIT_CHDIR
53236 + bool "Chdir logging"
53237 + help
53238 + If you say Y here, all chdir() calls will be logged. If the sysctl
53239 + option is enabled, a sysctl option with name "audit_chdir" is created.
53240 +
53241 +config GRKERNSEC_AUDIT_MOUNT
53242 + bool "(Un)Mount logging"
53243 + help
53244 + If you say Y here, all mounts and unmounts will be logged. If the
53245 + sysctl option is enabled, a sysctl option with name "audit_mount" is
53246 + created.
53247 +
53248 +config GRKERNSEC_SIGNAL
53249 + bool "Signal logging"
53250 + default y if GRKERNSEC_CONFIG_AUTO
53251 + help
53252 + If you say Y here, certain important signals will be logged, such as
53253 + SIGSEGV, which will as a result inform you of when a error in a program
53254 + occurred, which in some cases could mean a possible exploit attempt.
53255 + If the sysctl option is enabled, a sysctl option with name
53256 + "signal_logging" is created.
53257 +
53258 +config GRKERNSEC_FORKFAIL
53259 + bool "Fork failure logging"
53260 + help
53261 + If you say Y here, all failed fork() attempts will be logged.
53262 + This could suggest a fork bomb, or someone attempting to overstep
53263 + their process limit. If the sysctl option is enabled, a sysctl option
53264 + with name "forkfail_logging" is created.
53265 +
53266 +config GRKERNSEC_TIME
53267 + bool "Time change logging"
53268 + default y if GRKERNSEC_CONFIG_AUTO
53269 + help
53270 + If you say Y here, any changes of the system clock will be logged.
53271 + If the sysctl option is enabled, a sysctl option with name
53272 + "timechange_logging" is created.
53273 +
53274 +config GRKERNSEC_PROC_IPADDR
53275 + bool "/proc/<pid>/ipaddr support"
53276 + default y if GRKERNSEC_CONFIG_AUTO
53277 + help
53278 + If you say Y here, a new entry will be added to each /proc/<pid>
53279 + directory that contains the IP address of the person using the task.
53280 + The IP is carried across local TCP and AF_UNIX stream sockets.
53281 + This information can be useful for IDS/IPSes to perform remote response
53282 + to a local attack. The entry is readable by only the owner of the
53283 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
53284 + the RBAC system), and thus does not create privacy concerns.
53285 +
53286 +config GRKERNSEC_RWXMAP_LOG
53287 + bool 'Denied RWX mmap/mprotect logging'
53288 + default y if GRKERNSEC_CONFIG_AUTO
53289 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
53290 + help
53291 + If you say Y here, calls to mmap() and mprotect() with explicit
53292 + usage of PROT_WRITE and PROT_EXEC together will be logged when
53293 + denied by the PAX_MPROTECT feature. If the sysctl option is
53294 + enabled, a sysctl option with name "rwxmap_logging" is created.
53295 +
53296 +config GRKERNSEC_AUDIT_TEXTREL
53297 + bool 'ELF text relocations logging (READ HELP)'
53298 + depends on PAX_MPROTECT
53299 + help
53300 + If you say Y here, text relocations will be logged with the filename
53301 + of the offending library or binary. The purpose of the feature is
53302 + to help Linux distribution developers get rid of libraries and
53303 + binaries that need text relocations which hinder the future progress
53304 + of PaX. Only Linux distribution developers should say Y here, and
53305 + never on a production machine, as this option creates an information
53306 + leak that could aid an attacker in defeating the randomization of
53307 + a single memory region. If the sysctl option is enabled, a sysctl
53308 + option with name "audit_textrel" is created.
53309 +
53310 +endmenu
53311 +
53312 +menu "Executable Protections"
53313 +depends on GRKERNSEC
53314 +
53315 +config GRKERNSEC_DMESG
53316 + bool "Dmesg(8) restriction"
53317 + default y if GRKERNSEC_CONFIG_AUTO
53318 + help
53319 + If you say Y here, non-root users will not be able to use dmesg(8)
53320 + to view the contents of the kernel's circular log buffer.
53321 + The kernel's log buffer often contains kernel addresses and other
53322 + identifying information useful to an attacker in fingerprinting a
53323 + system for a targeted exploit.
53324 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
53325 + created.
53326 +
53327 +config GRKERNSEC_HARDEN_PTRACE
53328 + bool "Deter ptrace-based process snooping"
53329 + default y if GRKERNSEC_CONFIG_AUTO
53330 + help
53331 + If you say Y here, TTY sniffers and other malicious monitoring
53332 + programs implemented through ptrace will be defeated. If you
53333 + have been using the RBAC system, this option has already been
53334 + enabled for several years for all users, with the ability to make
53335 + fine-grained exceptions.
53336 +
53337 + This option only affects the ability of non-root users to ptrace
53338 + processes that are not a descendent of the ptracing process.
53339 + This means that strace ./binary and gdb ./binary will still work,
53340 + but attaching to arbitrary processes will not. If the sysctl
53341 + option is enabled, a sysctl option with name "harden_ptrace" is
53342 + created.
53343 +
53344 +config GRKERNSEC_PTRACE_READEXEC
53345 + bool "Require read access to ptrace sensitive binaries"
53346 + default y if GRKERNSEC_CONFIG_AUTO
53347 + help
53348 + If you say Y here, unprivileged users will not be able to ptrace unreadable
53349 + binaries. This option is useful in environments that
53350 + remove the read bits (e.g. file mode 4711) from suid binaries to
53351 + prevent infoleaking of their contents. This option adds
53352 + consistency to the use of that file mode, as the binary could normally
53353 + be read out when run without privileges while ptracing.
53354 +
53355 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
53356 + is created.
53357 +
53358 +config GRKERNSEC_SETXID
53359 + bool "Enforce consistent multithreaded privileges"
53360 + default y if GRKERNSEC_CONFIG_AUTO
53361 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
53362 + help
53363 + If you say Y here, a change from a root uid to a non-root uid
53364 + in a multithreaded application will cause the resulting uids,
53365 + gids, supplementary groups, and capabilities in that thread
53366 + to be propagated to the other threads of the process. In most
53367 + cases this is unnecessary, as glibc will emulate this behavior
53368 + on behalf of the application. Other libcs do not act in the
53369 + same way, allowing the other threads of the process to continue
53370 + running with root privileges. If the sysctl option is enabled,
53371 + a sysctl option with name "consistent_setxid" is created.
53372 +
53373 +config GRKERNSEC_TPE
53374 + bool "Trusted Path Execution (TPE)"
53375 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
53376 + help
53377 + If you say Y here, you will be able to choose a gid to add to the
53378 + supplementary groups of users you want to mark as "untrusted."
53379 + These users will not be able to execute any files that are not in
53380 + root-owned directories writable only by root. If the sysctl option
53381 + is enabled, a sysctl option with name "tpe" is created.
53382 +
53383 +config GRKERNSEC_TPE_ALL
53384 + bool "Partially restrict all non-root users"
53385 + depends on GRKERNSEC_TPE
53386 + help
53387 + If you say Y here, all non-root users will be covered under
53388 + a weaker TPE restriction. This is separate from, and in addition to,
53389 + the main TPE options that you have selected elsewhere. Thus, if a
53390 + "trusted" GID is chosen, this restriction applies to even that GID.
53391 + Under this restriction, all non-root users will only be allowed to
53392 + execute files in directories they own that are not group or
53393 + world-writable, or in directories owned by root and writable only by
53394 + root. If the sysctl option is enabled, a sysctl option with name
53395 + "tpe_restrict_all" is created.
53396 +
53397 +config GRKERNSEC_TPE_INVERT
53398 + bool "Invert GID option"
53399 + depends on GRKERNSEC_TPE
53400 + help
53401 + If you say Y here, the group you specify in the TPE configuration will
53402 + decide what group TPE restrictions will be *disabled* for. This
53403 + option is useful if you want TPE restrictions to be applied to most
53404 + users on the system. If the sysctl option is enabled, a sysctl option
53405 + with name "tpe_invert" is created. Unlike other sysctl options, this
53406 + entry will default to on for backward-compatibility.
53407 +
53408 +config GRKERNSEC_TPE_GID
53409 + int
53410 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
53411 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
53412 +
53413 +config GRKERNSEC_TPE_UNTRUSTED_GID
53414 + int "GID for TPE-untrusted users"
53415 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
53416 + default 1005
53417 + help
53418 + Setting this GID determines what group TPE restrictions will be
53419 + *enabled* for. If the sysctl option is enabled, a sysctl option
53420 + with name "tpe_gid" is created.
53421 +
53422 +config GRKERNSEC_TPE_TRUSTED_GID
53423 + int "GID for TPE-trusted users"
53424 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
53425 + default 1005
53426 + help
53427 + Setting this GID determines what group TPE restrictions will be
53428 + *disabled* for. If the sysctl option is enabled, a sysctl option
53429 + with name "tpe_gid" is created.
53430 +
53431 +endmenu
53432 +menu "Network Protections"
53433 +depends on GRKERNSEC
53434 +
53435 +config GRKERNSEC_RANDNET
53436 + bool "Larger entropy pools"
53437 + default y if GRKERNSEC_CONFIG_AUTO
53438 + help
53439 + If you say Y here, the entropy pools used for many features of Linux
53440 + and grsecurity will be doubled in size. Since several grsecurity
53441 + features use additional randomness, it is recommended that you say Y
53442 + here. Saying Y here has a similar effect as modifying
53443 + /proc/sys/kernel/random/poolsize.
53444 +
53445 +config GRKERNSEC_BLACKHOLE
53446 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
53447 + default y if GRKERNSEC_CONFIG_AUTO
53448 + depends on NET
53449 + help
53450 + If you say Y here, neither TCP resets nor ICMP
53451 + destination-unreachable packets will be sent in response to packets
53452 + sent to ports for which no associated listening process exists.
53453 + This feature supports both IPV4 and IPV6 and exempts the
53454 + loopback interface from blackholing. Enabling this feature
53455 + makes a host more resilient to DoS attacks and reduces network
53456 + visibility against scanners.
53457 +
53458 + The blackhole feature as-implemented is equivalent to the FreeBSD
53459 + blackhole feature, as it prevents RST responses to all packets, not
53460 + just SYNs. Under most application behavior this causes no
53461 + problems, but applications (like haproxy) may not close certain
53462 + connections in a way that cleanly terminates them on the remote
53463 + end, leaving the remote host in LAST_ACK state. Because of this
53464 + side-effect and to prevent intentional LAST_ACK DoSes, this
53465 + feature also adds automatic mitigation against such attacks.
53466 + The mitigation drastically reduces the amount of time a socket
53467 + can spend in LAST_ACK state. If you're using haproxy and not
53468 + all servers it connects to have this option enabled, consider
53469 + disabling this feature on the haproxy host.
53470 +
53471 + If the sysctl option is enabled, two sysctl options with names
53472 + "ip_blackhole" and "lastack_retries" will be created.
53473 + While "ip_blackhole" takes the standard zero/non-zero on/off
53474 + toggle, "lastack_retries" uses the same kinds of values as
53475 + "tcp_retries1" and "tcp_retries2". The default value of 4
53476 + prevents a socket from lasting more than 45 seconds in LAST_ACK
53477 + state.
53478 +
53479 +config GRKERNSEC_NO_SIMULT_CONNECT
53480 + bool "Disable TCP Simultaneous Connect"
53481 + default y if GRKERNSEC_CONFIG_AUTO
53482 + depends on NET
53483 + help
53484 + If you say Y here, a feature by Willy Tarreau will be enabled that
53485 + removes a weakness in Linux's strict implementation of TCP that
53486 + allows two clients to connect to each other without either entering
53487 + a listening state. The weakness allows an attacker to easily prevent
53488 + a client from connecting to a known server provided the source port
53489 + for the connection is guessed correctly.
53490 +
53491 + As the weakness could be used to prevent an antivirus or IPS from
53492 + fetching updates, or prevent an SSL gateway from fetching a CRL,
53493 + it should be eliminated by enabling this option. Though Linux is
53494 + one of few operating systems supporting simultaneous connect, it
53495 + has no legitimate use in practice and is rarely supported by firewalls.
53496 +
53497 +config GRKERNSEC_SOCKET
53498 + bool "Socket restrictions"
53499 + depends on NET
53500 + help
53501 + If you say Y here, you will be able to choose from several options.
53502 + If you assign a GID on your system and add it to the supplementary
53503 + groups of users you want to restrict socket access to, this patch
53504 + will perform up to three things, based on the option(s) you choose.
53505 +
53506 +config GRKERNSEC_SOCKET_ALL
53507 + bool "Deny any sockets to group"
53508 + depends on GRKERNSEC_SOCKET
53509 + help
53510 + If you say Y here, you will be able to choose a GID of whose users will
53511 + be unable to connect to other hosts from your machine or run server
53512 + applications from your machine. If the sysctl option is enabled, a
53513 + sysctl option with name "socket_all" is created.
53514 +
53515 +config GRKERNSEC_SOCKET_ALL_GID
53516 + int "GID to deny all sockets for"
53517 + depends on GRKERNSEC_SOCKET_ALL
53518 + default 1004
53519 + help
53520 + Here you can choose the GID to disable socket access for. Remember to
53521 + add the users you want socket access disabled for to the GID
53522 + specified here. If the sysctl option is enabled, a sysctl option
53523 + with name "socket_all_gid" is created.
53524 +
53525 +config GRKERNSEC_SOCKET_CLIENT
53526 + bool "Deny client sockets to group"
53527 + depends on GRKERNSEC_SOCKET
53528 + help
53529 + If you say Y here, you will be able to choose a GID of whose users will
53530 + be unable to connect to other hosts from your machine, but will be
53531 + able to run servers. If this option is enabled, all users in the group
53532 + you specify will have to use passive mode when initiating ftp transfers
53533 + from the shell on your machine. If the sysctl option is enabled, a
53534 + sysctl option with name "socket_client" is created.
53535 +
53536 +config GRKERNSEC_SOCKET_CLIENT_GID
53537 + int "GID to deny client sockets for"
53538 + depends on GRKERNSEC_SOCKET_CLIENT
53539 + default 1003
53540 + help
53541 + Here you can choose the GID to disable client socket access for.
53542 + Remember to add the users you want client socket access disabled for to
53543 + the GID specified here. If the sysctl option is enabled, a sysctl
53544 + option with name "socket_client_gid" is created.
53545 +
53546 +config GRKERNSEC_SOCKET_SERVER
53547 + bool "Deny server sockets to group"
53548 + depends on GRKERNSEC_SOCKET
53549 + help
53550 + If you say Y here, you will be able to choose a GID of whose users will
53551 + be unable to run server applications from your machine. If the sysctl
53552 + option is enabled, a sysctl option with name "socket_server" is created.
53553 +
53554 +config GRKERNSEC_SOCKET_SERVER_GID
53555 + int "GID to deny server sockets for"
53556 + depends on GRKERNSEC_SOCKET_SERVER
53557 + default 1002
53558 + help
53559 + Here you can choose the GID to disable server socket access for.
53560 + Remember to add the users you want server socket access disabled for to
53561 + the GID specified here. If the sysctl option is enabled, a sysctl
53562 + option with name "socket_server_gid" is created.
53563 +
53564 +endmenu
53565 +menu "Sysctl Support"
53566 +depends on GRKERNSEC && SYSCTL
53567 +
53568 +config GRKERNSEC_SYSCTL
53569 + bool "Sysctl support"
53570 + default y if GRKERNSEC_CONFIG_AUTO
53571 + help
53572 + If you say Y here, you will be able to change the options that
53573 + grsecurity runs with at bootup, without having to recompile your
53574 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
53575 + to enable (1) or disable (0) various features. All the sysctl entries
53576 + are mutable until the "grsec_lock" entry is set to a non-zero value.
53577 + All features enabled in the kernel configuration are disabled at boot
53578 + if you do not say Y to the "Turn on features by default" option.
53579 + All options should be set at startup, and the grsec_lock entry should
53580 + be set to a non-zero value after all the options are set.
53581 + *THIS IS EXTREMELY IMPORTANT*
53582 +
53583 +config GRKERNSEC_SYSCTL_DISTRO
53584 + bool "Extra sysctl support for distro makers (READ HELP)"
53585 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
53586 + help
53587 + If you say Y here, additional sysctl options will be created
53588 + for features that affect processes running as root. Therefore,
53589 + it is critical when using this option that the grsec_lock entry be
53590 + enabled after boot. Only distros with prebuilt kernel packages
53591 + with this option enabled that can ensure grsec_lock is enabled
53592 + after boot should use this option.
53593 + *Failure to set grsec_lock after boot makes all grsec features
53594 + this option covers useless*
53595 +
53596 + Currently this option creates the following sysctl entries:
53597 + "Disable Privileged I/O": "disable_priv_io"
53598 +
53599 +config GRKERNSEC_SYSCTL_ON
53600 + bool "Turn on features by default"
53601 + default y if GRKERNSEC_CONFIG_AUTO
53602 + depends on GRKERNSEC_SYSCTL
53603 + help
53604 + If you say Y here, instead of having all features enabled in the
53605 + kernel configuration disabled at boot time, the features will be
53606 + enabled at boot time. It is recommended you say Y here unless
53607 + there is some reason you would want all sysctl-tunable features to
53608 + be disabled by default. As mentioned elsewhere, it is important
53609 + to enable the grsec_lock entry once you have finished modifying
53610 + the sysctl entries.
53611 +
53612 +endmenu
53613 +menu "Logging Options"
53614 +depends on GRKERNSEC
53615 +
53616 +config GRKERNSEC_FLOODTIME
53617 + int "Seconds in between log messages (minimum)"
53618 + default 10
53619 + help
53620 + This option allows you to enforce the number of seconds between
53621 + grsecurity log messages. The default should be suitable for most
53622 + people, however, if you choose to change it, choose a value small enough
53623 + to allow informative logs to be produced, but large enough to
53624 + prevent flooding.
53625 +
53626 +config GRKERNSEC_FLOODBURST
53627 + int "Number of messages in a burst (maximum)"
53628 + default 6
53629 + help
53630 + This option allows you to choose the maximum number of messages allowed
53631 + within the flood time interval you chose in a separate option. The
53632 + default should be suitable for most people, however if you find that
53633 + many of your logs are being interpreted as flooding, you may want to
53634 + raise this value.
53635 +
53636 +endmenu
53637 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
53638 new file mode 100644
53639 index 0000000..1b9afa9
53640 --- /dev/null
53641 +++ b/grsecurity/Makefile
53642 @@ -0,0 +1,38 @@
53643 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
53644 +# during 2001-2009 it has been completely redesigned by Brad Spengler
53645 +# into an RBAC system
53646 +#
53647 +# All code in this directory and various hooks inserted throughout the kernel
53648 +# are copyright Brad Spengler - Open Source Security, Inc., and released
53649 +# under the GPL v2 or higher
53650 +
53651 +KBUILD_CFLAGS += -Werror
53652 +
53653 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
53654 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
53655 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
53656 +
53657 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
53658 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
53659 + gracl_learn.o grsec_log.o
53660 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
53661 +
53662 +ifdef CONFIG_NET
53663 +obj-y += grsec_sock.o
53664 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
53665 +endif
53666 +
53667 +ifndef CONFIG_GRKERNSEC
53668 +obj-y += grsec_disabled.o
53669 +endif
53670 +
53671 +ifdef CONFIG_GRKERNSEC_HIDESYM
53672 +extra-y := grsec_hidesym.o
53673 +$(obj)/grsec_hidesym.o:
53674 + @-chmod -f 500 /boot
53675 + @-chmod -f 500 /lib/modules
53676 + @-chmod -f 500 /lib64/modules
53677 + @-chmod -f 500 /lib32/modules
53678 + @-chmod -f 700 .
53679 + @echo ' grsec: protected kernel image paths'
53680 +endif
53681 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
53682 new file mode 100644
53683 index 0000000..960766a
53684 --- /dev/null
53685 +++ b/grsecurity/gracl.c
53686 @@ -0,0 +1,4003 @@
53687 +#include <linux/kernel.h>
53688 +#include <linux/module.h>
53689 +#include <linux/sched.h>
53690 +#include <linux/mm.h>
53691 +#include <linux/file.h>
53692 +#include <linux/fs.h>
53693 +#include <linux/namei.h>
53694 +#include <linux/mount.h>
53695 +#include <linux/tty.h>
53696 +#include <linux/proc_fs.h>
53697 +#include <linux/lglock.h>
53698 +#include <linux/slab.h>
53699 +#include <linux/vmalloc.h>
53700 +#include <linux/types.h>
53701 +#include <linux/sysctl.h>
53702 +#include <linux/netdevice.h>
53703 +#include <linux/ptrace.h>
53704 +#include <linux/gracl.h>
53705 +#include <linux/gralloc.h>
53706 +#include <linux/security.h>
53707 +#include <linux/grinternal.h>
53708 +#include <linux/pid_namespace.h>
53709 +#include <linux/stop_machine.h>
53710 +#include <linux/fdtable.h>
53711 +#include <linux/percpu.h>
53712 +#include <linux/lglock.h>
53713 +#include "../fs/mount.h"
53714 +
53715 +#include <asm/uaccess.h>
53716 +#include <asm/errno.h>
53717 +#include <asm/mman.h>
53718 +
53719 +extern struct lglock vfsmount_lock;
53720 +
53721 +static struct acl_role_db acl_role_set;
53722 +static struct name_db name_set;
53723 +static struct inodev_db inodev_set;
53724 +
53725 +/* for keeping track of userspace pointers used for subjects, so we
53726 + can share references in the kernel as well
53727 +*/
53728 +
53729 +static struct path real_root;
53730 +
53731 +static struct acl_subj_map_db subj_map_set;
53732 +
53733 +static struct acl_role_label *default_role;
53734 +
53735 +static struct acl_role_label *role_list;
53736 +
53737 +static u16 acl_sp_role_value;
53738 +
53739 +extern char *gr_shared_page[4];
53740 +static DEFINE_MUTEX(gr_dev_mutex);
53741 +DEFINE_RWLOCK(gr_inode_lock);
53742 +
53743 +struct gr_arg *gr_usermode;
53744 +
53745 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
53746 +
53747 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
53748 +extern void gr_clear_learn_entries(void);
53749 +
53750 +unsigned char *gr_system_salt;
53751 +unsigned char *gr_system_sum;
53752 +
53753 +static struct sprole_pw **acl_special_roles = NULL;
53754 +static __u16 num_sprole_pws = 0;
53755 +
53756 +static struct acl_role_label *kernel_role = NULL;
53757 +
53758 +static unsigned int gr_auth_attempts = 0;
53759 +static unsigned long gr_auth_expires = 0UL;
53760 +
53761 +#ifdef CONFIG_NET
53762 +extern struct vfsmount *sock_mnt;
53763 +#endif
53764 +
53765 +extern struct vfsmount *pipe_mnt;
53766 +extern struct vfsmount *shm_mnt;
53767 +#ifdef CONFIG_HUGETLBFS
53768 +extern struct vfsmount *hugetlbfs_vfsmount;
53769 +#endif
53770 +
53771 +static struct acl_object_label *fakefs_obj_rw;
53772 +static struct acl_object_label *fakefs_obj_rwx;
53773 +
53774 +extern int gr_init_uidset(void);
53775 +extern void gr_free_uidset(void);
53776 +extern void gr_remove_uid(uid_t uid);
53777 +extern int gr_find_uid(uid_t uid);
53778 +
53779 +__inline__ int
53780 +gr_acl_is_enabled(void)
53781 +{
53782 + return (gr_status & GR_READY);
53783 +}
53784 +
53785 +#ifdef CONFIG_BTRFS_FS
53786 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
53787 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
53788 +#endif
53789 +
53790 +static inline dev_t __get_dev(const struct dentry *dentry)
53791 +{
53792 +#ifdef CONFIG_BTRFS_FS
53793 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
53794 + return get_btrfs_dev_from_inode(dentry->d_inode);
53795 + else
53796 +#endif
53797 + return dentry->d_inode->i_sb->s_dev;
53798 +}
53799 +
53800 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
53801 +{
53802 + return __get_dev(dentry);
53803 +}
53804 +
53805 +static char gr_task_roletype_to_char(struct task_struct *task)
53806 +{
53807 + switch (task->role->roletype &
53808 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
53809 + GR_ROLE_SPECIAL)) {
53810 + case GR_ROLE_DEFAULT:
53811 + return 'D';
53812 + case GR_ROLE_USER:
53813 + return 'U';
53814 + case GR_ROLE_GROUP:
53815 + return 'G';
53816 + case GR_ROLE_SPECIAL:
53817 + return 'S';
53818 + }
53819 +
53820 + return 'X';
53821 +}
53822 +
53823 +char gr_roletype_to_char(void)
53824 +{
53825 + return gr_task_roletype_to_char(current);
53826 +}
53827 +
53828 +__inline__ int
53829 +gr_acl_tpe_check(void)
53830 +{
53831 + if (unlikely(!(gr_status & GR_READY)))
53832 + return 0;
53833 + if (current->role->roletype & GR_ROLE_TPE)
53834 + return 1;
53835 + else
53836 + return 0;
53837 +}
53838 +
53839 +int
53840 +gr_handle_rawio(const struct inode *inode)
53841 +{
53842 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
53843 + if (inode && S_ISBLK(inode->i_mode) &&
53844 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
53845 + !capable(CAP_SYS_RAWIO))
53846 + return 1;
53847 +#endif
53848 + return 0;
53849 +}
53850 +
53851 +static int
53852 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
53853 +{
53854 + if (likely(lena != lenb))
53855 + return 0;
53856 +
53857 + return !memcmp(a, b, lena);
53858 +}
53859 +
53860 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
53861 +{
53862 + *buflen -= namelen;
53863 + if (*buflen < 0)
53864 + return -ENAMETOOLONG;
53865 + *buffer -= namelen;
53866 + memcpy(*buffer, str, namelen);
53867 + return 0;
53868 +}
53869 +
53870 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
53871 +{
53872 + return prepend(buffer, buflen, name->name, name->len);
53873 +}
53874 +
53875 +static int prepend_path(const struct path *path, struct path *root,
53876 + char **buffer, int *buflen)
53877 +{
53878 + struct dentry *dentry = path->dentry;
53879 + struct vfsmount *vfsmnt = path->mnt;
53880 + struct mount *mnt = real_mount(vfsmnt);
53881 + bool slash = false;
53882 + int error = 0;
53883 +
53884 + while (dentry != root->dentry || vfsmnt != root->mnt) {
53885 + struct dentry * parent;
53886 +
53887 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
53888 + /* Global root? */
53889 + if (!mnt_has_parent(mnt)) {
53890 + goto out;
53891 + }
53892 + dentry = mnt->mnt_mountpoint;
53893 + mnt = mnt->mnt_parent;
53894 + vfsmnt = &mnt->mnt;
53895 + continue;
53896 + }
53897 + parent = dentry->d_parent;
53898 + prefetch(parent);
53899 + spin_lock(&dentry->d_lock);
53900 + error = prepend_name(buffer, buflen, &dentry->d_name);
53901 + spin_unlock(&dentry->d_lock);
53902 + if (!error)
53903 + error = prepend(buffer, buflen, "/", 1);
53904 + if (error)
53905 + break;
53906 +
53907 + slash = true;
53908 + dentry = parent;
53909 + }
53910 +
53911 +out:
53912 + if (!error && !slash)
53913 + error = prepend(buffer, buflen, "/", 1);
53914 +
53915 + return error;
53916 +}
53917 +
53918 +/* this must be called with vfsmount_lock and rename_lock held */
53919 +
53920 +static char *__our_d_path(const struct path *path, struct path *root,
53921 + char *buf, int buflen)
53922 +{
53923 + char *res = buf + buflen;
53924 + int error;
53925 +
53926 + prepend(&res, &buflen, "\0", 1);
53927 + error = prepend_path(path, root, &res, &buflen);
53928 + if (error)
53929 + return ERR_PTR(error);
53930 +
53931 + return res;
53932 +}
53933 +
53934 +static char *
53935 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
53936 +{
53937 + char *retval;
53938 +
53939 + retval = __our_d_path(path, root, buf, buflen);
53940 + if (unlikely(IS_ERR(retval)))
53941 + retval = strcpy(buf, "<path too long>");
53942 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
53943 + retval[1] = '\0';
53944 +
53945 + return retval;
53946 +}
53947 +
53948 +static char *
53949 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
53950 + char *buf, int buflen)
53951 +{
53952 + struct path path;
53953 + char *res;
53954 +
53955 + path.dentry = (struct dentry *)dentry;
53956 + path.mnt = (struct vfsmount *)vfsmnt;
53957 +
53958 + /* we can use real_root.dentry, real_root.mnt, because this is only called
53959 + by the RBAC system */
53960 + res = gen_full_path(&path, &real_root, buf, buflen);
53961 +
53962 + return res;
53963 +}
53964 +
53965 +static char *
53966 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
53967 + char *buf, int buflen)
53968 +{
53969 + char *res;
53970 + struct path path;
53971 + struct path root;
53972 + struct task_struct *reaper = init_pid_ns.child_reaper;
53973 +
53974 + path.dentry = (struct dentry *)dentry;
53975 + path.mnt = (struct vfsmount *)vfsmnt;
53976 +
53977 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
53978 + get_fs_root(reaper->fs, &root);
53979 +
53980 + write_seqlock(&rename_lock);
53981 + br_read_lock(&vfsmount_lock);
53982 + res = gen_full_path(&path, &root, buf, buflen);
53983 + br_read_unlock(&vfsmount_lock);
53984 + write_sequnlock(&rename_lock);
53985 +
53986 + path_put(&root);
53987 + return res;
53988 +}
53989 +
53990 +static char *
53991 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
53992 +{
53993 + char *ret;
53994 + write_seqlock(&rename_lock);
53995 + br_read_lock(&vfsmount_lock);
53996 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
53997 + PAGE_SIZE);
53998 + br_read_unlock(&vfsmount_lock);
53999 + write_sequnlock(&rename_lock);
54000 + return ret;
54001 +}
54002 +
54003 +static char *
54004 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
54005 +{
54006 + char *ret;
54007 + char *buf;
54008 + int buflen;
54009 +
54010 + write_seqlock(&rename_lock);
54011 + br_read_lock(&vfsmount_lock);
54012 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
54013 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
54014 + buflen = (int)(ret - buf);
54015 + if (buflen >= 5)
54016 + prepend(&ret, &buflen, "/proc", 5);
54017 + else
54018 + ret = strcpy(buf, "<path too long>");
54019 + br_read_unlock(&vfsmount_lock);
54020 + write_sequnlock(&rename_lock);
54021 + return ret;
54022 +}
54023 +
54024 +char *
54025 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
54026 +{
54027 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
54028 + PAGE_SIZE);
54029 +}
54030 +
54031 +char *
54032 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
54033 +{
54034 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
54035 + PAGE_SIZE);
54036 +}
54037 +
54038 +char *
54039 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
54040 +{
54041 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
54042 + PAGE_SIZE);
54043 +}
54044 +
54045 +char *
54046 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
54047 +{
54048 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
54049 + PAGE_SIZE);
54050 +}
54051 +
54052 +char *
54053 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
54054 +{
54055 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
54056 + PAGE_SIZE);
54057 +}
54058 +
54059 +__inline__ __u32
54060 +to_gr_audit(const __u32 reqmode)
54061 +{
54062 + /* masks off auditable permission flags, then shifts them to create
54063 + auditing flags, and adds the special case of append auditing if
54064 + we're requesting write */
54065 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
54066 +}
54067 +
54068 +struct acl_subject_label *
54069 +lookup_subject_map(const struct acl_subject_label *userp)
54070 +{
54071 + unsigned int index = gr_shash(userp, subj_map_set.s_size);
54072 + struct subject_map *match;
54073 +
54074 + match = subj_map_set.s_hash[index];
54075 +
54076 + while (match && match->user != userp)
54077 + match = match->next;
54078 +
54079 + if (match != NULL)
54080 + return match->kernel;
54081 + else
54082 + return NULL;
54083 +}
54084 +
54085 +static void
54086 +insert_subj_map_entry(struct subject_map *subjmap)
54087 +{
54088 + unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
54089 + struct subject_map **curr;
54090 +
54091 + subjmap->prev = NULL;
54092 +
54093 + curr = &subj_map_set.s_hash[index];
54094 + if (*curr != NULL)
54095 + (*curr)->prev = subjmap;
54096 +
54097 + subjmap->next = *curr;
54098 + *curr = subjmap;
54099 +
54100 + return;
54101 +}
54102 +
54103 +static struct acl_role_label *
54104 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
54105 + const gid_t gid)
54106 +{
54107 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
54108 + struct acl_role_label *match;
54109 + struct role_allowed_ip *ipp;
54110 + unsigned int x;
54111 + u32 curr_ip = task->signal->curr_ip;
54112 +
54113 + task->signal->saved_ip = curr_ip;
54114 +
54115 + match = acl_role_set.r_hash[index];
54116 +
54117 + while (match) {
54118 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
54119 + for (x = 0; x < match->domain_child_num; x++) {
54120 + if (match->domain_children[x] == uid)
54121 + goto found;
54122 + }
54123 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
54124 + break;
54125 + match = match->next;
54126 + }
54127 +found:
54128 + if (match == NULL) {
54129 + try_group:
54130 + index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
54131 + match = acl_role_set.r_hash[index];
54132 +
54133 + while (match) {
54134 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
54135 + for (x = 0; x < match->domain_child_num; x++) {
54136 + if (match->domain_children[x] == gid)
54137 + goto found2;
54138 + }
54139 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
54140 + break;
54141 + match = match->next;
54142 + }
54143 +found2:
54144 + if (match == NULL)
54145 + match = default_role;
54146 + if (match->allowed_ips == NULL)
54147 + return match;
54148 + else {
54149 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
54150 + if (likely
54151 + ((ntohl(curr_ip) & ipp->netmask) ==
54152 + (ntohl(ipp->addr) & ipp->netmask)))
54153 + return match;
54154 + }
54155 + match = default_role;
54156 + }
54157 + } else if (match->allowed_ips == NULL) {
54158 + return match;
54159 + } else {
54160 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
54161 + if (likely
54162 + ((ntohl(curr_ip) & ipp->netmask) ==
54163 + (ntohl(ipp->addr) & ipp->netmask)))
54164 + return match;
54165 + }
54166 + goto try_group;
54167 + }
54168 +
54169 + return match;
54170 +}
54171 +
54172 +struct acl_subject_label *
54173 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
54174 + const struct acl_role_label *role)
54175 +{
54176 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
54177 + struct acl_subject_label *match;
54178 +
54179 + match = role->subj_hash[index];
54180 +
54181 + while (match && (match->inode != ino || match->device != dev ||
54182 + (match->mode & GR_DELETED))) {
54183 + match = match->next;
54184 + }
54185 +
54186 + if (match && !(match->mode & GR_DELETED))
54187 + return match;
54188 + else
54189 + return NULL;
54190 +}
54191 +
54192 +struct acl_subject_label *
54193 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
54194 + const struct acl_role_label *role)
54195 +{
54196 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
54197 + struct acl_subject_label *match;
54198 +
54199 + match = role->subj_hash[index];
54200 +
54201 + while (match && (match->inode != ino || match->device != dev ||
54202 + !(match->mode & GR_DELETED))) {
54203 + match = match->next;
54204 + }
54205 +
54206 + if (match && (match->mode & GR_DELETED))
54207 + return match;
54208 + else
54209 + return NULL;
54210 +}
54211 +
54212 +static struct acl_object_label *
54213 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
54214 + const struct acl_subject_label *subj)
54215 +{
54216 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
54217 + struct acl_object_label *match;
54218 +
54219 + match = subj->obj_hash[index];
54220 +
54221 + while (match && (match->inode != ino || match->device != dev ||
54222 + (match->mode & GR_DELETED))) {
54223 + match = match->next;
54224 + }
54225 +
54226 + if (match && !(match->mode & GR_DELETED))
54227 + return match;
54228 + else
54229 + return NULL;
54230 +}
54231 +
54232 +static struct acl_object_label *
54233 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
54234 + const struct acl_subject_label *subj)
54235 +{
54236 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
54237 + struct acl_object_label *match;
54238 +
54239 + match = subj->obj_hash[index];
54240 +
54241 + while (match && (match->inode != ino || match->device != dev ||
54242 + !(match->mode & GR_DELETED))) {
54243 + match = match->next;
54244 + }
54245 +
54246 + if (match && (match->mode & GR_DELETED))
54247 + return match;
54248 +
54249 + match = subj->obj_hash[index];
54250 +
54251 + while (match && (match->inode != ino || match->device != dev ||
54252 + (match->mode & GR_DELETED))) {
54253 + match = match->next;
54254 + }
54255 +
54256 + if (match && !(match->mode & GR_DELETED))
54257 + return match;
54258 + else
54259 + return NULL;
54260 +}
54261 +
54262 +static struct name_entry *
54263 +lookup_name_entry(const char *name)
54264 +{
54265 + unsigned int len = strlen(name);
54266 + unsigned int key = full_name_hash(name, len);
54267 + unsigned int index = key % name_set.n_size;
54268 + struct name_entry *match;
54269 +
54270 + match = name_set.n_hash[index];
54271 +
54272 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
54273 + match = match->next;
54274 +
54275 + return match;
54276 +}
54277 +
54278 +static struct name_entry *
54279 +lookup_name_entry_create(const char *name)
54280 +{
54281 + unsigned int len = strlen(name);
54282 + unsigned int key = full_name_hash(name, len);
54283 + unsigned int index = key % name_set.n_size;
54284 + struct name_entry *match;
54285 +
54286 + match = name_set.n_hash[index];
54287 +
54288 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
54289 + !match->deleted))
54290 + match = match->next;
54291 +
54292 + if (match && match->deleted)
54293 + return match;
54294 +
54295 + match = name_set.n_hash[index];
54296 +
54297 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
54298 + match->deleted))
54299 + match = match->next;
54300 +
54301 + if (match && !match->deleted)
54302 + return match;
54303 + else
54304 + return NULL;
54305 +}
54306 +
54307 +static struct inodev_entry *
54308 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
54309 +{
54310 + unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
54311 + struct inodev_entry *match;
54312 +
54313 + match = inodev_set.i_hash[index];
54314 +
54315 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
54316 + match = match->next;
54317 +
54318 + return match;
54319 +}
54320 +
54321 +static void
54322 +insert_inodev_entry(struct inodev_entry *entry)
54323 +{
54324 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
54325 + inodev_set.i_size);
54326 + struct inodev_entry **curr;
54327 +
54328 + entry->prev = NULL;
54329 +
54330 + curr = &inodev_set.i_hash[index];
54331 + if (*curr != NULL)
54332 + (*curr)->prev = entry;
54333 +
54334 + entry->next = *curr;
54335 + *curr = entry;
54336 +
54337 + return;
54338 +}
54339 +
54340 +static void
54341 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
54342 +{
54343 + unsigned int index =
54344 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
54345 + struct acl_role_label **curr;
54346 + struct acl_role_label *tmp, *tmp2;
54347 +
54348 + curr = &acl_role_set.r_hash[index];
54349 +
54350 + /* simple case, slot is empty, just set it to our role */
54351 + if (*curr == NULL) {
54352 + *curr = role;
54353 + } else {
54354 + /* example:
54355 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
54356 + 2 -> 3
54357 + */
54358 + /* first check to see if we can already be reached via this slot */
54359 + tmp = *curr;
54360 + while (tmp && tmp != role)
54361 + tmp = tmp->next;
54362 + if (tmp == role) {
54363 + /* we don't need to add ourselves to this slot's chain */
54364 + return;
54365 + }
54366 + /* we need to add ourselves to this chain, two cases */
54367 + if (role->next == NULL) {
54368 + /* simple case, append the current chain to our role */
54369 + role->next = *curr;
54370 + *curr = role;
54371 + } else {
54372 + /* 1 -> 2 -> 3 -> 4
54373 + 2 -> 3 -> 4
54374 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
54375 + */
54376 + /* trickier case: walk our role's chain until we find
54377 + the role for the start of the current slot's chain */
54378 + tmp = role;
54379 + tmp2 = *curr;
54380 + while (tmp->next && tmp->next != tmp2)
54381 + tmp = tmp->next;
54382 + if (tmp->next == tmp2) {
54383 + /* from example above, we found 3, so just
54384 + replace this slot's chain with ours */
54385 + *curr = role;
54386 + } else {
54387 + /* we didn't find a subset of our role's chain
54388 + in the current slot's chain, so append their
54389 + chain to ours, and set us as the first role in
54390 + the slot's chain
54391 +
54392 + we could fold this case with the case above,
54393 + but making it explicit for clarity
54394 + */
54395 + tmp->next = tmp2;
54396 + *curr = role;
54397 + }
54398 + }
54399 + }
54400 +
54401 + return;
54402 +}
54403 +
54404 +static void
54405 +insert_acl_role_label(struct acl_role_label *role)
54406 +{
54407 + int i;
54408 +
54409 + if (role_list == NULL) {
54410 + role_list = role;
54411 + role->prev = NULL;
54412 + } else {
54413 + role->prev = role_list;
54414 + role_list = role;
54415 + }
54416 +
54417 + /* used for hash chains */
54418 + role->next = NULL;
54419 +
54420 + if (role->roletype & GR_ROLE_DOMAIN) {
54421 + for (i = 0; i < role->domain_child_num; i++)
54422 + __insert_acl_role_label(role, role->domain_children[i]);
54423 + } else
54424 + __insert_acl_role_label(role, role->uidgid);
54425 +}
54426 +
54427 +static int
54428 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
54429 +{
54430 + struct name_entry **curr, *nentry;
54431 + struct inodev_entry *ientry;
54432 + unsigned int len = strlen(name);
54433 + unsigned int key = full_name_hash(name, len);
54434 + unsigned int index = key % name_set.n_size;
54435 +
54436 + curr = &name_set.n_hash[index];
54437 +
54438 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
54439 + curr = &((*curr)->next);
54440 +
54441 + if (*curr != NULL)
54442 + return 1;
54443 +
54444 + nentry = acl_alloc(sizeof (struct name_entry));
54445 + if (nentry == NULL)
54446 + return 0;
54447 + ientry = acl_alloc(sizeof (struct inodev_entry));
54448 + if (ientry == NULL)
54449 + return 0;
54450 + ientry->nentry = nentry;
54451 +
54452 + nentry->key = key;
54453 + nentry->name = name;
54454 + nentry->inode = inode;
54455 + nentry->device = device;
54456 + nentry->len = len;
54457 + nentry->deleted = deleted;
54458 +
54459 + nentry->prev = NULL;
54460 + curr = &name_set.n_hash[index];
54461 + if (*curr != NULL)
54462 + (*curr)->prev = nentry;
54463 + nentry->next = *curr;
54464 + *curr = nentry;
54465 +
54466 + /* insert us into the table searchable by inode/dev */
54467 + insert_inodev_entry(ientry);
54468 +
54469 + return 1;
54470 +}
54471 +
54472 +static void
54473 +insert_acl_obj_label(struct acl_object_label *obj,
54474 + struct acl_subject_label *subj)
54475 +{
54476 + unsigned int index =
54477 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
54478 + struct acl_object_label **curr;
54479 +
54480 +
54481 + obj->prev = NULL;
54482 +
54483 + curr = &subj->obj_hash[index];
54484 + if (*curr != NULL)
54485 + (*curr)->prev = obj;
54486 +
54487 + obj->next = *curr;
54488 + *curr = obj;
54489 +
54490 + return;
54491 +}
54492 +
54493 +static void
54494 +insert_acl_subj_label(struct acl_subject_label *obj,
54495 + struct acl_role_label *role)
54496 +{
54497 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
54498 + struct acl_subject_label **curr;
54499 +
54500 + obj->prev = NULL;
54501 +
54502 + curr = &role->subj_hash[index];
54503 + if (*curr != NULL)
54504 + (*curr)->prev = obj;
54505 +
54506 + obj->next = *curr;
54507 + *curr = obj;
54508 +
54509 + return;
54510 +}
54511 +
54512 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
54513 +
54514 +static void *
54515 +create_table(__u32 * len, int elementsize)
54516 +{
54517 + unsigned int table_sizes[] = {
54518 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
54519 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
54520 + 4194301, 8388593, 16777213, 33554393, 67108859
54521 + };
54522 + void *newtable = NULL;
54523 + unsigned int pwr = 0;
54524 +
54525 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
54526 + table_sizes[pwr] <= *len)
54527 + pwr++;
54528 +
54529 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
54530 + return newtable;
54531 +
54532 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
54533 + newtable =
54534 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
54535 + else
54536 + newtable = vmalloc(table_sizes[pwr] * elementsize);
54537 +
54538 + *len = table_sizes[pwr];
54539 +
54540 + return newtable;
54541 +}
54542 +
54543 +static int
54544 +init_variables(const struct gr_arg *arg)
54545 +{
54546 + struct task_struct *reaper = init_pid_ns.child_reaper;
54547 + unsigned int stacksize;
54548 +
54549 + subj_map_set.s_size = arg->role_db.num_subjects;
54550 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
54551 + name_set.n_size = arg->role_db.num_objects;
54552 + inodev_set.i_size = arg->role_db.num_objects;
54553 +
54554 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
54555 + !name_set.n_size || !inodev_set.i_size)
54556 + return 1;
54557 +
54558 + if (!gr_init_uidset())
54559 + return 1;
54560 +
54561 + /* set up the stack that holds allocation info */
54562 +
54563 + stacksize = arg->role_db.num_pointers + 5;
54564 +
54565 + if (!acl_alloc_stack_init(stacksize))
54566 + return 1;
54567 +
54568 + /* grab reference for the real root dentry and vfsmount */
54569 + get_fs_root(reaper->fs, &real_root);
54570 +
54571 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54572 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
54573 +#endif
54574 +
54575 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
54576 + if (fakefs_obj_rw == NULL)
54577 + return 1;
54578 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
54579 +
54580 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
54581 + if (fakefs_obj_rwx == NULL)
54582 + return 1;
54583 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
54584 +
54585 + subj_map_set.s_hash =
54586 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
54587 + acl_role_set.r_hash =
54588 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
54589 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
54590 + inodev_set.i_hash =
54591 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
54592 +
54593 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
54594 + !name_set.n_hash || !inodev_set.i_hash)
54595 + return 1;
54596 +
54597 + memset(subj_map_set.s_hash, 0,
54598 + sizeof(struct subject_map *) * subj_map_set.s_size);
54599 + memset(acl_role_set.r_hash, 0,
54600 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
54601 + memset(name_set.n_hash, 0,
54602 + sizeof (struct name_entry *) * name_set.n_size);
54603 + memset(inodev_set.i_hash, 0,
54604 + sizeof (struct inodev_entry *) * inodev_set.i_size);
54605 +
54606 + return 0;
54607 +}
54608 +
54609 +/* free information not needed after startup
54610 + currently contains user->kernel pointer mappings for subjects
54611 +*/
54612 +
54613 +static void
54614 +free_init_variables(void)
54615 +{
54616 + __u32 i;
54617 +
54618 + if (subj_map_set.s_hash) {
54619 + for (i = 0; i < subj_map_set.s_size; i++) {
54620 + if (subj_map_set.s_hash[i]) {
54621 + kfree(subj_map_set.s_hash[i]);
54622 + subj_map_set.s_hash[i] = NULL;
54623 + }
54624 + }
54625 +
54626 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
54627 + PAGE_SIZE)
54628 + kfree(subj_map_set.s_hash);
54629 + else
54630 + vfree(subj_map_set.s_hash);
54631 + }
54632 +
54633 + return;
54634 +}
54635 +
54636 +static void
54637 +free_variables(void)
54638 +{
54639 + struct acl_subject_label *s;
54640 + struct acl_role_label *r;
54641 + struct task_struct *task, *task2;
54642 + unsigned int x;
54643 +
54644 + gr_clear_learn_entries();
54645 +
54646 + read_lock(&tasklist_lock);
54647 + do_each_thread(task2, task) {
54648 + task->acl_sp_role = 0;
54649 + task->acl_role_id = 0;
54650 + task->acl = NULL;
54651 + task->role = NULL;
54652 + } while_each_thread(task2, task);
54653 + read_unlock(&tasklist_lock);
54654 +
54655 + /* release the reference to the real root dentry and vfsmount */
54656 + path_put(&real_root);
54657 + memset(&real_root, 0, sizeof(real_root));
54658 +
54659 + /* free all object hash tables */
54660 +
54661 + FOR_EACH_ROLE_START(r)
54662 + if (r->subj_hash == NULL)
54663 + goto next_role;
54664 + FOR_EACH_SUBJECT_START(r, s, x)
54665 + if (s->obj_hash == NULL)
54666 + break;
54667 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
54668 + kfree(s->obj_hash);
54669 + else
54670 + vfree(s->obj_hash);
54671 + FOR_EACH_SUBJECT_END(s, x)
54672 + FOR_EACH_NESTED_SUBJECT_START(r, s)
54673 + if (s->obj_hash == NULL)
54674 + break;
54675 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
54676 + kfree(s->obj_hash);
54677 + else
54678 + vfree(s->obj_hash);
54679 + FOR_EACH_NESTED_SUBJECT_END(s)
54680 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
54681 + kfree(r->subj_hash);
54682 + else
54683 + vfree(r->subj_hash);
54684 + r->subj_hash = NULL;
54685 +next_role:
54686 + FOR_EACH_ROLE_END(r)
54687 +
54688 + acl_free_all();
54689 +
54690 + if (acl_role_set.r_hash) {
54691 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
54692 + PAGE_SIZE)
54693 + kfree(acl_role_set.r_hash);
54694 + else
54695 + vfree(acl_role_set.r_hash);
54696 + }
54697 + if (name_set.n_hash) {
54698 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
54699 + PAGE_SIZE)
54700 + kfree(name_set.n_hash);
54701 + else
54702 + vfree(name_set.n_hash);
54703 + }
54704 +
54705 + if (inodev_set.i_hash) {
54706 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
54707 + PAGE_SIZE)
54708 + kfree(inodev_set.i_hash);
54709 + else
54710 + vfree(inodev_set.i_hash);
54711 + }
54712 +
54713 + gr_free_uidset();
54714 +
54715 + memset(&name_set, 0, sizeof (struct name_db));
54716 + memset(&inodev_set, 0, sizeof (struct inodev_db));
54717 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
54718 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
54719 +
54720 + default_role = NULL;
54721 + kernel_role = NULL;
54722 + role_list = NULL;
54723 +
54724 + return;
54725 +}
54726 +
54727 +static __u32
54728 +count_user_objs(struct acl_object_label *userp)
54729 +{
54730 + struct acl_object_label o_tmp;
54731 + __u32 num = 0;
54732 +
54733 + while (userp) {
54734 + if (copy_from_user(&o_tmp, userp,
54735 + sizeof (struct acl_object_label)))
54736 + break;
54737 +
54738 + userp = o_tmp.prev;
54739 + num++;
54740 + }
54741 +
54742 + return num;
54743 +}
54744 +
54745 +static struct acl_subject_label *
54746 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
54747 +
54748 +static int
54749 +copy_user_glob(struct acl_object_label *obj)
54750 +{
54751 + struct acl_object_label *g_tmp, **guser;
54752 + unsigned int len;
54753 + char *tmp;
54754 +
54755 + if (obj->globbed == NULL)
54756 + return 0;
54757 +
54758 + guser = &obj->globbed;
54759 + while (*guser) {
54760 + g_tmp = (struct acl_object_label *)
54761 + acl_alloc(sizeof (struct acl_object_label));
54762 + if (g_tmp == NULL)
54763 + return -ENOMEM;
54764 +
54765 + if (copy_from_user(g_tmp, *guser,
54766 + sizeof (struct acl_object_label)))
54767 + return -EFAULT;
54768 +
54769 + len = strnlen_user(g_tmp->filename, PATH_MAX);
54770 +
54771 + if (!len || len >= PATH_MAX)
54772 + return -EINVAL;
54773 +
54774 + if ((tmp = (char *) acl_alloc(len)) == NULL)
54775 + return -ENOMEM;
54776 +
54777 + if (copy_from_user(tmp, g_tmp->filename, len))
54778 + return -EFAULT;
54779 + tmp[len-1] = '\0';
54780 + g_tmp->filename = tmp;
54781 +
54782 + *guser = g_tmp;
54783 + guser = &(g_tmp->next);
54784 + }
54785 +
54786 + return 0;
54787 +}
54788 +
54789 +static int
54790 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
54791 + struct acl_role_label *role)
54792 +{
54793 + struct acl_object_label *o_tmp;
54794 + unsigned int len;
54795 + int ret;
54796 + char *tmp;
54797 +
54798 + while (userp) {
54799 + if ((o_tmp = (struct acl_object_label *)
54800 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
54801 + return -ENOMEM;
54802 +
54803 + if (copy_from_user(o_tmp, userp,
54804 + sizeof (struct acl_object_label)))
54805 + return -EFAULT;
54806 +
54807 + userp = o_tmp->prev;
54808 +
54809 + len = strnlen_user(o_tmp->filename, PATH_MAX);
54810 +
54811 + if (!len || len >= PATH_MAX)
54812 + return -EINVAL;
54813 +
54814 + if ((tmp = (char *) acl_alloc(len)) == NULL)
54815 + return -ENOMEM;
54816 +
54817 + if (copy_from_user(tmp, o_tmp->filename, len))
54818 + return -EFAULT;
54819 + tmp[len-1] = '\0';
54820 + o_tmp->filename = tmp;
54821 +
54822 + insert_acl_obj_label(o_tmp, subj);
54823 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
54824 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
54825 + return -ENOMEM;
54826 +
54827 + ret = copy_user_glob(o_tmp);
54828 + if (ret)
54829 + return ret;
54830 +
54831 + if (o_tmp->nested) {
54832 + int already_copied;
54833 +
54834 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
54835 + if (IS_ERR(o_tmp->nested))
54836 + return PTR_ERR(o_tmp->nested);
54837 +
54838 + /* insert into nested subject list if we haven't copied this one yet
54839 + to prevent duplicate entries */
54840 + if (!already_copied) {
54841 + o_tmp->nested->next = role->hash->first;
54842 + role->hash->first = o_tmp->nested;
54843 + }
54844 + }
54845 + }
54846 +
54847 + return 0;
54848 +}
54849 +
54850 +static __u32
54851 +count_user_subjs(struct acl_subject_label *userp)
54852 +{
54853 + struct acl_subject_label s_tmp;
54854 + __u32 num = 0;
54855 +
54856 + while (userp) {
54857 + if (copy_from_user(&s_tmp, userp,
54858 + sizeof (struct acl_subject_label)))
54859 + break;
54860 +
54861 + userp = s_tmp.prev;
54862 + }
54863 +
54864 + return num;
54865 +}
54866 +
54867 +static int
54868 +copy_user_allowedips(struct acl_role_label *rolep)
54869 +{
54870 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
54871 +
54872 + ruserip = rolep->allowed_ips;
54873 +
54874 + while (ruserip) {
54875 + rlast = rtmp;
54876 +
54877 + if ((rtmp = (struct role_allowed_ip *)
54878 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
54879 + return -ENOMEM;
54880 +
54881 + if (copy_from_user(rtmp, ruserip,
54882 + sizeof (struct role_allowed_ip)))
54883 + return -EFAULT;
54884 +
54885 + ruserip = rtmp->prev;
54886 +
54887 + if (!rlast) {
54888 + rtmp->prev = NULL;
54889 + rolep->allowed_ips = rtmp;
54890 + } else {
54891 + rlast->next = rtmp;
54892 + rtmp->prev = rlast;
54893 + }
54894 +
54895 + if (!ruserip)
54896 + rtmp->next = NULL;
54897 + }
54898 +
54899 + return 0;
54900 +}
54901 +
54902 +static int
54903 +copy_user_transitions(struct acl_role_label *rolep)
54904 +{
54905 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
54906 +
54907 + unsigned int len;
54908 + char *tmp;
54909 +
54910 + rusertp = rolep->transitions;
54911 +
54912 + while (rusertp) {
54913 + rlast = rtmp;
54914 +
54915 + if ((rtmp = (struct role_transition *)
54916 + acl_alloc(sizeof (struct role_transition))) == NULL)
54917 + return -ENOMEM;
54918 +
54919 + if (copy_from_user(rtmp, rusertp,
54920 + sizeof (struct role_transition)))
54921 + return -EFAULT;
54922 +
54923 + rusertp = rtmp->prev;
54924 +
54925 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
54926 +
54927 + if (!len || len >= GR_SPROLE_LEN)
54928 + return -EINVAL;
54929 +
54930 + if ((tmp = (char *) acl_alloc(len)) == NULL)
54931 + return -ENOMEM;
54932 +
54933 + if (copy_from_user(tmp, rtmp->rolename, len))
54934 + return -EFAULT;
54935 + tmp[len-1] = '\0';
54936 + rtmp->rolename = tmp;
54937 +
54938 + if (!rlast) {
54939 + rtmp->prev = NULL;
54940 + rolep->transitions = rtmp;
54941 + } else {
54942 + rlast->next = rtmp;
54943 + rtmp->prev = rlast;
54944 + }
54945 +
54946 + if (!rusertp)
54947 + rtmp->next = NULL;
54948 + }
54949 +
54950 + return 0;
54951 +}
54952 +
54953 +static struct acl_subject_label *
54954 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
54955 +{
54956 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
54957 + unsigned int len;
54958 + char *tmp;
54959 + __u32 num_objs;
54960 + struct acl_ip_label **i_tmp, *i_utmp2;
54961 + struct gr_hash_struct ghash;
54962 + struct subject_map *subjmap;
54963 + unsigned int i_num;
54964 + int err;
54965 +
54966 + if (already_copied != NULL)
54967 + *already_copied = 0;
54968 +
54969 + s_tmp = lookup_subject_map(userp);
54970 +
54971 + /* we've already copied this subject into the kernel, just return
54972 + the reference to it, and don't copy it over again
54973 + */
54974 + if (s_tmp) {
54975 + if (already_copied != NULL)
54976 + *already_copied = 1;
54977 + return(s_tmp);
54978 + }
54979 +
54980 + if ((s_tmp = (struct acl_subject_label *)
54981 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
54982 + return ERR_PTR(-ENOMEM);
54983 +
54984 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
54985 + if (subjmap == NULL)
54986 + return ERR_PTR(-ENOMEM);
54987 +
54988 + subjmap->user = userp;
54989 + subjmap->kernel = s_tmp;
54990 + insert_subj_map_entry(subjmap);
54991 +
54992 + if (copy_from_user(s_tmp, userp,
54993 + sizeof (struct acl_subject_label)))
54994 + return ERR_PTR(-EFAULT);
54995 +
54996 + len = strnlen_user(s_tmp->filename, PATH_MAX);
54997 +
54998 + if (!len || len >= PATH_MAX)
54999 + return ERR_PTR(-EINVAL);
55000 +
55001 + if ((tmp = (char *) acl_alloc(len)) == NULL)
55002 + return ERR_PTR(-ENOMEM);
55003 +
55004 + if (copy_from_user(tmp, s_tmp->filename, len))
55005 + return ERR_PTR(-EFAULT);
55006 + tmp[len-1] = '\0';
55007 + s_tmp->filename = tmp;
55008 +
55009 + if (!strcmp(s_tmp->filename, "/"))
55010 + role->root_label = s_tmp;
55011 +
55012 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
55013 + return ERR_PTR(-EFAULT);
55014 +
55015 + /* copy user and group transition tables */
55016 +
55017 + if (s_tmp->user_trans_num) {
55018 + uid_t *uidlist;
55019 +
55020 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
55021 + if (uidlist == NULL)
55022 + return ERR_PTR(-ENOMEM);
55023 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
55024 + return ERR_PTR(-EFAULT);
55025 +
55026 + s_tmp->user_transitions = uidlist;
55027 + }
55028 +
55029 + if (s_tmp->group_trans_num) {
55030 + gid_t *gidlist;
55031 +
55032 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
55033 + if (gidlist == NULL)
55034 + return ERR_PTR(-ENOMEM);
55035 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
55036 + return ERR_PTR(-EFAULT);
55037 +
55038 + s_tmp->group_transitions = gidlist;
55039 + }
55040 +
55041 + /* set up object hash table */
55042 + num_objs = count_user_objs(ghash.first);
55043 +
55044 + s_tmp->obj_hash_size = num_objs;
55045 + s_tmp->obj_hash =
55046 + (struct acl_object_label **)
55047 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
55048 +
55049 + if (!s_tmp->obj_hash)
55050 + return ERR_PTR(-ENOMEM);
55051 +
55052 + memset(s_tmp->obj_hash, 0,
55053 + s_tmp->obj_hash_size *
55054 + sizeof (struct acl_object_label *));
55055 +
55056 + /* add in objects */
55057 + err = copy_user_objs(ghash.first, s_tmp, role);
55058 +
55059 + if (err)
55060 + return ERR_PTR(err);
55061 +
55062 + /* set pointer for parent subject */
55063 + if (s_tmp->parent_subject) {
55064 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
55065 +
55066 + if (IS_ERR(s_tmp2))
55067 + return s_tmp2;
55068 +
55069 + s_tmp->parent_subject = s_tmp2;
55070 + }
55071 +
55072 + /* add in ip acls */
55073 +
55074 + if (!s_tmp->ip_num) {
55075 + s_tmp->ips = NULL;
55076 + goto insert;
55077 + }
55078 +
55079 + i_tmp =
55080 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
55081 + sizeof (struct acl_ip_label *));
55082 +
55083 + if (!i_tmp)
55084 + return ERR_PTR(-ENOMEM);
55085 +
55086 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
55087 + *(i_tmp + i_num) =
55088 + (struct acl_ip_label *)
55089 + acl_alloc(sizeof (struct acl_ip_label));
55090 + if (!*(i_tmp + i_num))
55091 + return ERR_PTR(-ENOMEM);
55092 +
55093 + if (copy_from_user
55094 + (&i_utmp2, s_tmp->ips + i_num,
55095 + sizeof (struct acl_ip_label *)))
55096 + return ERR_PTR(-EFAULT);
55097 +
55098 + if (copy_from_user
55099 + (*(i_tmp + i_num), i_utmp2,
55100 + sizeof (struct acl_ip_label)))
55101 + return ERR_PTR(-EFAULT);
55102 +
55103 + if ((*(i_tmp + i_num))->iface == NULL)
55104 + continue;
55105 +
55106 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
55107 + if (!len || len >= IFNAMSIZ)
55108 + return ERR_PTR(-EINVAL);
55109 + tmp = acl_alloc(len);
55110 + if (tmp == NULL)
55111 + return ERR_PTR(-ENOMEM);
55112 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
55113 + return ERR_PTR(-EFAULT);
55114 + (*(i_tmp + i_num))->iface = tmp;
55115 + }
55116 +
55117 + s_tmp->ips = i_tmp;
55118 +
55119 +insert:
55120 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
55121 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
55122 + return ERR_PTR(-ENOMEM);
55123 +
55124 + return s_tmp;
55125 +}
55126 +
55127 +static int
55128 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
55129 +{
55130 + struct acl_subject_label s_pre;
55131 + struct acl_subject_label * ret;
55132 + int err;
55133 +
55134 + while (userp) {
55135 + if (copy_from_user(&s_pre, userp,
55136 + sizeof (struct acl_subject_label)))
55137 + return -EFAULT;
55138 +
55139 + ret = do_copy_user_subj(userp, role, NULL);
55140 +
55141 + err = PTR_ERR(ret);
55142 + if (IS_ERR(ret))
55143 + return err;
55144 +
55145 + insert_acl_subj_label(ret, role);
55146 +
55147 + userp = s_pre.prev;
55148 + }
55149 +
55150 + return 0;
55151 +}
55152 +
55153 +static int
55154 +copy_user_acl(struct gr_arg *arg)
55155 +{
55156 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
55157 + struct acl_subject_label *subj_list;
55158 + struct sprole_pw *sptmp;
55159 + struct gr_hash_struct *ghash;
55160 + uid_t *domainlist;
55161 + unsigned int r_num;
55162 + unsigned int len;
55163 + char *tmp;
55164 + int err = 0;
55165 + __u16 i;
55166 + __u32 num_subjs;
55167 +
55168 + /* we need a default and kernel role */
55169 + if (arg->role_db.num_roles < 2)
55170 + return -EINVAL;
55171 +
55172 + /* copy special role authentication info from userspace */
55173 +
55174 + num_sprole_pws = arg->num_sprole_pws;
55175 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
55176 +
55177 + if (!acl_special_roles && num_sprole_pws)
55178 + return -ENOMEM;
55179 +
55180 + for (i = 0; i < num_sprole_pws; i++) {
55181 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
55182 + if (!sptmp)
55183 + return -ENOMEM;
55184 + if (copy_from_user(sptmp, arg->sprole_pws + i,
55185 + sizeof (struct sprole_pw)))
55186 + return -EFAULT;
55187 +
55188 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
55189 +
55190 + if (!len || len >= GR_SPROLE_LEN)
55191 + return -EINVAL;
55192 +
55193 + if ((tmp = (char *) acl_alloc(len)) == NULL)
55194 + return -ENOMEM;
55195 +
55196 + if (copy_from_user(tmp, sptmp->rolename, len))
55197 + return -EFAULT;
55198 +
55199 + tmp[len-1] = '\0';
55200 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55201 + printk(KERN_ALERT "Copying special role %s\n", tmp);
55202 +#endif
55203 + sptmp->rolename = tmp;
55204 + acl_special_roles[i] = sptmp;
55205 + }
55206 +
55207 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
55208 +
55209 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
55210 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
55211 +
55212 + if (!r_tmp)
55213 + return -ENOMEM;
55214 +
55215 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
55216 + sizeof (struct acl_role_label *)))
55217 + return -EFAULT;
55218 +
55219 + if (copy_from_user(r_tmp, r_utmp2,
55220 + sizeof (struct acl_role_label)))
55221 + return -EFAULT;
55222 +
55223 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
55224 +
55225 + if (!len || len >= PATH_MAX)
55226 + return -EINVAL;
55227 +
55228 + if ((tmp = (char *) acl_alloc(len)) == NULL)
55229 + return -ENOMEM;
55230 +
55231 + if (copy_from_user(tmp, r_tmp->rolename, len))
55232 + return -EFAULT;
55233 +
55234 + tmp[len-1] = '\0';
55235 + r_tmp->rolename = tmp;
55236 +
55237 + if (!strcmp(r_tmp->rolename, "default")
55238 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
55239 + default_role = r_tmp;
55240 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
55241 + kernel_role = r_tmp;
55242 + }
55243 +
55244 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
55245 + return -ENOMEM;
55246 +
55247 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
55248 + return -EFAULT;
55249 +
55250 + r_tmp->hash = ghash;
55251 +
55252 + num_subjs = count_user_subjs(r_tmp->hash->first);
55253 +
55254 + r_tmp->subj_hash_size = num_subjs;
55255 + r_tmp->subj_hash =
55256 + (struct acl_subject_label **)
55257 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
55258 +
55259 + if (!r_tmp->subj_hash)
55260 + return -ENOMEM;
55261 +
55262 + err = copy_user_allowedips(r_tmp);
55263 + if (err)
55264 + return err;
55265 +
55266 + /* copy domain info */
55267 + if (r_tmp->domain_children != NULL) {
55268 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
55269 + if (domainlist == NULL)
55270 + return -ENOMEM;
55271 +
55272 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
55273 + return -EFAULT;
55274 +
55275 + r_tmp->domain_children = domainlist;
55276 + }
55277 +
55278 + err = copy_user_transitions(r_tmp);
55279 + if (err)
55280 + return err;
55281 +
55282 + memset(r_tmp->subj_hash, 0,
55283 + r_tmp->subj_hash_size *
55284 + sizeof (struct acl_subject_label *));
55285 +
55286 + /* acquire the list of subjects, then NULL out
55287 + the list prior to parsing the subjects for this role,
55288 + as during this parsing the list is replaced with a list
55289 + of *nested* subjects for the role
55290 + */
55291 + subj_list = r_tmp->hash->first;
55292 +
55293 + /* set nested subject list to null */
55294 + r_tmp->hash->first = NULL;
55295 +
55296 + err = copy_user_subjs(subj_list, r_tmp);
55297 +
55298 + if (err)
55299 + return err;
55300 +
55301 + insert_acl_role_label(r_tmp);
55302 + }
55303 +
55304 + if (default_role == NULL || kernel_role == NULL)
55305 + return -EINVAL;
55306 +
55307 + return err;
55308 +}
55309 +
55310 +static int
55311 +gracl_init(struct gr_arg *args)
55312 +{
55313 + int error = 0;
55314 +
55315 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
55316 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
55317 +
55318 + if (init_variables(args)) {
55319 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
55320 + error = -ENOMEM;
55321 + free_variables();
55322 + goto out;
55323 + }
55324 +
55325 + error = copy_user_acl(args);
55326 + free_init_variables();
55327 + if (error) {
55328 + free_variables();
55329 + goto out;
55330 + }
55331 +
55332 + if ((error = gr_set_acls(0))) {
55333 + free_variables();
55334 + goto out;
55335 + }
55336 +
55337 + pax_open_kernel();
55338 + gr_status |= GR_READY;
55339 + pax_close_kernel();
55340 +
55341 + out:
55342 + return error;
55343 +}
55344 +
55345 +/* derived from glibc fnmatch() 0: match, 1: no match*/
55346 +
55347 +static int
55348 +glob_match(const char *p, const char *n)
55349 +{
55350 + char c;
55351 +
55352 + while ((c = *p++) != '\0') {
55353 + switch (c) {
55354 + case '?':
55355 + if (*n == '\0')
55356 + return 1;
55357 + else if (*n == '/')
55358 + return 1;
55359 + break;
55360 + case '\\':
55361 + if (*n != c)
55362 + return 1;
55363 + break;
55364 + case '*':
55365 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
55366 + if (*n == '/')
55367 + return 1;
55368 + else if (c == '?') {
55369 + if (*n == '\0')
55370 + return 1;
55371 + else
55372 + ++n;
55373 + }
55374 + }
55375 + if (c == '\0') {
55376 + return 0;
55377 + } else {
55378 + const char *endp;
55379 +
55380 + if ((endp = strchr(n, '/')) == NULL)
55381 + endp = n + strlen(n);
55382 +
55383 + if (c == '[') {
55384 + for (--p; n < endp; ++n)
55385 + if (!glob_match(p, n))
55386 + return 0;
55387 + } else if (c == '/') {
55388 + while (*n != '\0' && *n != '/')
55389 + ++n;
55390 + if (*n == '/' && !glob_match(p, n + 1))
55391 + return 0;
55392 + } else {
55393 + for (--p; n < endp; ++n)
55394 + if (*n == c && !glob_match(p, n))
55395 + return 0;
55396 + }
55397 +
55398 + return 1;
55399 + }
55400 + case '[':
55401 + {
55402 + int not;
55403 + char cold;
55404 +
55405 + if (*n == '\0' || *n == '/')
55406 + return 1;
55407 +
55408 + not = (*p == '!' || *p == '^');
55409 + if (not)
55410 + ++p;
55411 +
55412 + c = *p++;
55413 + for (;;) {
55414 + unsigned char fn = (unsigned char)*n;
55415 +
55416 + if (c == '\0')
55417 + return 1;
55418 + else {
55419 + if (c == fn)
55420 + goto matched;
55421 + cold = c;
55422 + c = *p++;
55423 +
55424 + if (c == '-' && *p != ']') {
55425 + unsigned char cend = *p++;
55426 +
55427 + if (cend == '\0')
55428 + return 1;
55429 +
55430 + if (cold <= fn && fn <= cend)
55431 + goto matched;
55432 +
55433 + c = *p++;
55434 + }
55435 + }
55436 +
55437 + if (c == ']')
55438 + break;
55439 + }
55440 + if (!not)
55441 + return 1;
55442 + break;
55443 + matched:
55444 + while (c != ']') {
55445 + if (c == '\0')
55446 + return 1;
55447 +
55448 + c = *p++;
55449 + }
55450 + if (not)
55451 + return 1;
55452 + }
55453 + break;
55454 + default:
55455 + if (c != *n)
55456 + return 1;
55457 + }
55458 +
55459 + ++n;
55460 + }
55461 +
55462 + if (*n == '\0')
55463 + return 0;
55464 +
55465 + if (*n == '/')
55466 + return 0;
55467 +
55468 + return 1;
55469 +}
55470 +
55471 +static struct acl_object_label *
55472 +chk_glob_label(struct acl_object_label *globbed,
55473 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
55474 +{
55475 + struct acl_object_label *tmp;
55476 +
55477 + if (*path == NULL)
55478 + *path = gr_to_filename_nolock(dentry, mnt);
55479 +
55480 + tmp = globbed;
55481 +
55482 + while (tmp) {
55483 + if (!glob_match(tmp->filename, *path))
55484 + return tmp;
55485 + tmp = tmp->next;
55486 + }
55487 +
55488 + return NULL;
55489 +}
55490 +
55491 +static struct acl_object_label *
55492 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
55493 + const ino_t curr_ino, const dev_t curr_dev,
55494 + const struct acl_subject_label *subj, char **path, const int checkglob)
55495 +{
55496 + struct acl_subject_label *tmpsubj;
55497 + struct acl_object_label *retval;
55498 + struct acl_object_label *retval2;
55499 +
55500 + tmpsubj = (struct acl_subject_label *) subj;
55501 + read_lock(&gr_inode_lock);
55502 + do {
55503 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
55504 + if (retval) {
55505 + if (checkglob && retval->globbed) {
55506 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
55507 + if (retval2)
55508 + retval = retval2;
55509 + }
55510 + break;
55511 + }
55512 + } while ((tmpsubj = tmpsubj->parent_subject));
55513 + read_unlock(&gr_inode_lock);
55514 +
55515 + return retval;
55516 +}
55517 +
55518 +static __inline__ struct acl_object_label *
55519 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
55520 + struct dentry *curr_dentry,
55521 + const struct acl_subject_label *subj, char **path, const int checkglob)
55522 +{
55523 + int newglob = checkglob;
55524 + ino_t inode;
55525 + dev_t device;
55526 +
55527 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
55528 + as we don't want a / * rule to match instead of the / object
55529 + don't do this for create lookups that call this function though, since they're looking up
55530 + on the parent and thus need globbing checks on all paths
55531 + */
55532 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
55533 + newglob = GR_NO_GLOB;
55534 +
55535 + spin_lock(&curr_dentry->d_lock);
55536 + inode = curr_dentry->d_inode->i_ino;
55537 + device = __get_dev(curr_dentry);
55538 + spin_unlock(&curr_dentry->d_lock);
55539 +
55540 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
55541 +}
55542 +
55543 +static struct acl_object_label *
55544 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55545 + const struct acl_subject_label *subj, char *path, const int checkglob)
55546 +{
55547 + struct dentry *dentry = (struct dentry *) l_dentry;
55548 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
55549 + struct mount *real_mnt = real_mount(mnt);
55550 + struct acl_object_label *retval;
55551 + struct dentry *parent;
55552 +
55553 + write_seqlock(&rename_lock);
55554 + br_read_lock(&vfsmount_lock);
55555 +
55556 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
55557 +#ifdef CONFIG_NET
55558 + mnt == sock_mnt ||
55559 +#endif
55560 +#ifdef CONFIG_HUGETLBFS
55561 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
55562 +#endif
55563 + /* ignore Eric Biederman */
55564 + IS_PRIVATE(l_dentry->d_inode))) {
55565 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
55566 + goto out;
55567 + }
55568 +
55569 + for (;;) {
55570 + if (dentry == real_root.dentry && mnt == real_root.mnt)
55571 + break;
55572 +
55573 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
55574 + if (!mnt_has_parent(real_mnt))
55575 + break;
55576 +
55577 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
55578 + if (retval != NULL)
55579 + goto out;
55580 +
55581 + dentry = real_mnt->mnt_mountpoint;
55582 + real_mnt = real_mnt->mnt_parent;
55583 + mnt = &real_mnt->mnt;
55584 + continue;
55585 + }
55586 +
55587 + parent = dentry->d_parent;
55588 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
55589 + if (retval != NULL)
55590 + goto out;
55591 +
55592 + dentry = parent;
55593 + }
55594 +
55595 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
55596 +
55597 + /* real_root is pinned so we don't have to hold a reference */
55598 + if (retval == NULL)
55599 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
55600 +out:
55601 + br_read_unlock(&vfsmount_lock);
55602 + write_sequnlock(&rename_lock);
55603 +
55604 + BUG_ON(retval == NULL);
55605 +
55606 + return retval;
55607 +}
55608 +
55609 +static __inline__ struct acl_object_label *
55610 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55611 + const struct acl_subject_label *subj)
55612 +{
55613 + char *path = NULL;
55614 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
55615 +}
55616 +
55617 +static __inline__ struct acl_object_label *
55618 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55619 + const struct acl_subject_label *subj)
55620 +{
55621 + char *path = NULL;
55622 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
55623 +}
55624 +
55625 +static __inline__ struct acl_object_label *
55626 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55627 + const struct acl_subject_label *subj, char *path)
55628 +{
55629 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
55630 +}
55631 +
55632 +static struct acl_subject_label *
55633 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55634 + const struct acl_role_label *role)
55635 +{
55636 + struct dentry *dentry = (struct dentry *) l_dentry;
55637 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
55638 + struct mount *real_mnt = real_mount(mnt);
55639 + struct acl_subject_label *retval;
55640 + struct dentry *parent;
55641 +
55642 + write_seqlock(&rename_lock);
55643 + br_read_lock(&vfsmount_lock);
55644 +
55645 + for (;;) {
55646 + if (dentry == real_root.dentry && mnt == real_root.mnt)
55647 + break;
55648 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
55649 + if (!mnt_has_parent(real_mnt))
55650 + break;
55651 +
55652 + spin_lock(&dentry->d_lock);
55653 + read_lock(&gr_inode_lock);
55654 + retval =
55655 + lookup_acl_subj_label(dentry->d_inode->i_ino,
55656 + __get_dev(dentry), role);
55657 + read_unlock(&gr_inode_lock);
55658 + spin_unlock(&dentry->d_lock);
55659 + if (retval != NULL)
55660 + goto out;
55661 +
55662 + dentry = real_mnt->mnt_mountpoint;
55663 + real_mnt = real_mnt->mnt_parent;
55664 + mnt = &real_mnt->mnt;
55665 + continue;
55666 + }
55667 +
55668 + spin_lock(&dentry->d_lock);
55669 + read_lock(&gr_inode_lock);
55670 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
55671 + __get_dev(dentry), role);
55672 + read_unlock(&gr_inode_lock);
55673 + parent = dentry->d_parent;
55674 + spin_unlock(&dentry->d_lock);
55675 +
55676 + if (retval != NULL)
55677 + goto out;
55678 +
55679 + dentry = parent;
55680 + }
55681 +
55682 + spin_lock(&dentry->d_lock);
55683 + read_lock(&gr_inode_lock);
55684 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
55685 + __get_dev(dentry), role);
55686 + read_unlock(&gr_inode_lock);
55687 + spin_unlock(&dentry->d_lock);
55688 +
55689 + if (unlikely(retval == NULL)) {
55690 + /* real_root is pinned, we don't need to hold a reference */
55691 + read_lock(&gr_inode_lock);
55692 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
55693 + __get_dev(real_root.dentry), role);
55694 + read_unlock(&gr_inode_lock);
55695 + }
55696 +out:
55697 + br_read_unlock(&vfsmount_lock);
55698 + write_sequnlock(&rename_lock);
55699 +
55700 + BUG_ON(retval == NULL);
55701 +
55702 + return retval;
55703 +}
55704 +
55705 +static void
55706 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
55707 +{
55708 + struct task_struct *task = current;
55709 + const struct cred *cred = current_cred();
55710 +
55711 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
55712 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
55713 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
55714 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
55715 +
55716 + return;
55717 +}
55718 +
55719 +static void
55720 +gr_log_learn_id_change(const char type, const unsigned int real,
55721 + const unsigned int effective, const unsigned int fs)
55722 +{
55723 + struct task_struct *task = current;
55724 + const struct cred *cred = current_cred();
55725 +
55726 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
55727 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
55728 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
55729 + type, real, effective, fs, &task->signal->saved_ip);
55730 +
55731 + return;
55732 +}
55733 +
55734 +__u32
55735 +gr_search_file(const struct dentry * dentry, const __u32 mode,
55736 + const struct vfsmount * mnt)
55737 +{
55738 + __u32 retval = mode;
55739 + struct acl_subject_label *curracl;
55740 + struct acl_object_label *currobj;
55741 +
55742 + if (unlikely(!(gr_status & GR_READY)))
55743 + return (mode & ~GR_AUDITS);
55744 +
55745 + curracl = current->acl;
55746 +
55747 + currobj = chk_obj_label(dentry, mnt, curracl);
55748 + retval = currobj->mode & mode;
55749 +
55750 + /* if we're opening a specified transfer file for writing
55751 + (e.g. /dev/initctl), then transfer our role to init
55752 + */
55753 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
55754 + current->role->roletype & GR_ROLE_PERSIST)) {
55755 + struct task_struct *task = init_pid_ns.child_reaper;
55756 +
55757 + if (task->role != current->role) {
55758 + task->acl_sp_role = 0;
55759 + task->acl_role_id = current->acl_role_id;
55760 + task->role = current->role;
55761 + rcu_read_lock();
55762 + read_lock(&grsec_exec_file_lock);
55763 + gr_apply_subject_to_task(task);
55764 + read_unlock(&grsec_exec_file_lock);
55765 + rcu_read_unlock();
55766 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
55767 + }
55768 + }
55769 +
55770 + if (unlikely
55771 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
55772 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
55773 + __u32 new_mode = mode;
55774 +
55775 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
55776 +
55777 + retval = new_mode;
55778 +
55779 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
55780 + new_mode |= GR_INHERIT;
55781 +
55782 + if (!(mode & GR_NOLEARN))
55783 + gr_log_learn(dentry, mnt, new_mode);
55784 + }
55785 +
55786 + return retval;
55787 +}
55788 +
55789 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
55790 + const struct dentry *parent,
55791 + const struct vfsmount *mnt)
55792 +{
55793 + struct name_entry *match;
55794 + struct acl_object_label *matchpo;
55795 + struct acl_subject_label *curracl;
55796 + char *path;
55797 +
55798 + if (unlikely(!(gr_status & GR_READY)))
55799 + return NULL;
55800 +
55801 + preempt_disable();
55802 + path = gr_to_filename_rbac(new_dentry, mnt);
55803 + match = lookup_name_entry_create(path);
55804 +
55805 + curracl = current->acl;
55806 +
55807 + if (match) {
55808 + read_lock(&gr_inode_lock);
55809 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
55810 + read_unlock(&gr_inode_lock);
55811 +
55812 + if (matchpo) {
55813 + preempt_enable();
55814 + return matchpo;
55815 + }
55816 + }
55817 +
55818 + // lookup parent
55819 +
55820 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
55821 +
55822 + preempt_enable();
55823 + return matchpo;
55824 +}
55825 +
55826 +__u32
55827 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
55828 + const struct vfsmount * mnt, const __u32 mode)
55829 +{
55830 + struct acl_object_label *matchpo;
55831 + __u32 retval;
55832 +
55833 + if (unlikely(!(gr_status & GR_READY)))
55834 + return (mode & ~GR_AUDITS);
55835 +
55836 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
55837 +
55838 + retval = matchpo->mode & mode;
55839 +
55840 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
55841 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
55842 + __u32 new_mode = mode;
55843 +
55844 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
55845 +
55846 + gr_log_learn(new_dentry, mnt, new_mode);
55847 + return new_mode;
55848 + }
55849 +
55850 + return retval;
55851 +}
55852 +
55853 +__u32
55854 +gr_check_link(const struct dentry * new_dentry,
55855 + const struct dentry * parent_dentry,
55856 + const struct vfsmount * parent_mnt,
55857 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
55858 +{
55859 + struct acl_object_label *obj;
55860 + __u32 oldmode, newmode;
55861 + __u32 needmode;
55862 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
55863 + GR_DELETE | GR_INHERIT;
55864 +
55865 + if (unlikely(!(gr_status & GR_READY)))
55866 + return (GR_CREATE | GR_LINK);
55867 +
55868 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
55869 + oldmode = obj->mode;
55870 +
55871 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
55872 + newmode = obj->mode;
55873 +
55874 + needmode = newmode & checkmodes;
55875 +
55876 + // old name for hardlink must have at least the permissions of the new name
55877 + if ((oldmode & needmode) != needmode)
55878 + goto bad;
55879 +
55880 + // if old name had restrictions/auditing, make sure the new name does as well
55881 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
55882 +
55883 + // don't allow hardlinking of suid/sgid/fcapped files without permission
55884 + if (is_privileged_binary(old_dentry))
55885 + needmode |= GR_SETID;
55886 +
55887 + if ((newmode & needmode) != needmode)
55888 + goto bad;
55889 +
55890 + // enforce minimum permissions
55891 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
55892 + return newmode;
55893 +bad:
55894 + needmode = oldmode;
55895 + if (is_privileged_binary(old_dentry))
55896 + needmode |= GR_SETID;
55897 +
55898 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
55899 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
55900 + return (GR_CREATE | GR_LINK);
55901 + } else if (newmode & GR_SUPPRESS)
55902 + return GR_SUPPRESS;
55903 + else
55904 + return 0;
55905 +}
55906 +
55907 +int
55908 +gr_check_hidden_task(const struct task_struct *task)
55909 +{
55910 + if (unlikely(!(gr_status & GR_READY)))
55911 + return 0;
55912 +
55913 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
55914 + return 1;
55915 +
55916 + return 0;
55917 +}
55918 +
55919 +int
55920 +gr_check_protected_task(const struct task_struct *task)
55921 +{
55922 + if (unlikely(!(gr_status & GR_READY) || !task))
55923 + return 0;
55924 +
55925 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
55926 + task->acl != current->acl)
55927 + return 1;
55928 +
55929 + return 0;
55930 +}
55931 +
55932 +int
55933 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
55934 +{
55935 + struct task_struct *p;
55936 + int ret = 0;
55937 +
55938 + if (unlikely(!(gr_status & GR_READY) || !pid))
55939 + return ret;
55940 +
55941 + read_lock(&tasklist_lock);
55942 + do_each_pid_task(pid, type, p) {
55943 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
55944 + p->acl != current->acl) {
55945 + ret = 1;
55946 + goto out;
55947 + }
55948 + } while_each_pid_task(pid, type, p);
55949 +out:
55950 + read_unlock(&tasklist_lock);
55951 +
55952 + return ret;
55953 +}
55954 +
55955 +void
55956 +gr_copy_label(struct task_struct *tsk)
55957 +{
55958 + tsk->signal->used_accept = 0;
55959 + tsk->acl_sp_role = 0;
55960 + tsk->acl_role_id = current->acl_role_id;
55961 + tsk->acl = current->acl;
55962 + tsk->role = current->role;
55963 + tsk->signal->curr_ip = current->signal->curr_ip;
55964 + tsk->signal->saved_ip = current->signal->saved_ip;
55965 + if (current->exec_file)
55966 + get_file(current->exec_file);
55967 + tsk->exec_file = current->exec_file;
55968 + tsk->is_writable = current->is_writable;
55969 + if (unlikely(current->signal->used_accept)) {
55970 + current->signal->curr_ip = 0;
55971 + current->signal->saved_ip = 0;
55972 + }
55973 +
55974 + return;
55975 +}
55976 +
55977 +static void
55978 +gr_set_proc_res(struct task_struct *task)
55979 +{
55980 + struct acl_subject_label *proc;
55981 + unsigned short i;
55982 +
55983 + proc = task->acl;
55984 +
55985 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
55986 + return;
55987 +
55988 + for (i = 0; i < RLIM_NLIMITS; i++) {
55989 + if (!(proc->resmask & (1 << i)))
55990 + continue;
55991 +
55992 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
55993 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
55994 + }
55995 +
55996 + return;
55997 +}
55998 +
55999 +extern int __gr_process_user_ban(struct user_struct *user);
56000 +
56001 +int
56002 +gr_check_user_change(int real, int effective, int fs)
56003 +{
56004 + unsigned int i;
56005 + __u16 num;
56006 + uid_t *uidlist;
56007 + int curuid;
56008 + int realok = 0;
56009 + int effectiveok = 0;
56010 + int fsok = 0;
56011 +
56012 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
56013 + struct user_struct *user;
56014 +
56015 + if (real == -1)
56016 + goto skipit;
56017 +
56018 + user = find_user(real);
56019 + if (user == NULL)
56020 + goto skipit;
56021 +
56022 + if (__gr_process_user_ban(user)) {
56023 + /* for find_user */
56024 + free_uid(user);
56025 + return 1;
56026 + }
56027 +
56028 + /* for find_user */
56029 + free_uid(user);
56030 +
56031 +skipit:
56032 +#endif
56033 +
56034 + if (unlikely(!(gr_status & GR_READY)))
56035 + return 0;
56036 +
56037 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
56038 + gr_log_learn_id_change('u', real, effective, fs);
56039 +
56040 + num = current->acl->user_trans_num;
56041 + uidlist = current->acl->user_transitions;
56042 +
56043 + if (uidlist == NULL)
56044 + return 0;
56045 +
56046 + if (real == -1)
56047 + realok = 1;
56048 + if (effective == -1)
56049 + effectiveok = 1;
56050 + if (fs == -1)
56051 + fsok = 1;
56052 +
56053 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
56054 + for (i = 0; i < num; i++) {
56055 + curuid = (int)uidlist[i];
56056 + if (real == curuid)
56057 + realok = 1;
56058 + if (effective == curuid)
56059 + effectiveok = 1;
56060 + if (fs == curuid)
56061 + fsok = 1;
56062 + }
56063 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
56064 + for (i = 0; i < num; i++) {
56065 + curuid = (int)uidlist[i];
56066 + if (real == curuid)
56067 + break;
56068 + if (effective == curuid)
56069 + break;
56070 + if (fs == curuid)
56071 + break;
56072 + }
56073 + /* not in deny list */
56074 + if (i == num) {
56075 + realok = 1;
56076 + effectiveok = 1;
56077 + fsok = 1;
56078 + }
56079 + }
56080 +
56081 + if (realok && effectiveok && fsok)
56082 + return 0;
56083 + else {
56084 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
56085 + return 1;
56086 + }
56087 +}
56088 +
56089 +int
56090 +gr_check_group_change(int real, int effective, int fs)
56091 +{
56092 + unsigned int i;
56093 + __u16 num;
56094 + gid_t *gidlist;
56095 + int curgid;
56096 + int realok = 0;
56097 + int effectiveok = 0;
56098 + int fsok = 0;
56099 +
56100 + if (unlikely(!(gr_status & GR_READY)))
56101 + return 0;
56102 +
56103 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
56104 + gr_log_learn_id_change('g', real, effective, fs);
56105 +
56106 + num = current->acl->group_trans_num;
56107 + gidlist = current->acl->group_transitions;
56108 +
56109 + if (gidlist == NULL)
56110 + return 0;
56111 +
56112 + if (real == -1)
56113 + realok = 1;
56114 + if (effective == -1)
56115 + effectiveok = 1;
56116 + if (fs == -1)
56117 + fsok = 1;
56118 +
56119 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
56120 + for (i = 0; i < num; i++) {
56121 + curgid = (int)gidlist[i];
56122 + if (real == curgid)
56123 + realok = 1;
56124 + if (effective == curgid)
56125 + effectiveok = 1;
56126 + if (fs == curgid)
56127 + fsok = 1;
56128 + }
56129 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
56130 + for (i = 0; i < num; i++) {
56131 + curgid = (int)gidlist[i];
56132 + if (real == curgid)
56133 + break;
56134 + if (effective == curgid)
56135 + break;
56136 + if (fs == curgid)
56137 + break;
56138 + }
56139 + /* not in deny list */
56140 + if (i == num) {
56141 + realok = 1;
56142 + effectiveok = 1;
56143 + fsok = 1;
56144 + }
56145 + }
56146 +
56147 + if (realok && effectiveok && fsok)
56148 + return 0;
56149 + else {
56150 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
56151 + return 1;
56152 + }
56153 +}
56154 +
56155 +extern int gr_acl_is_capable(const int cap);
56156 +
56157 +void
56158 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
56159 +{
56160 + struct acl_role_label *role = task->role;
56161 + struct acl_subject_label *subj = NULL;
56162 + struct acl_object_label *obj;
56163 + struct file *filp;
56164 +
56165 + if (unlikely(!(gr_status & GR_READY)))
56166 + return;
56167 +
56168 + filp = task->exec_file;
56169 +
56170 + /* kernel process, we'll give them the kernel role */
56171 + if (unlikely(!filp)) {
56172 + task->role = kernel_role;
56173 + task->acl = kernel_role->root_label;
56174 + return;
56175 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
56176 + role = lookup_acl_role_label(task, uid, gid);
56177 +
56178 + /* don't change the role if we're not a privileged process */
56179 + if (role && task->role != role &&
56180 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
56181 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
56182 + return;
56183 +
56184 + /* perform subject lookup in possibly new role
56185 + we can use this result below in the case where role == task->role
56186 + */
56187 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
56188 +
56189 + /* if we changed uid/gid, but result in the same role
56190 + and are using inheritance, don't lose the inherited subject
56191 + if current subject is other than what normal lookup
56192 + would result in, we arrived via inheritance, don't
56193 + lose subject
56194 + */
56195 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
56196 + (subj == task->acl)))
56197 + task->acl = subj;
56198 +
56199 + task->role = role;
56200 +
56201 + task->is_writable = 0;
56202 +
56203 + /* ignore additional mmap checks for processes that are writable
56204 + by the default ACL */
56205 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
56206 + if (unlikely(obj->mode & GR_WRITE))
56207 + task->is_writable = 1;
56208 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
56209 + if (unlikely(obj->mode & GR_WRITE))
56210 + task->is_writable = 1;
56211 +
56212 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56213 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
56214 +#endif
56215 +
56216 + gr_set_proc_res(task);
56217 +
56218 + return;
56219 +}
56220 +
56221 +int
56222 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
56223 + const int unsafe_flags)
56224 +{
56225 + struct task_struct *task = current;
56226 + struct acl_subject_label *newacl;
56227 + struct acl_object_label *obj;
56228 + __u32 retmode;
56229 +
56230 + if (unlikely(!(gr_status & GR_READY)))
56231 + return 0;
56232 +
56233 + newacl = chk_subj_label(dentry, mnt, task->role);
56234 +
56235 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
56236 + did an exec
56237 + */
56238 + rcu_read_lock();
56239 + read_lock(&tasklist_lock);
56240 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
56241 + (task->parent->acl->mode & GR_POVERRIDE))) {
56242 + read_unlock(&tasklist_lock);
56243 + rcu_read_unlock();
56244 + goto skip_check;
56245 + }
56246 + read_unlock(&tasklist_lock);
56247 + rcu_read_unlock();
56248 +
56249 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
56250 + !(task->role->roletype & GR_ROLE_GOD) &&
56251 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
56252 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
56253 + if (unsafe_flags & LSM_UNSAFE_SHARE)
56254 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
56255 + else
56256 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
56257 + return -EACCES;
56258 + }
56259 +
56260 +skip_check:
56261 +
56262 + obj = chk_obj_label(dentry, mnt, task->acl);
56263 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
56264 +
56265 + if (!(task->acl->mode & GR_INHERITLEARN) &&
56266 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
56267 + if (obj->nested)
56268 + task->acl = obj->nested;
56269 + else
56270 + task->acl = newacl;
56271 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
56272 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
56273 +
56274 + task->is_writable = 0;
56275 +
56276 + /* ignore additional mmap checks for processes that are writable
56277 + by the default ACL */
56278 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
56279 + if (unlikely(obj->mode & GR_WRITE))
56280 + task->is_writable = 1;
56281 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
56282 + if (unlikely(obj->mode & GR_WRITE))
56283 + task->is_writable = 1;
56284 +
56285 + gr_set_proc_res(task);
56286 +
56287 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56288 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
56289 +#endif
56290 + return 0;
56291 +}
56292 +
56293 +/* always called with valid inodev ptr */
56294 +static void
56295 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
56296 +{
56297 + struct acl_object_label *matchpo;
56298 + struct acl_subject_label *matchps;
56299 + struct acl_subject_label *subj;
56300 + struct acl_role_label *role;
56301 + unsigned int x;
56302 +
56303 + FOR_EACH_ROLE_START(role)
56304 + FOR_EACH_SUBJECT_START(role, subj, x)
56305 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
56306 + matchpo->mode |= GR_DELETED;
56307 + FOR_EACH_SUBJECT_END(subj,x)
56308 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
56309 + /* nested subjects aren't in the role's subj_hash table */
56310 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
56311 + matchpo->mode |= GR_DELETED;
56312 + FOR_EACH_NESTED_SUBJECT_END(subj)
56313 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
56314 + matchps->mode |= GR_DELETED;
56315 + FOR_EACH_ROLE_END(role)
56316 +
56317 + inodev->nentry->deleted = 1;
56318 +
56319 + return;
56320 +}
56321 +
56322 +void
56323 +gr_handle_delete(const ino_t ino, const dev_t dev)
56324 +{
56325 + struct inodev_entry *inodev;
56326 +
56327 + if (unlikely(!(gr_status & GR_READY)))
56328 + return;
56329 +
56330 + write_lock(&gr_inode_lock);
56331 + inodev = lookup_inodev_entry(ino, dev);
56332 + if (inodev != NULL)
56333 + do_handle_delete(inodev, ino, dev);
56334 + write_unlock(&gr_inode_lock);
56335 +
56336 + return;
56337 +}
56338 +
56339 +static void
56340 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
56341 + const ino_t newinode, const dev_t newdevice,
56342 + struct acl_subject_label *subj)
56343 +{
56344 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
56345 + struct acl_object_label *match;
56346 +
56347 + match = subj->obj_hash[index];
56348 +
56349 + while (match && (match->inode != oldinode ||
56350 + match->device != olddevice ||
56351 + !(match->mode & GR_DELETED)))
56352 + match = match->next;
56353 +
56354 + if (match && (match->inode == oldinode)
56355 + && (match->device == olddevice)
56356 + && (match->mode & GR_DELETED)) {
56357 + if (match->prev == NULL) {
56358 + subj->obj_hash[index] = match->next;
56359 + if (match->next != NULL)
56360 + match->next->prev = NULL;
56361 + } else {
56362 + match->prev->next = match->next;
56363 + if (match->next != NULL)
56364 + match->next->prev = match->prev;
56365 + }
56366 + match->prev = NULL;
56367 + match->next = NULL;
56368 + match->inode = newinode;
56369 + match->device = newdevice;
56370 + match->mode &= ~GR_DELETED;
56371 +
56372 + insert_acl_obj_label(match, subj);
56373 + }
56374 +
56375 + return;
56376 +}
56377 +
56378 +static void
56379 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
56380 + const ino_t newinode, const dev_t newdevice,
56381 + struct acl_role_label *role)
56382 +{
56383 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
56384 + struct acl_subject_label *match;
56385 +
56386 + match = role->subj_hash[index];
56387 +
56388 + while (match && (match->inode != oldinode ||
56389 + match->device != olddevice ||
56390 + !(match->mode & GR_DELETED)))
56391 + match = match->next;
56392 +
56393 + if (match && (match->inode == oldinode)
56394 + && (match->device == olddevice)
56395 + && (match->mode & GR_DELETED)) {
56396 + if (match->prev == NULL) {
56397 + role->subj_hash[index] = match->next;
56398 + if (match->next != NULL)
56399 + match->next->prev = NULL;
56400 + } else {
56401 + match->prev->next = match->next;
56402 + if (match->next != NULL)
56403 + match->next->prev = match->prev;
56404 + }
56405 + match->prev = NULL;
56406 + match->next = NULL;
56407 + match->inode = newinode;
56408 + match->device = newdevice;
56409 + match->mode &= ~GR_DELETED;
56410 +
56411 + insert_acl_subj_label(match, role);
56412 + }
56413 +
56414 + return;
56415 +}
56416 +
56417 +static void
56418 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
56419 + const ino_t newinode, const dev_t newdevice)
56420 +{
56421 + unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
56422 + struct inodev_entry *match;
56423 +
56424 + match = inodev_set.i_hash[index];
56425 +
56426 + while (match && (match->nentry->inode != oldinode ||
56427 + match->nentry->device != olddevice || !match->nentry->deleted))
56428 + match = match->next;
56429 +
56430 + if (match && (match->nentry->inode == oldinode)
56431 + && (match->nentry->device == olddevice) &&
56432 + match->nentry->deleted) {
56433 + if (match->prev == NULL) {
56434 + inodev_set.i_hash[index] = match->next;
56435 + if (match->next != NULL)
56436 + match->next->prev = NULL;
56437 + } else {
56438 + match->prev->next = match->next;
56439 + if (match->next != NULL)
56440 + match->next->prev = match->prev;
56441 + }
56442 + match->prev = NULL;
56443 + match->next = NULL;
56444 + match->nentry->inode = newinode;
56445 + match->nentry->device = newdevice;
56446 + match->nentry->deleted = 0;
56447 +
56448 + insert_inodev_entry(match);
56449 + }
56450 +
56451 + return;
56452 +}
56453 +
56454 +static void
56455 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
56456 +{
56457 + struct acl_subject_label *subj;
56458 + struct acl_role_label *role;
56459 + unsigned int x;
56460 +
56461 + FOR_EACH_ROLE_START(role)
56462 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
56463 +
56464 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
56465 + if ((subj->inode == ino) && (subj->device == dev)) {
56466 + subj->inode = ino;
56467 + subj->device = dev;
56468 + }
56469 + /* nested subjects aren't in the role's subj_hash table */
56470 + update_acl_obj_label(matchn->inode, matchn->device,
56471 + ino, dev, subj);
56472 + FOR_EACH_NESTED_SUBJECT_END(subj)
56473 + FOR_EACH_SUBJECT_START(role, subj, x)
56474 + update_acl_obj_label(matchn->inode, matchn->device,
56475 + ino, dev, subj);
56476 + FOR_EACH_SUBJECT_END(subj,x)
56477 + FOR_EACH_ROLE_END(role)
56478 +
56479 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
56480 +
56481 + return;
56482 +}
56483 +
56484 +static void
56485 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
56486 + const struct vfsmount *mnt)
56487 +{
56488 + ino_t ino = dentry->d_inode->i_ino;
56489 + dev_t dev = __get_dev(dentry);
56490 +
56491 + __do_handle_create(matchn, ino, dev);
56492 +
56493 + return;
56494 +}
56495 +
56496 +void
56497 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
56498 +{
56499 + struct name_entry *matchn;
56500 +
56501 + if (unlikely(!(gr_status & GR_READY)))
56502 + return;
56503 +
56504 + preempt_disable();
56505 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
56506 +
56507 + if (unlikely((unsigned long)matchn)) {
56508 + write_lock(&gr_inode_lock);
56509 + do_handle_create(matchn, dentry, mnt);
56510 + write_unlock(&gr_inode_lock);
56511 + }
56512 + preempt_enable();
56513 +
56514 + return;
56515 +}
56516 +
56517 +void
56518 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
56519 +{
56520 + struct name_entry *matchn;
56521 +
56522 + if (unlikely(!(gr_status & GR_READY)))
56523 + return;
56524 +
56525 + preempt_disable();
56526 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
56527 +
56528 + if (unlikely((unsigned long)matchn)) {
56529 + write_lock(&gr_inode_lock);
56530 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
56531 + write_unlock(&gr_inode_lock);
56532 + }
56533 + preempt_enable();
56534 +
56535 + return;
56536 +}
56537 +
56538 +void
56539 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
56540 + struct dentry *old_dentry,
56541 + struct dentry *new_dentry,
56542 + struct vfsmount *mnt, const __u8 replace)
56543 +{
56544 + struct name_entry *matchn;
56545 + struct inodev_entry *inodev;
56546 + struct inode *inode = new_dentry->d_inode;
56547 + ino_t old_ino = old_dentry->d_inode->i_ino;
56548 + dev_t old_dev = __get_dev(old_dentry);
56549 +
56550 + /* vfs_rename swaps the name and parent link for old_dentry and
56551 + new_dentry
56552 + at this point, old_dentry has the new name, parent link, and inode
56553 + for the renamed file
56554 + if a file is being replaced by a rename, new_dentry has the inode
56555 + and name for the replaced file
56556 + */
56557 +
56558 + if (unlikely(!(gr_status & GR_READY)))
56559 + return;
56560 +
56561 + preempt_disable();
56562 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
56563 +
56564 + /* we wouldn't have to check d_inode if it weren't for
56565 + NFS silly-renaming
56566 + */
56567 +
56568 + write_lock(&gr_inode_lock);
56569 + if (unlikely(replace && inode)) {
56570 + ino_t new_ino = inode->i_ino;
56571 + dev_t new_dev = __get_dev(new_dentry);
56572 +
56573 + inodev = lookup_inodev_entry(new_ino, new_dev);
56574 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
56575 + do_handle_delete(inodev, new_ino, new_dev);
56576 + }
56577 +
56578 + inodev = lookup_inodev_entry(old_ino, old_dev);
56579 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
56580 + do_handle_delete(inodev, old_ino, old_dev);
56581 +
56582 + if (unlikely((unsigned long)matchn))
56583 + do_handle_create(matchn, old_dentry, mnt);
56584 +
56585 + write_unlock(&gr_inode_lock);
56586 + preempt_enable();
56587 +
56588 + return;
56589 +}
56590 +
56591 +static int
56592 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
56593 + unsigned char **sum)
56594 +{
56595 + struct acl_role_label *r;
56596 + struct role_allowed_ip *ipp;
56597 + struct role_transition *trans;
56598 + unsigned int i;
56599 + int found = 0;
56600 + u32 curr_ip = current->signal->curr_ip;
56601 +
56602 + current->signal->saved_ip = curr_ip;
56603 +
56604 + /* check transition table */
56605 +
56606 + for (trans = current->role->transitions; trans; trans = trans->next) {
56607 + if (!strcmp(rolename, trans->rolename)) {
56608 + found = 1;
56609 + break;
56610 + }
56611 + }
56612 +
56613 + if (!found)
56614 + return 0;
56615 +
56616 + /* handle special roles that do not require authentication
56617 + and check ip */
56618 +
56619 + FOR_EACH_ROLE_START(r)
56620 + if (!strcmp(rolename, r->rolename) &&
56621 + (r->roletype & GR_ROLE_SPECIAL)) {
56622 + found = 0;
56623 + if (r->allowed_ips != NULL) {
56624 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
56625 + if ((ntohl(curr_ip) & ipp->netmask) ==
56626 + (ntohl(ipp->addr) & ipp->netmask))
56627 + found = 1;
56628 + }
56629 + } else
56630 + found = 2;
56631 + if (!found)
56632 + return 0;
56633 +
56634 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
56635 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
56636 + *salt = NULL;
56637 + *sum = NULL;
56638 + return 1;
56639 + }
56640 + }
56641 + FOR_EACH_ROLE_END(r)
56642 +
56643 + for (i = 0; i < num_sprole_pws; i++) {
56644 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
56645 + *salt = acl_special_roles[i]->salt;
56646 + *sum = acl_special_roles[i]->sum;
56647 + return 1;
56648 + }
56649 + }
56650 +
56651 + return 0;
56652 +}
56653 +
56654 +static void
56655 +assign_special_role(char *rolename)
56656 +{
56657 + struct acl_object_label *obj;
56658 + struct acl_role_label *r;
56659 + struct acl_role_label *assigned = NULL;
56660 + struct task_struct *tsk;
56661 + struct file *filp;
56662 +
56663 + FOR_EACH_ROLE_START(r)
56664 + if (!strcmp(rolename, r->rolename) &&
56665 + (r->roletype & GR_ROLE_SPECIAL)) {
56666 + assigned = r;
56667 + break;
56668 + }
56669 + FOR_EACH_ROLE_END(r)
56670 +
56671 + if (!assigned)
56672 + return;
56673 +
56674 + read_lock(&tasklist_lock);
56675 + read_lock(&grsec_exec_file_lock);
56676 +
56677 + tsk = current->real_parent;
56678 + if (tsk == NULL)
56679 + goto out_unlock;
56680 +
56681 + filp = tsk->exec_file;
56682 + if (filp == NULL)
56683 + goto out_unlock;
56684 +
56685 + tsk->is_writable = 0;
56686 +
56687 + tsk->acl_sp_role = 1;
56688 + tsk->acl_role_id = ++acl_sp_role_value;
56689 + tsk->role = assigned;
56690 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
56691 +
56692 + /* ignore additional mmap checks for processes that are writable
56693 + by the default ACL */
56694 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
56695 + if (unlikely(obj->mode & GR_WRITE))
56696 + tsk->is_writable = 1;
56697 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
56698 + if (unlikely(obj->mode & GR_WRITE))
56699 + tsk->is_writable = 1;
56700 +
56701 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56702 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
56703 +#endif
56704 +
56705 +out_unlock:
56706 + read_unlock(&grsec_exec_file_lock);
56707 + read_unlock(&tasklist_lock);
56708 + return;
56709 +}
56710 +
56711 +int gr_check_secure_terminal(struct task_struct *task)
56712 +{
56713 + struct task_struct *p, *p2, *p3;
56714 + struct files_struct *files;
56715 + struct fdtable *fdt;
56716 + struct file *our_file = NULL, *file;
56717 + int i;
56718 +
56719 + if (task->signal->tty == NULL)
56720 + return 1;
56721 +
56722 + files = get_files_struct(task);
56723 + if (files != NULL) {
56724 + rcu_read_lock();
56725 + fdt = files_fdtable(files);
56726 + for (i=0; i < fdt->max_fds; i++) {
56727 + file = fcheck_files(files, i);
56728 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
56729 + get_file(file);
56730 + our_file = file;
56731 + }
56732 + }
56733 + rcu_read_unlock();
56734 + put_files_struct(files);
56735 + }
56736 +
56737 + if (our_file == NULL)
56738 + return 1;
56739 +
56740 + read_lock(&tasklist_lock);
56741 + do_each_thread(p2, p) {
56742 + files = get_files_struct(p);
56743 + if (files == NULL ||
56744 + (p->signal && p->signal->tty == task->signal->tty)) {
56745 + if (files != NULL)
56746 + put_files_struct(files);
56747 + continue;
56748 + }
56749 + rcu_read_lock();
56750 + fdt = files_fdtable(files);
56751 + for (i=0; i < fdt->max_fds; i++) {
56752 + file = fcheck_files(files, i);
56753 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
56754 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
56755 + p3 = task;
56756 + while (p3->pid > 0) {
56757 + if (p3 == p)
56758 + break;
56759 + p3 = p3->real_parent;
56760 + }
56761 + if (p3 == p)
56762 + break;
56763 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
56764 + gr_handle_alertkill(p);
56765 + rcu_read_unlock();
56766 + put_files_struct(files);
56767 + read_unlock(&tasklist_lock);
56768 + fput(our_file);
56769 + return 0;
56770 + }
56771 + }
56772 + rcu_read_unlock();
56773 + put_files_struct(files);
56774 + } while_each_thread(p2, p);
56775 + read_unlock(&tasklist_lock);
56776 +
56777 + fput(our_file);
56778 + return 1;
56779 +}
56780 +
56781 +static int gr_rbac_disable(void *unused)
56782 +{
56783 + pax_open_kernel();
56784 + gr_status &= ~GR_READY;
56785 + pax_close_kernel();
56786 +
56787 + return 0;
56788 +}
56789 +
56790 +ssize_t
56791 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
56792 +{
56793 + struct gr_arg_wrapper uwrap;
56794 + unsigned char *sprole_salt = NULL;
56795 + unsigned char *sprole_sum = NULL;
56796 + int error = sizeof (struct gr_arg_wrapper);
56797 + int error2 = 0;
56798 +
56799 + mutex_lock(&gr_dev_mutex);
56800 +
56801 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
56802 + error = -EPERM;
56803 + goto out;
56804 + }
56805 +
56806 + if (count != sizeof (struct gr_arg_wrapper)) {
56807 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
56808 + error = -EINVAL;
56809 + goto out;
56810 + }
56811 +
56812 +
56813 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
56814 + gr_auth_expires = 0;
56815 + gr_auth_attempts = 0;
56816 + }
56817 +
56818 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
56819 + error = -EFAULT;
56820 + goto out;
56821 + }
56822 +
56823 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
56824 + error = -EINVAL;
56825 + goto out;
56826 + }
56827 +
56828 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
56829 + error = -EFAULT;
56830 + goto out;
56831 + }
56832 +
56833 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
56834 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
56835 + time_after(gr_auth_expires, get_seconds())) {
56836 + error = -EBUSY;
56837 + goto out;
56838 + }
56839 +
56840 + /* if non-root trying to do anything other than use a special role,
56841 + do not attempt authentication, do not count towards authentication
56842 + locking
56843 + */
56844 +
56845 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
56846 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
56847 + !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
56848 + error = -EPERM;
56849 + goto out;
56850 + }
56851 +
56852 + /* ensure pw and special role name are null terminated */
56853 +
56854 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
56855 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
56856 +
56857 + /* Okay.
56858 + * We have our enough of the argument structure..(we have yet
56859 + * to copy_from_user the tables themselves) . Copy the tables
56860 + * only if we need them, i.e. for loading operations. */
56861 +
56862 + switch (gr_usermode->mode) {
56863 + case GR_STATUS:
56864 + if (gr_status & GR_READY) {
56865 + error = 1;
56866 + if (!gr_check_secure_terminal(current))
56867 + error = 3;
56868 + } else
56869 + error = 2;
56870 + goto out;
56871 + case GR_SHUTDOWN:
56872 + if ((gr_status & GR_READY)
56873 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
56874 + stop_machine(gr_rbac_disable, NULL, NULL);
56875 + free_variables();
56876 + memset(gr_usermode, 0, sizeof (struct gr_arg));
56877 + memset(gr_system_salt, 0, GR_SALT_LEN);
56878 + memset(gr_system_sum, 0, GR_SHA_LEN);
56879 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
56880 + } else if (gr_status & GR_READY) {
56881 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
56882 + error = -EPERM;
56883 + } else {
56884 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
56885 + error = -EAGAIN;
56886 + }
56887 + break;
56888 + case GR_ENABLE:
56889 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
56890 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
56891 + else {
56892 + if (gr_status & GR_READY)
56893 + error = -EAGAIN;
56894 + else
56895 + error = error2;
56896 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
56897 + }
56898 + break;
56899 + case GR_RELOAD:
56900 + if (!(gr_status & GR_READY)) {
56901 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
56902 + error = -EAGAIN;
56903 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
56904 + stop_machine(gr_rbac_disable, NULL, NULL);
56905 + free_variables();
56906 + error2 = gracl_init(gr_usermode);
56907 + if (!error2)
56908 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
56909 + else {
56910 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
56911 + error = error2;
56912 + }
56913 + } else {
56914 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
56915 + error = -EPERM;
56916 + }
56917 + break;
56918 + case GR_SEGVMOD:
56919 + if (unlikely(!(gr_status & GR_READY))) {
56920 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
56921 + error = -EAGAIN;
56922 + break;
56923 + }
56924 +
56925 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
56926 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
56927 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
56928 + struct acl_subject_label *segvacl;
56929 + segvacl =
56930 + lookup_acl_subj_label(gr_usermode->segv_inode,
56931 + gr_usermode->segv_device,
56932 + current->role);
56933 + if (segvacl) {
56934 + segvacl->crashes = 0;
56935 + segvacl->expires = 0;
56936 + }
56937 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
56938 + gr_remove_uid(gr_usermode->segv_uid);
56939 + }
56940 + } else {
56941 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
56942 + error = -EPERM;
56943 + }
56944 + break;
56945 + case GR_SPROLE:
56946 + case GR_SPROLEPAM:
56947 + if (unlikely(!(gr_status & GR_READY))) {
56948 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
56949 + error = -EAGAIN;
56950 + break;
56951 + }
56952 +
56953 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
56954 + current->role->expires = 0;
56955 + current->role->auth_attempts = 0;
56956 + }
56957 +
56958 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
56959 + time_after(current->role->expires, get_seconds())) {
56960 + error = -EBUSY;
56961 + goto out;
56962 + }
56963 +
56964 + if (lookup_special_role_auth
56965 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
56966 + && ((!sprole_salt && !sprole_sum)
56967 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
56968 + char *p = "";
56969 + assign_special_role(gr_usermode->sp_role);
56970 + read_lock(&tasklist_lock);
56971 + if (current->real_parent)
56972 + p = current->real_parent->role->rolename;
56973 + read_unlock(&tasklist_lock);
56974 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
56975 + p, acl_sp_role_value);
56976 + } else {
56977 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
56978 + error = -EPERM;
56979 + if(!(current->role->auth_attempts++))
56980 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
56981 +
56982 + goto out;
56983 + }
56984 + break;
56985 + case GR_UNSPROLE:
56986 + if (unlikely(!(gr_status & GR_READY))) {
56987 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
56988 + error = -EAGAIN;
56989 + break;
56990 + }
56991 +
56992 + if (current->role->roletype & GR_ROLE_SPECIAL) {
56993 + char *p = "";
56994 + int i = 0;
56995 +
56996 + read_lock(&tasklist_lock);
56997 + if (current->real_parent) {
56998 + p = current->real_parent->role->rolename;
56999 + i = current->real_parent->acl_role_id;
57000 + }
57001 + read_unlock(&tasklist_lock);
57002 +
57003 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
57004 + gr_set_acls(1);
57005 + } else {
57006 + error = -EPERM;
57007 + goto out;
57008 + }
57009 + break;
57010 + default:
57011 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
57012 + error = -EINVAL;
57013 + break;
57014 + }
57015 +
57016 + if (error != -EPERM)
57017 + goto out;
57018 +
57019 + if(!(gr_auth_attempts++))
57020 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
57021 +
57022 + out:
57023 + mutex_unlock(&gr_dev_mutex);
57024 + return error;
57025 +}
57026 +
57027 +/* must be called with
57028 + rcu_read_lock();
57029 + read_lock(&tasklist_lock);
57030 + read_lock(&grsec_exec_file_lock);
57031 +*/
57032 +int gr_apply_subject_to_task(struct task_struct *task)
57033 +{
57034 + struct acl_object_label *obj;
57035 + char *tmpname;
57036 + struct acl_subject_label *tmpsubj;
57037 + struct file *filp;
57038 + struct name_entry *nmatch;
57039 +
57040 + filp = task->exec_file;
57041 + if (filp == NULL)
57042 + return 0;
57043 +
57044 + /* the following is to apply the correct subject
57045 + on binaries running when the RBAC system
57046 + is enabled, when the binaries have been
57047 + replaced or deleted since their execution
57048 + -----
57049 + when the RBAC system starts, the inode/dev
57050 + from exec_file will be one the RBAC system
57051 + is unaware of. It only knows the inode/dev
57052 + of the present file on disk, or the absence
57053 + of it.
57054 + */
57055 + preempt_disable();
57056 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
57057 +
57058 + nmatch = lookup_name_entry(tmpname);
57059 + preempt_enable();
57060 + tmpsubj = NULL;
57061 + if (nmatch) {
57062 + if (nmatch->deleted)
57063 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
57064 + else
57065 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
57066 + if (tmpsubj != NULL)
57067 + task->acl = tmpsubj;
57068 + }
57069 + if (tmpsubj == NULL)
57070 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
57071 + task->role);
57072 + if (task->acl) {
57073 + task->is_writable = 0;
57074 + /* ignore additional mmap checks for processes that are writable
57075 + by the default ACL */
57076 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
57077 + if (unlikely(obj->mode & GR_WRITE))
57078 + task->is_writable = 1;
57079 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
57080 + if (unlikely(obj->mode & GR_WRITE))
57081 + task->is_writable = 1;
57082 +
57083 + gr_set_proc_res(task);
57084 +
57085 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57086 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
57087 +#endif
57088 + } else {
57089 + return 1;
57090 + }
57091 +
57092 + return 0;
57093 +}
57094 +
57095 +int
57096 +gr_set_acls(const int type)
57097 +{
57098 + struct task_struct *task, *task2;
57099 + struct acl_role_label *role = current->role;
57100 + __u16 acl_role_id = current->acl_role_id;
57101 + const struct cred *cred;
57102 + int ret;
57103 +
57104 + rcu_read_lock();
57105 + read_lock(&tasklist_lock);
57106 + read_lock(&grsec_exec_file_lock);
57107 + do_each_thread(task2, task) {
57108 + /* check to see if we're called from the exit handler,
57109 + if so, only replace ACLs that have inherited the admin
57110 + ACL */
57111 +
57112 + if (type && (task->role != role ||
57113 + task->acl_role_id != acl_role_id))
57114 + continue;
57115 +
57116 + task->acl_role_id = 0;
57117 + task->acl_sp_role = 0;
57118 +
57119 + if (task->exec_file) {
57120 + cred = __task_cred(task);
57121 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
57122 + ret = gr_apply_subject_to_task(task);
57123 + if (ret) {
57124 + read_unlock(&grsec_exec_file_lock);
57125 + read_unlock(&tasklist_lock);
57126 + rcu_read_unlock();
57127 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
57128 + return ret;
57129 + }
57130 + } else {
57131 + // it's a kernel process
57132 + task->role = kernel_role;
57133 + task->acl = kernel_role->root_label;
57134 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
57135 + task->acl->mode &= ~GR_PROCFIND;
57136 +#endif
57137 + }
57138 + } while_each_thread(task2, task);
57139 + read_unlock(&grsec_exec_file_lock);
57140 + read_unlock(&tasklist_lock);
57141 + rcu_read_unlock();
57142 +
57143 + return 0;
57144 +}
57145 +
57146 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
57147 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
57148 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
57149 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
57150 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
57151 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
57152 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
57153 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
57154 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
57155 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
57156 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
57157 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
57158 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
57159 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
57160 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
57161 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
57162 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
57163 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
57164 +};
57165 +
57166 +void
57167 +gr_learn_resource(const struct task_struct *task,
57168 + const int res, const unsigned long wanted, const int gt)
57169 +{
57170 + struct acl_subject_label *acl;
57171 + const struct cred *cred;
57172 +
57173 + if (unlikely((gr_status & GR_READY) &&
57174 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
57175 + goto skip_reslog;
57176 +
57177 + gr_log_resource(task, res, wanted, gt);
57178 +skip_reslog:
57179 +
57180 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
57181 + return;
57182 +
57183 + acl = task->acl;
57184 +
57185 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
57186 + !(acl->resmask & (1 << (unsigned short) res))))
57187 + return;
57188 +
57189 + if (wanted >= acl->res[res].rlim_cur) {
57190 + unsigned long res_add;
57191 +
57192 + res_add = wanted + res_learn_bumps[res];
57193 +
57194 + acl->res[res].rlim_cur = res_add;
57195 +
57196 + if (wanted > acl->res[res].rlim_max)
57197 + acl->res[res].rlim_max = res_add;
57198 +
57199 + /* only log the subject filename, since resource logging is supported for
57200 + single-subject learning only */
57201 + rcu_read_lock();
57202 + cred = __task_cred(task);
57203 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
57204 + task->role->roletype, cred->uid, cred->gid, acl->filename,
57205 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
57206 + "", (unsigned long) res, &task->signal->saved_ip);
57207 + rcu_read_unlock();
57208 + }
57209 +
57210 + return;
57211 +}
57212 +EXPORT_SYMBOL(gr_learn_resource);
57213 +#endif
57214 +
57215 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
57216 +void
57217 +pax_set_initial_flags(struct linux_binprm *bprm)
57218 +{
57219 + struct task_struct *task = current;
57220 + struct acl_subject_label *proc;
57221 + unsigned long flags;
57222 +
57223 + if (unlikely(!(gr_status & GR_READY)))
57224 + return;
57225 +
57226 + flags = pax_get_flags(task);
57227 +
57228 + proc = task->acl;
57229 +
57230 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
57231 + flags &= ~MF_PAX_PAGEEXEC;
57232 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
57233 + flags &= ~MF_PAX_SEGMEXEC;
57234 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
57235 + flags &= ~MF_PAX_RANDMMAP;
57236 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
57237 + flags &= ~MF_PAX_EMUTRAMP;
57238 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
57239 + flags &= ~MF_PAX_MPROTECT;
57240 +
57241 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
57242 + flags |= MF_PAX_PAGEEXEC;
57243 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
57244 + flags |= MF_PAX_SEGMEXEC;
57245 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
57246 + flags |= MF_PAX_RANDMMAP;
57247 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
57248 + flags |= MF_PAX_EMUTRAMP;
57249 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
57250 + flags |= MF_PAX_MPROTECT;
57251 +
57252 + pax_set_flags(task, flags);
57253 +
57254 + return;
57255 +}
57256 +#endif
57257 +
57258 +int
57259 +gr_handle_proc_ptrace(struct task_struct *task)
57260 +{
57261 + struct file *filp;
57262 + struct task_struct *tmp = task;
57263 + struct task_struct *curtemp = current;
57264 + __u32 retmode;
57265 +
57266 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
57267 + if (unlikely(!(gr_status & GR_READY)))
57268 + return 0;
57269 +#endif
57270 +
57271 + read_lock(&tasklist_lock);
57272 + read_lock(&grsec_exec_file_lock);
57273 + filp = task->exec_file;
57274 +
57275 + while (tmp->pid > 0) {
57276 + if (tmp == curtemp)
57277 + break;
57278 + tmp = tmp->real_parent;
57279 + }
57280 +
57281 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
57282 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
57283 + read_unlock(&grsec_exec_file_lock);
57284 + read_unlock(&tasklist_lock);
57285 + return 1;
57286 + }
57287 +
57288 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57289 + if (!(gr_status & GR_READY)) {
57290 + read_unlock(&grsec_exec_file_lock);
57291 + read_unlock(&tasklist_lock);
57292 + return 0;
57293 + }
57294 +#endif
57295 +
57296 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
57297 + read_unlock(&grsec_exec_file_lock);
57298 + read_unlock(&tasklist_lock);
57299 +
57300 + if (retmode & GR_NOPTRACE)
57301 + return 1;
57302 +
57303 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
57304 + && (current->acl != task->acl || (current->acl != current->role->root_label
57305 + && current->pid != task->pid)))
57306 + return 1;
57307 +
57308 + return 0;
57309 +}
57310 +
57311 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
57312 +{
57313 + if (unlikely(!(gr_status & GR_READY)))
57314 + return;
57315 +
57316 + if (!(current->role->roletype & GR_ROLE_GOD))
57317 + return;
57318 +
57319 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
57320 + p->role->rolename, gr_task_roletype_to_char(p),
57321 + p->acl->filename);
57322 +}
57323 +
57324 +int
57325 +gr_handle_ptrace(struct task_struct *task, const long request)
57326 +{
57327 + struct task_struct *tmp = task;
57328 + struct task_struct *curtemp = current;
57329 + __u32 retmode;
57330 +
57331 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
57332 + if (unlikely(!(gr_status & GR_READY)))
57333 + return 0;
57334 +#endif
57335 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
57336 + read_lock(&tasklist_lock);
57337 + while (tmp->pid > 0) {
57338 + if (tmp == curtemp)
57339 + break;
57340 + tmp = tmp->real_parent;
57341 + }
57342 +
57343 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
57344 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
57345 + read_unlock(&tasklist_lock);
57346 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
57347 + return 1;
57348 + }
57349 + read_unlock(&tasklist_lock);
57350 + }
57351 +
57352 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57353 + if (!(gr_status & GR_READY))
57354 + return 0;
57355 +#endif
57356 +
57357 + read_lock(&grsec_exec_file_lock);
57358 + if (unlikely(!task->exec_file)) {
57359 + read_unlock(&grsec_exec_file_lock);
57360 + return 0;
57361 + }
57362 +
57363 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
57364 + read_unlock(&grsec_exec_file_lock);
57365 +
57366 + if (retmode & GR_NOPTRACE) {
57367 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
57368 + return 1;
57369 + }
57370 +
57371 + if (retmode & GR_PTRACERD) {
57372 + switch (request) {
57373 + case PTRACE_SEIZE:
57374 + case PTRACE_POKETEXT:
57375 + case PTRACE_POKEDATA:
57376 + case PTRACE_POKEUSR:
57377 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
57378 + case PTRACE_SETREGS:
57379 + case PTRACE_SETFPREGS:
57380 +#endif
57381 +#ifdef CONFIG_X86
57382 + case PTRACE_SETFPXREGS:
57383 +#endif
57384 +#ifdef CONFIG_ALTIVEC
57385 + case PTRACE_SETVRREGS:
57386 +#endif
57387 + return 1;
57388 + default:
57389 + return 0;
57390 + }
57391 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
57392 + !(current->role->roletype & GR_ROLE_GOD) &&
57393 + (current->acl != task->acl)) {
57394 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
57395 + return 1;
57396 + }
57397 +
57398 + return 0;
57399 +}
57400 +
57401 +static int is_writable_mmap(const struct file *filp)
57402 +{
57403 + struct task_struct *task = current;
57404 + struct acl_object_label *obj, *obj2;
57405 +
57406 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
57407 + !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))) {
57408 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
57409 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
57410 + task->role->root_label);
57411 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
57412 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
57413 + return 1;
57414 + }
57415 + }
57416 + return 0;
57417 +}
57418 +
57419 +int
57420 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
57421 +{
57422 + __u32 mode;
57423 +
57424 + if (unlikely(!file || !(prot & PROT_EXEC)))
57425 + return 1;
57426 +
57427 + if (is_writable_mmap(file))
57428 + return 0;
57429 +
57430 + mode =
57431 + gr_search_file(file->f_path.dentry,
57432 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
57433 + file->f_path.mnt);
57434 +
57435 + if (!gr_tpe_allow(file))
57436 + return 0;
57437 +
57438 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
57439 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57440 + return 0;
57441 + } else if (unlikely(!(mode & GR_EXEC))) {
57442 + return 0;
57443 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
57444 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57445 + return 1;
57446 + }
57447 +
57448 + return 1;
57449 +}
57450 +
57451 +int
57452 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57453 +{
57454 + __u32 mode;
57455 +
57456 + if (unlikely(!file || !(prot & PROT_EXEC)))
57457 + return 1;
57458 +
57459 + if (is_writable_mmap(file))
57460 + return 0;
57461 +
57462 + mode =
57463 + gr_search_file(file->f_path.dentry,
57464 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
57465 + file->f_path.mnt);
57466 +
57467 + if (!gr_tpe_allow(file))
57468 + return 0;
57469 +
57470 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
57471 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57472 + return 0;
57473 + } else if (unlikely(!(mode & GR_EXEC))) {
57474 + return 0;
57475 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
57476 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57477 + return 1;
57478 + }
57479 +
57480 + return 1;
57481 +}
57482 +
57483 +void
57484 +gr_acl_handle_psacct(struct task_struct *task, const long code)
57485 +{
57486 + unsigned long runtime;
57487 + unsigned long cputime;
57488 + unsigned int wday, cday;
57489 + __u8 whr, chr;
57490 + __u8 wmin, cmin;
57491 + __u8 wsec, csec;
57492 + struct timespec timeval;
57493 +
57494 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
57495 + !(task->acl->mode & GR_PROCACCT)))
57496 + return;
57497 +
57498 + do_posix_clock_monotonic_gettime(&timeval);
57499 + runtime = timeval.tv_sec - task->start_time.tv_sec;
57500 + wday = runtime / (3600 * 24);
57501 + runtime -= wday * (3600 * 24);
57502 + whr = runtime / 3600;
57503 + runtime -= whr * 3600;
57504 + wmin = runtime / 60;
57505 + runtime -= wmin * 60;
57506 + wsec = runtime;
57507 +
57508 + cputime = (task->utime + task->stime) / HZ;
57509 + cday = cputime / (3600 * 24);
57510 + cputime -= cday * (3600 * 24);
57511 + chr = cputime / 3600;
57512 + cputime -= chr * 3600;
57513 + cmin = cputime / 60;
57514 + cputime -= cmin * 60;
57515 + csec = cputime;
57516 +
57517 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
57518 +
57519 + return;
57520 +}
57521 +
57522 +void gr_set_kernel_label(struct task_struct *task)
57523 +{
57524 + if (gr_status & GR_READY) {
57525 + task->role = kernel_role;
57526 + task->acl = kernel_role->root_label;
57527 + }
57528 + return;
57529 +}
57530 +
57531 +#ifdef CONFIG_TASKSTATS
57532 +int gr_is_taskstats_denied(int pid)
57533 +{
57534 + struct task_struct *task;
57535 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57536 + const struct cred *cred;
57537 +#endif
57538 + int ret = 0;
57539 +
57540 + /* restrict taskstats viewing to un-chrooted root users
57541 + who have the 'view' subject flag if the RBAC system is enabled
57542 + */
57543 +
57544 + rcu_read_lock();
57545 + read_lock(&tasklist_lock);
57546 + task = find_task_by_vpid(pid);
57547 + if (task) {
57548 +#ifdef CONFIG_GRKERNSEC_CHROOT
57549 + if (proc_is_chrooted(task))
57550 + ret = -EACCES;
57551 +#endif
57552 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57553 + cred = __task_cred(task);
57554 +#ifdef CONFIG_GRKERNSEC_PROC_USER
57555 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
57556 + ret = -EACCES;
57557 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57558 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
57559 + ret = -EACCES;
57560 +#endif
57561 +#endif
57562 + if (gr_status & GR_READY) {
57563 + if (!(task->acl->mode & GR_VIEW))
57564 + ret = -EACCES;
57565 + }
57566 + } else
57567 + ret = -ENOENT;
57568 +
57569 + read_unlock(&tasklist_lock);
57570 + rcu_read_unlock();
57571 +
57572 + return ret;
57573 +}
57574 +#endif
57575 +
57576 +/* AUXV entries are filled via a descendant of search_binary_handler
57577 + after we've already applied the subject for the target
57578 +*/
57579 +int gr_acl_enable_at_secure(void)
57580 +{
57581 + if (unlikely(!(gr_status & GR_READY)))
57582 + return 0;
57583 +
57584 + if (current->acl->mode & GR_ATSECURE)
57585 + return 1;
57586 +
57587 + return 0;
57588 +}
57589 +
57590 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
57591 +{
57592 + struct task_struct *task = current;
57593 + struct dentry *dentry = file->f_path.dentry;
57594 + struct vfsmount *mnt = file->f_path.mnt;
57595 + struct acl_object_label *obj, *tmp;
57596 + struct acl_subject_label *subj;
57597 + unsigned int bufsize;
57598 + int is_not_root;
57599 + char *path;
57600 + dev_t dev = __get_dev(dentry);
57601 +
57602 + if (unlikely(!(gr_status & GR_READY)))
57603 + return 1;
57604 +
57605 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
57606 + return 1;
57607 +
57608 + /* ignore Eric Biederman */
57609 + if (IS_PRIVATE(dentry->d_inode))
57610 + return 1;
57611 +
57612 + subj = task->acl;
57613 + read_lock(&gr_inode_lock);
57614 + do {
57615 + obj = lookup_acl_obj_label(ino, dev, subj);
57616 + if (obj != NULL) {
57617 + read_unlock(&gr_inode_lock);
57618 + return (obj->mode & GR_FIND) ? 1 : 0;
57619 + }
57620 + } while ((subj = subj->parent_subject));
57621 + read_unlock(&gr_inode_lock);
57622 +
57623 + /* this is purely an optimization since we're looking for an object
57624 + for the directory we're doing a readdir on
57625 + if it's possible for any globbed object to match the entry we're
57626 + filling into the directory, then the object we find here will be
57627 + an anchor point with attached globbed objects
57628 + */
57629 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
57630 + if (obj->globbed == NULL)
57631 + return (obj->mode & GR_FIND) ? 1 : 0;
57632 +
57633 + is_not_root = ((obj->filename[0] == '/') &&
57634 + (obj->filename[1] == '\0')) ? 0 : 1;
57635 + bufsize = PAGE_SIZE - namelen - is_not_root;
57636 +
57637 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
57638 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
57639 + return 1;
57640 +
57641 + preempt_disable();
57642 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
57643 + bufsize);
57644 +
57645 + bufsize = strlen(path);
57646 +
57647 + /* if base is "/", don't append an additional slash */
57648 + if (is_not_root)
57649 + *(path + bufsize) = '/';
57650 + memcpy(path + bufsize + is_not_root, name, namelen);
57651 + *(path + bufsize + namelen + is_not_root) = '\0';
57652 +
57653 + tmp = obj->globbed;
57654 + while (tmp) {
57655 + if (!glob_match(tmp->filename, path)) {
57656 + preempt_enable();
57657 + return (tmp->mode & GR_FIND) ? 1 : 0;
57658 + }
57659 + tmp = tmp->next;
57660 + }
57661 + preempt_enable();
57662 + return (obj->mode & GR_FIND) ? 1 : 0;
57663 +}
57664 +
57665 +void gr_put_exec_file(struct task_struct *task)
57666 +{
57667 + struct file *filp;
57668 +
57669 + write_lock(&grsec_exec_file_lock);
57670 + filp = task->exec_file;
57671 + task->exec_file = NULL;
57672 + write_unlock(&grsec_exec_file_lock);
57673 +
57674 + if (filp)
57675 + fput(filp);
57676 +
57677 + return;
57678 +}
57679 +
57680 +
57681 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
57682 +EXPORT_SYMBOL(gr_acl_is_enabled);
57683 +#endif
57684 +EXPORT_SYMBOL(gr_set_kernel_label);
57685 +#ifdef CONFIG_SECURITY
57686 +EXPORT_SYMBOL(gr_check_user_change);
57687 +EXPORT_SYMBOL(gr_check_group_change);
57688 +#endif
57689 +
57690 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
57691 new file mode 100644
57692 index 0000000..34fefda
57693 --- /dev/null
57694 +++ b/grsecurity/gracl_alloc.c
57695 @@ -0,0 +1,105 @@
57696 +#include <linux/kernel.h>
57697 +#include <linux/mm.h>
57698 +#include <linux/slab.h>
57699 +#include <linux/vmalloc.h>
57700 +#include <linux/gracl.h>
57701 +#include <linux/grsecurity.h>
57702 +
57703 +static unsigned long alloc_stack_next = 1;
57704 +static unsigned long alloc_stack_size = 1;
57705 +static void **alloc_stack;
57706 +
57707 +static __inline__ int
57708 +alloc_pop(void)
57709 +{
57710 + if (alloc_stack_next == 1)
57711 + return 0;
57712 +
57713 + kfree(alloc_stack[alloc_stack_next - 2]);
57714 +
57715 + alloc_stack_next--;
57716 +
57717 + return 1;
57718 +}
57719 +
57720 +static __inline__ int
57721 +alloc_push(void *buf)
57722 +{
57723 + if (alloc_stack_next >= alloc_stack_size)
57724 + return 1;
57725 +
57726 + alloc_stack[alloc_stack_next - 1] = buf;
57727 +
57728 + alloc_stack_next++;
57729 +
57730 + return 0;
57731 +}
57732 +
57733 +void *
57734 +acl_alloc(unsigned long len)
57735 +{
57736 + void *ret = NULL;
57737 +
57738 + if (!len || len > PAGE_SIZE)
57739 + goto out;
57740 +
57741 + ret = kmalloc(len, GFP_KERNEL);
57742 +
57743 + if (ret) {
57744 + if (alloc_push(ret)) {
57745 + kfree(ret);
57746 + ret = NULL;
57747 + }
57748 + }
57749 +
57750 +out:
57751 + return ret;
57752 +}
57753 +
57754 +void *
57755 +acl_alloc_num(unsigned long num, unsigned long len)
57756 +{
57757 + if (!len || (num > (PAGE_SIZE / len)))
57758 + return NULL;
57759 +
57760 + return acl_alloc(num * len);
57761 +}
57762 +
57763 +void
57764 +acl_free_all(void)
57765 +{
57766 + if (gr_acl_is_enabled() || !alloc_stack)
57767 + return;
57768 +
57769 + while (alloc_pop()) ;
57770 +
57771 + if (alloc_stack) {
57772 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
57773 + kfree(alloc_stack);
57774 + else
57775 + vfree(alloc_stack);
57776 + }
57777 +
57778 + alloc_stack = NULL;
57779 + alloc_stack_size = 1;
57780 + alloc_stack_next = 1;
57781 +
57782 + return;
57783 +}
57784 +
57785 +int
57786 +acl_alloc_stack_init(unsigned long size)
57787 +{
57788 + if ((size * sizeof (void *)) <= PAGE_SIZE)
57789 + alloc_stack =
57790 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
57791 + else
57792 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
57793 +
57794 + alloc_stack_size = size;
57795 +
57796 + if (!alloc_stack)
57797 + return 0;
57798 + else
57799 + return 1;
57800 +}
57801 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
57802 new file mode 100644
57803 index 0000000..6d21049
57804 --- /dev/null
57805 +++ b/grsecurity/gracl_cap.c
57806 @@ -0,0 +1,110 @@
57807 +#include <linux/kernel.h>
57808 +#include <linux/module.h>
57809 +#include <linux/sched.h>
57810 +#include <linux/gracl.h>
57811 +#include <linux/grsecurity.h>
57812 +#include <linux/grinternal.h>
57813 +
57814 +extern const char *captab_log[];
57815 +extern int captab_log_entries;
57816 +
57817 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57818 +{
57819 + struct acl_subject_label *curracl;
57820 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
57821 + kernel_cap_t cap_audit = __cap_empty_set;
57822 +
57823 + if (!gr_acl_is_enabled())
57824 + return 1;
57825 +
57826 + curracl = task->acl;
57827 +
57828 + cap_drop = curracl->cap_lower;
57829 + cap_mask = curracl->cap_mask;
57830 + cap_audit = curracl->cap_invert_audit;
57831 +
57832 + while ((curracl = curracl->parent_subject)) {
57833 + /* if the cap isn't specified in the current computed mask but is specified in the
57834 + current level subject, and is lowered in the current level subject, then add
57835 + it to the set of dropped capabilities
57836 + otherwise, add the current level subject's mask to the current computed mask
57837 + */
57838 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
57839 + cap_raise(cap_mask, cap);
57840 + if (cap_raised(curracl->cap_lower, cap))
57841 + cap_raise(cap_drop, cap);
57842 + if (cap_raised(curracl->cap_invert_audit, cap))
57843 + cap_raise(cap_audit, cap);
57844 + }
57845 + }
57846 +
57847 + if (!cap_raised(cap_drop, cap)) {
57848 + if (cap_raised(cap_audit, cap))
57849 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
57850 + return 1;
57851 + }
57852 +
57853 + curracl = task->acl;
57854 +
57855 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
57856 + && cap_raised(cred->cap_effective, cap)) {
57857 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
57858 + task->role->roletype, cred->uid,
57859 + cred->gid, task->exec_file ?
57860 + gr_to_filename(task->exec_file->f_path.dentry,
57861 + task->exec_file->f_path.mnt) : curracl->filename,
57862 + curracl->filename, 0UL,
57863 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
57864 + return 1;
57865 + }
57866 +
57867 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
57868 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
57869 +
57870 + return 0;
57871 +}
57872 +
57873 +int
57874 +gr_acl_is_capable(const int cap)
57875 +{
57876 + return gr_task_acl_is_capable(current, current_cred(), cap);
57877 +}
57878 +
57879 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
57880 +{
57881 + struct acl_subject_label *curracl;
57882 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
57883 +
57884 + if (!gr_acl_is_enabled())
57885 + return 1;
57886 +
57887 + curracl = task->acl;
57888 +
57889 + cap_drop = curracl->cap_lower;
57890 + cap_mask = curracl->cap_mask;
57891 +
57892 + while ((curracl = curracl->parent_subject)) {
57893 + /* if the cap isn't specified in the current computed mask but is specified in the
57894 + current level subject, and is lowered in the current level subject, then add
57895 + it to the set of dropped capabilities
57896 + otherwise, add the current level subject's mask to the current computed mask
57897 + */
57898 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
57899 + cap_raise(cap_mask, cap);
57900 + if (cap_raised(curracl->cap_lower, cap))
57901 + cap_raise(cap_drop, cap);
57902 + }
57903 + }
57904 +
57905 + if (!cap_raised(cap_drop, cap))
57906 + return 1;
57907 +
57908 + return 0;
57909 +}
57910 +
57911 +int
57912 +gr_acl_is_capable_nolog(const int cap)
57913 +{
57914 + return gr_task_acl_is_capable_nolog(current, cap);
57915 +}
57916 +
57917 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
57918 new file mode 100644
57919 index 0000000..a340c17
57920 --- /dev/null
57921 +++ b/grsecurity/gracl_fs.c
57922 @@ -0,0 +1,431 @@
57923 +#include <linux/kernel.h>
57924 +#include <linux/sched.h>
57925 +#include <linux/types.h>
57926 +#include <linux/fs.h>
57927 +#include <linux/file.h>
57928 +#include <linux/stat.h>
57929 +#include <linux/grsecurity.h>
57930 +#include <linux/grinternal.h>
57931 +#include <linux/gracl.h>
57932 +
57933 +umode_t
57934 +gr_acl_umask(void)
57935 +{
57936 + if (unlikely(!gr_acl_is_enabled()))
57937 + return 0;
57938 +
57939 + return current->role->umask;
57940 +}
57941 +
57942 +__u32
57943 +gr_acl_handle_hidden_file(const struct dentry * dentry,
57944 + const struct vfsmount * mnt)
57945 +{
57946 + __u32 mode;
57947 +
57948 + if (unlikely(!dentry->d_inode))
57949 + return GR_FIND;
57950 +
57951 + mode =
57952 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
57953 +
57954 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
57955 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
57956 + return mode;
57957 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
57958 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
57959 + return 0;
57960 + } else if (unlikely(!(mode & GR_FIND)))
57961 + return 0;
57962 +
57963 + return GR_FIND;
57964 +}
57965 +
57966 +__u32
57967 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57968 + int acc_mode)
57969 +{
57970 + __u32 reqmode = GR_FIND;
57971 + __u32 mode;
57972 +
57973 + if (unlikely(!dentry->d_inode))
57974 + return reqmode;
57975 +
57976 + if (acc_mode & MAY_APPEND)
57977 + reqmode |= GR_APPEND;
57978 + else if (acc_mode & MAY_WRITE)
57979 + reqmode |= GR_WRITE;
57980 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
57981 + reqmode |= GR_READ;
57982 +
57983 + mode =
57984 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
57985 + mnt);
57986 +
57987 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
57988 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
57989 + reqmode & GR_READ ? " reading" : "",
57990 + reqmode & GR_WRITE ? " writing" : reqmode &
57991 + GR_APPEND ? " appending" : "");
57992 + return reqmode;
57993 + } else
57994 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
57995 + {
57996 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
57997 + reqmode & GR_READ ? " reading" : "",
57998 + reqmode & GR_WRITE ? " writing" : reqmode &
57999 + GR_APPEND ? " appending" : "");
58000 + return 0;
58001 + } else if (unlikely((mode & reqmode) != reqmode))
58002 + return 0;
58003 +
58004 + return reqmode;
58005 +}
58006 +
58007 +__u32
58008 +gr_acl_handle_creat(const struct dentry * dentry,
58009 + const struct dentry * p_dentry,
58010 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
58011 + const int imode)
58012 +{
58013 + __u32 reqmode = GR_WRITE | GR_CREATE;
58014 + __u32 mode;
58015 +
58016 + if (acc_mode & MAY_APPEND)
58017 + reqmode |= GR_APPEND;
58018 + // if a directory was required or the directory already exists, then
58019 + // don't count this open as a read
58020 + if ((acc_mode & MAY_READ) &&
58021 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
58022 + reqmode |= GR_READ;
58023 + if ((open_flags & O_CREAT) &&
58024 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
58025 + reqmode |= GR_SETID;
58026 +
58027 + mode =
58028 + gr_check_create(dentry, p_dentry, p_mnt,
58029 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
58030 +
58031 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
58032 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
58033 + reqmode & GR_READ ? " reading" : "",
58034 + reqmode & GR_WRITE ? " writing" : reqmode &
58035 + GR_APPEND ? " appending" : "");
58036 + return reqmode;
58037 + } else
58038 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
58039 + {
58040 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
58041 + reqmode & GR_READ ? " reading" : "",
58042 + reqmode & GR_WRITE ? " writing" : reqmode &
58043 + GR_APPEND ? " appending" : "");
58044 + return 0;
58045 + } else if (unlikely((mode & reqmode) != reqmode))
58046 + return 0;
58047 +
58048 + return reqmode;
58049 +}
58050 +
58051 +__u32
58052 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
58053 + const int fmode)
58054 +{
58055 + __u32 mode, reqmode = GR_FIND;
58056 +
58057 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
58058 + reqmode |= GR_EXEC;
58059 + if (fmode & S_IWOTH)
58060 + reqmode |= GR_WRITE;
58061 + if (fmode & S_IROTH)
58062 + reqmode |= GR_READ;
58063 +
58064 + mode =
58065 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
58066 + mnt);
58067 +
58068 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
58069 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
58070 + reqmode & GR_READ ? " reading" : "",
58071 + reqmode & GR_WRITE ? " writing" : "",
58072 + reqmode & GR_EXEC ? " executing" : "");
58073 + return reqmode;
58074 + } else
58075 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
58076 + {
58077 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
58078 + reqmode & GR_READ ? " reading" : "",
58079 + reqmode & GR_WRITE ? " writing" : "",
58080 + reqmode & GR_EXEC ? " executing" : "");
58081 + return 0;
58082 + } else if (unlikely((mode & reqmode) != reqmode))
58083 + return 0;
58084 +
58085 + return reqmode;
58086 +}
58087 +
58088 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
58089 +{
58090 + __u32 mode;
58091 +
58092 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
58093 +
58094 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
58095 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
58096 + return mode;
58097 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
58098 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
58099 + return 0;
58100 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
58101 + return 0;
58102 +
58103 + return (reqmode);
58104 +}
58105 +
58106 +__u32
58107 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
58108 +{
58109 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
58110 +}
58111 +
58112 +__u32
58113 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
58114 +{
58115 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
58116 +}
58117 +
58118 +__u32
58119 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
58120 +{
58121 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
58122 +}
58123 +
58124 +__u32
58125 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
58126 +{
58127 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
58128 +}
58129 +
58130 +__u32
58131 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
58132 + umode_t *modeptr)
58133 +{
58134 + umode_t mode;
58135 +
58136 + *modeptr &= ~gr_acl_umask();
58137 + mode = *modeptr;
58138 +
58139 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
58140 + return 1;
58141 +
58142 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
58143 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
58144 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
58145 + GR_CHMOD_ACL_MSG);
58146 + } else {
58147 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
58148 + }
58149 +}
58150 +
58151 +__u32
58152 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
58153 +{
58154 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
58155 +}
58156 +
58157 +__u32
58158 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
58159 +{
58160 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
58161 +}
58162 +
58163 +__u32
58164 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
58165 +{
58166 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
58167 +}
58168 +
58169 +__u32
58170 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
58171 +{
58172 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
58173 + GR_UNIXCONNECT_ACL_MSG);
58174 +}
58175 +
58176 +/* hardlinks require at minimum create and link permission,
58177 + any additional privilege required is based on the
58178 + privilege of the file being linked to
58179 +*/
58180 +__u32
58181 +gr_acl_handle_link(const struct dentry * new_dentry,
58182 + const struct dentry * parent_dentry,
58183 + const struct vfsmount * parent_mnt,
58184 + const struct dentry * old_dentry,
58185 + const struct vfsmount * old_mnt, const struct filename *to)
58186 +{
58187 + __u32 mode;
58188 + __u32 needmode = GR_CREATE | GR_LINK;
58189 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
58190 +
58191 + mode =
58192 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
58193 + old_mnt);
58194 +
58195 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
58196 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
58197 + return mode;
58198 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
58199 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
58200 + return 0;
58201 + } else if (unlikely((mode & needmode) != needmode))
58202 + return 0;
58203 +
58204 + return 1;
58205 +}
58206 +
58207 +__u32
58208 +gr_acl_handle_symlink(const struct dentry * new_dentry,
58209 + const struct dentry * parent_dentry,
58210 + const struct vfsmount * parent_mnt, const struct filename *from)
58211 +{
58212 + __u32 needmode = GR_WRITE | GR_CREATE;
58213 + __u32 mode;
58214 +
58215 + mode =
58216 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
58217 + GR_CREATE | GR_AUDIT_CREATE |
58218 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
58219 +
58220 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
58221 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
58222 + return mode;
58223 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
58224 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
58225 + return 0;
58226 + } else if (unlikely((mode & needmode) != needmode))
58227 + return 0;
58228 +
58229 + return (GR_WRITE | GR_CREATE);
58230 +}
58231 +
58232 +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)
58233 +{
58234 + __u32 mode;
58235 +
58236 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
58237 +
58238 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
58239 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
58240 + return mode;
58241 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
58242 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
58243 + return 0;
58244 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
58245 + return 0;
58246 +
58247 + return (reqmode);
58248 +}
58249 +
58250 +__u32
58251 +gr_acl_handle_mknod(const struct dentry * new_dentry,
58252 + const struct dentry * parent_dentry,
58253 + const struct vfsmount * parent_mnt,
58254 + const int mode)
58255 +{
58256 + __u32 reqmode = GR_WRITE | GR_CREATE;
58257 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
58258 + reqmode |= GR_SETID;
58259 +
58260 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
58261 + reqmode, GR_MKNOD_ACL_MSG);
58262 +}
58263 +
58264 +__u32
58265 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
58266 + const struct dentry *parent_dentry,
58267 + const struct vfsmount *parent_mnt)
58268 +{
58269 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
58270 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
58271 +}
58272 +
58273 +#define RENAME_CHECK_SUCCESS(old, new) \
58274 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
58275 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
58276 +
58277 +int
58278 +gr_acl_handle_rename(struct dentry *new_dentry,
58279 + struct dentry *parent_dentry,
58280 + const struct vfsmount *parent_mnt,
58281 + struct dentry *old_dentry,
58282 + struct inode *old_parent_inode,
58283 + struct vfsmount *old_mnt, const struct filename *newname)
58284 +{
58285 + __u32 comp1, comp2;
58286 + int error = 0;
58287 +
58288 + if (unlikely(!gr_acl_is_enabled()))
58289 + return 0;
58290 +
58291 + if (!new_dentry->d_inode) {
58292 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
58293 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
58294 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
58295 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
58296 + GR_DELETE | GR_AUDIT_DELETE |
58297 + GR_AUDIT_READ | GR_AUDIT_WRITE |
58298 + GR_SUPPRESS, old_mnt);
58299 + } else {
58300 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
58301 + GR_CREATE | GR_DELETE |
58302 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
58303 + GR_AUDIT_READ | GR_AUDIT_WRITE |
58304 + GR_SUPPRESS, parent_mnt);
58305 + comp2 =
58306 + gr_search_file(old_dentry,
58307 + GR_READ | GR_WRITE | GR_AUDIT_READ |
58308 + GR_DELETE | GR_AUDIT_DELETE |
58309 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
58310 + }
58311 +
58312 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
58313 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
58314 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
58315 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
58316 + && !(comp2 & GR_SUPPRESS)) {
58317 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
58318 + error = -EACCES;
58319 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
58320 + error = -EACCES;
58321 +
58322 + return error;
58323 +}
58324 +
58325 +void
58326 +gr_acl_handle_exit(void)
58327 +{
58328 + u16 id;
58329 + char *rolename;
58330 +
58331 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
58332 + !(current->role->roletype & GR_ROLE_PERSIST))) {
58333 + id = current->acl_role_id;
58334 + rolename = current->role->rolename;
58335 + gr_set_acls(1);
58336 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
58337 + }
58338 +
58339 + gr_put_exec_file(current);
58340 + return;
58341 +}
58342 +
58343 +int
58344 +gr_acl_handle_procpidmem(const struct task_struct *task)
58345 +{
58346 + if (unlikely(!gr_acl_is_enabled()))
58347 + return 0;
58348 +
58349 + if (task != current && task->acl->mode & GR_PROTPROCFD)
58350 + return -EACCES;
58351 +
58352 + return 0;
58353 +}
58354 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
58355 new file mode 100644
58356 index 0000000..58800a7
58357 --- /dev/null
58358 +++ b/grsecurity/gracl_ip.c
58359 @@ -0,0 +1,384 @@
58360 +#include <linux/kernel.h>
58361 +#include <asm/uaccess.h>
58362 +#include <asm/errno.h>
58363 +#include <net/sock.h>
58364 +#include <linux/file.h>
58365 +#include <linux/fs.h>
58366 +#include <linux/net.h>
58367 +#include <linux/in.h>
58368 +#include <linux/skbuff.h>
58369 +#include <linux/ip.h>
58370 +#include <linux/udp.h>
58371 +#include <linux/types.h>
58372 +#include <linux/sched.h>
58373 +#include <linux/netdevice.h>
58374 +#include <linux/inetdevice.h>
58375 +#include <linux/gracl.h>
58376 +#include <linux/grsecurity.h>
58377 +#include <linux/grinternal.h>
58378 +
58379 +#define GR_BIND 0x01
58380 +#define GR_CONNECT 0x02
58381 +#define GR_INVERT 0x04
58382 +#define GR_BINDOVERRIDE 0x08
58383 +#define GR_CONNECTOVERRIDE 0x10
58384 +#define GR_SOCK_FAMILY 0x20
58385 +
58386 +static const char * gr_protocols[IPPROTO_MAX] = {
58387 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
58388 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
58389 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
58390 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
58391 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
58392 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
58393 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
58394 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
58395 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
58396 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
58397 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
58398 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
58399 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
58400 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
58401 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
58402 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
58403 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
58404 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
58405 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
58406 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
58407 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
58408 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
58409 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
58410 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
58411 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
58412 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
58413 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
58414 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
58415 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
58416 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
58417 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
58418 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
58419 + };
58420 +
58421 +static const char * gr_socktypes[SOCK_MAX] = {
58422 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
58423 + "unknown:7", "unknown:8", "unknown:9", "packet"
58424 + };
58425 +
58426 +static const char * gr_sockfamilies[AF_MAX+1] = {
58427 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
58428 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
58429 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
58430 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
58431 + };
58432 +
58433 +const char *
58434 +gr_proto_to_name(unsigned char proto)
58435 +{
58436 + return gr_protocols[proto];
58437 +}
58438 +
58439 +const char *
58440 +gr_socktype_to_name(unsigned char type)
58441 +{
58442 + return gr_socktypes[type];
58443 +}
58444 +
58445 +const char *
58446 +gr_sockfamily_to_name(unsigned char family)
58447 +{
58448 + return gr_sockfamilies[family];
58449 +}
58450 +
58451 +int
58452 +gr_search_socket(const int domain, const int type, const int protocol)
58453 +{
58454 + struct acl_subject_label *curr;
58455 + const struct cred *cred = current_cred();
58456 +
58457 + if (unlikely(!gr_acl_is_enabled()))
58458 + goto exit;
58459 +
58460 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
58461 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
58462 + goto exit; // let the kernel handle it
58463 +
58464 + curr = current->acl;
58465 +
58466 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
58467 + /* the family is allowed, if this is PF_INET allow it only if
58468 + the extra sock type/protocol checks pass */
58469 + if (domain == PF_INET)
58470 + goto inet_check;
58471 + goto exit;
58472 + } else {
58473 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
58474 + __u32 fakeip = 0;
58475 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58476 + current->role->roletype, cred->uid,
58477 + cred->gid, current->exec_file ?
58478 + gr_to_filename(current->exec_file->f_path.dentry,
58479 + current->exec_file->f_path.mnt) :
58480 + curr->filename, curr->filename,
58481 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
58482 + &current->signal->saved_ip);
58483 + goto exit;
58484 + }
58485 + goto exit_fail;
58486 + }
58487 +
58488 +inet_check:
58489 + /* the rest of this checking is for IPv4 only */
58490 + if (!curr->ips)
58491 + goto exit;
58492 +
58493 + if ((curr->ip_type & (1 << type)) &&
58494 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
58495 + goto exit;
58496 +
58497 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
58498 + /* we don't place acls on raw sockets , and sometimes
58499 + dgram/ip sockets are opened for ioctl and not
58500 + bind/connect, so we'll fake a bind learn log */
58501 + if (type == SOCK_RAW || type == SOCK_PACKET) {
58502 + __u32 fakeip = 0;
58503 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58504 + current->role->roletype, cred->uid,
58505 + cred->gid, current->exec_file ?
58506 + gr_to_filename(current->exec_file->f_path.dentry,
58507 + current->exec_file->f_path.mnt) :
58508 + curr->filename, curr->filename,
58509 + &fakeip, 0, type,
58510 + protocol, GR_CONNECT, &current->signal->saved_ip);
58511 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
58512 + __u32 fakeip = 0;
58513 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58514 + current->role->roletype, cred->uid,
58515 + cred->gid, current->exec_file ?
58516 + gr_to_filename(current->exec_file->f_path.dentry,
58517 + current->exec_file->f_path.mnt) :
58518 + curr->filename, curr->filename,
58519 + &fakeip, 0, type,
58520 + protocol, GR_BIND, &current->signal->saved_ip);
58521 + }
58522 + /* we'll log when they use connect or bind */
58523 + goto exit;
58524 + }
58525 +
58526 +exit_fail:
58527 + if (domain == PF_INET)
58528 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
58529 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
58530 + else
58531 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
58532 + gr_socktype_to_name(type), protocol);
58533 +
58534 + return 0;
58535 +exit:
58536 + return 1;
58537 +}
58538 +
58539 +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)
58540 +{
58541 + if ((ip->mode & mode) &&
58542 + (ip_port >= ip->low) &&
58543 + (ip_port <= ip->high) &&
58544 + ((ntohl(ip_addr) & our_netmask) ==
58545 + (ntohl(our_addr) & our_netmask))
58546 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
58547 + && (ip->type & (1 << type))) {
58548 + if (ip->mode & GR_INVERT)
58549 + return 2; // specifically denied
58550 + else
58551 + return 1; // allowed
58552 + }
58553 +
58554 + return 0; // not specifically allowed, may continue parsing
58555 +}
58556 +
58557 +static int
58558 +gr_search_connectbind(const int full_mode, struct sock *sk,
58559 + struct sockaddr_in *addr, const int type)
58560 +{
58561 + char iface[IFNAMSIZ] = {0};
58562 + struct acl_subject_label *curr;
58563 + struct acl_ip_label *ip;
58564 + struct inet_sock *isk;
58565 + struct net_device *dev;
58566 + struct in_device *idev;
58567 + unsigned long i;
58568 + int ret;
58569 + int mode = full_mode & (GR_BIND | GR_CONNECT);
58570 + __u32 ip_addr = 0;
58571 + __u32 our_addr;
58572 + __u32 our_netmask;
58573 + char *p;
58574 + __u16 ip_port = 0;
58575 + const struct cred *cred = current_cred();
58576 +
58577 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
58578 + return 0;
58579 +
58580 + curr = current->acl;
58581 + isk = inet_sk(sk);
58582 +
58583 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
58584 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
58585 + addr->sin_addr.s_addr = curr->inaddr_any_override;
58586 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
58587 + struct sockaddr_in saddr;
58588 + int err;
58589 +
58590 + saddr.sin_family = AF_INET;
58591 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
58592 + saddr.sin_port = isk->inet_sport;
58593 +
58594 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
58595 + if (err)
58596 + return err;
58597 +
58598 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
58599 + if (err)
58600 + return err;
58601 + }
58602 +
58603 + if (!curr->ips)
58604 + return 0;
58605 +
58606 + ip_addr = addr->sin_addr.s_addr;
58607 + ip_port = ntohs(addr->sin_port);
58608 +
58609 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
58610 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58611 + current->role->roletype, cred->uid,
58612 + cred->gid, current->exec_file ?
58613 + gr_to_filename(current->exec_file->f_path.dentry,
58614 + current->exec_file->f_path.mnt) :
58615 + curr->filename, curr->filename,
58616 + &ip_addr, ip_port, type,
58617 + sk->sk_protocol, mode, &current->signal->saved_ip);
58618 + return 0;
58619 + }
58620 +
58621 + for (i = 0; i < curr->ip_num; i++) {
58622 + ip = *(curr->ips + i);
58623 + if (ip->iface != NULL) {
58624 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
58625 + p = strchr(iface, ':');
58626 + if (p != NULL)
58627 + *p = '\0';
58628 + dev = dev_get_by_name(sock_net(sk), iface);
58629 + if (dev == NULL)
58630 + continue;
58631 + idev = in_dev_get(dev);
58632 + if (idev == NULL) {
58633 + dev_put(dev);
58634 + continue;
58635 + }
58636 + rcu_read_lock();
58637 + for_ifa(idev) {
58638 + if (!strcmp(ip->iface, ifa->ifa_label)) {
58639 + our_addr = ifa->ifa_address;
58640 + our_netmask = 0xffffffff;
58641 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
58642 + if (ret == 1) {
58643 + rcu_read_unlock();
58644 + in_dev_put(idev);
58645 + dev_put(dev);
58646 + return 0;
58647 + } else if (ret == 2) {
58648 + rcu_read_unlock();
58649 + in_dev_put(idev);
58650 + dev_put(dev);
58651 + goto denied;
58652 + }
58653 + }
58654 + } endfor_ifa(idev);
58655 + rcu_read_unlock();
58656 + in_dev_put(idev);
58657 + dev_put(dev);
58658 + } else {
58659 + our_addr = ip->addr;
58660 + our_netmask = ip->netmask;
58661 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
58662 + if (ret == 1)
58663 + return 0;
58664 + else if (ret == 2)
58665 + goto denied;
58666 + }
58667 + }
58668 +
58669 +denied:
58670 + if (mode == GR_BIND)
58671 + 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));
58672 + else if (mode == GR_CONNECT)
58673 + 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));
58674 +
58675 + return -EACCES;
58676 +}
58677 +
58678 +int
58679 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
58680 +{
58681 + /* always allow disconnection of dgram sockets with connect */
58682 + if (addr->sin_family == AF_UNSPEC)
58683 + return 0;
58684 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
58685 +}
58686 +
58687 +int
58688 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
58689 +{
58690 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
58691 +}
58692 +
58693 +int gr_search_listen(struct socket *sock)
58694 +{
58695 + struct sock *sk = sock->sk;
58696 + struct sockaddr_in addr;
58697 +
58698 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
58699 + addr.sin_port = inet_sk(sk)->inet_sport;
58700 +
58701 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
58702 +}
58703 +
58704 +int gr_search_accept(struct socket *sock)
58705 +{
58706 + struct sock *sk = sock->sk;
58707 + struct sockaddr_in addr;
58708 +
58709 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
58710 + addr.sin_port = inet_sk(sk)->inet_sport;
58711 +
58712 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
58713 +}
58714 +
58715 +int
58716 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
58717 +{
58718 + if (addr)
58719 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
58720 + else {
58721 + struct sockaddr_in sin;
58722 + const struct inet_sock *inet = inet_sk(sk);
58723 +
58724 + sin.sin_addr.s_addr = inet->inet_daddr;
58725 + sin.sin_port = inet->inet_dport;
58726 +
58727 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
58728 + }
58729 +}
58730 +
58731 +int
58732 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
58733 +{
58734 + struct sockaddr_in sin;
58735 +
58736 + if (unlikely(skb->len < sizeof (struct udphdr)))
58737 + return 0; // skip this packet
58738 +
58739 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
58740 + sin.sin_port = udp_hdr(skb)->source;
58741 +
58742 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
58743 +}
58744 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
58745 new file mode 100644
58746 index 0000000..25f54ef
58747 --- /dev/null
58748 +++ b/grsecurity/gracl_learn.c
58749 @@ -0,0 +1,207 @@
58750 +#include <linux/kernel.h>
58751 +#include <linux/mm.h>
58752 +#include <linux/sched.h>
58753 +#include <linux/poll.h>
58754 +#include <linux/string.h>
58755 +#include <linux/file.h>
58756 +#include <linux/types.h>
58757 +#include <linux/vmalloc.h>
58758 +#include <linux/grinternal.h>
58759 +
58760 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
58761 + size_t count, loff_t *ppos);
58762 +extern int gr_acl_is_enabled(void);
58763 +
58764 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
58765 +static int gr_learn_attached;
58766 +
58767 +/* use a 512k buffer */
58768 +#define LEARN_BUFFER_SIZE (512 * 1024)
58769 +
58770 +static DEFINE_SPINLOCK(gr_learn_lock);
58771 +static DEFINE_MUTEX(gr_learn_user_mutex);
58772 +
58773 +/* we need to maintain two buffers, so that the kernel context of grlearn
58774 + uses a semaphore around the userspace copying, and the other kernel contexts
58775 + use a spinlock when copying into the buffer, since they cannot sleep
58776 +*/
58777 +static char *learn_buffer;
58778 +static char *learn_buffer_user;
58779 +static int learn_buffer_len;
58780 +static int learn_buffer_user_len;
58781 +
58782 +static ssize_t
58783 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
58784 +{
58785 + DECLARE_WAITQUEUE(wait, current);
58786 + ssize_t retval = 0;
58787 +
58788 + add_wait_queue(&learn_wait, &wait);
58789 + set_current_state(TASK_INTERRUPTIBLE);
58790 + do {
58791 + mutex_lock(&gr_learn_user_mutex);
58792 + spin_lock(&gr_learn_lock);
58793 + if (learn_buffer_len)
58794 + break;
58795 + spin_unlock(&gr_learn_lock);
58796 + mutex_unlock(&gr_learn_user_mutex);
58797 + if (file->f_flags & O_NONBLOCK) {
58798 + retval = -EAGAIN;
58799 + goto out;
58800 + }
58801 + if (signal_pending(current)) {
58802 + retval = -ERESTARTSYS;
58803 + goto out;
58804 + }
58805 +
58806 + schedule();
58807 + } while (1);
58808 +
58809 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
58810 + learn_buffer_user_len = learn_buffer_len;
58811 + retval = learn_buffer_len;
58812 + learn_buffer_len = 0;
58813 +
58814 + spin_unlock(&gr_learn_lock);
58815 +
58816 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
58817 + retval = -EFAULT;
58818 +
58819 + mutex_unlock(&gr_learn_user_mutex);
58820 +out:
58821 + set_current_state(TASK_RUNNING);
58822 + remove_wait_queue(&learn_wait, &wait);
58823 + return retval;
58824 +}
58825 +
58826 +static unsigned int
58827 +poll_learn(struct file * file, poll_table * wait)
58828 +{
58829 + poll_wait(file, &learn_wait, wait);
58830 +
58831 + if (learn_buffer_len)
58832 + return (POLLIN | POLLRDNORM);
58833 +
58834 + return 0;
58835 +}
58836 +
58837 +void
58838 +gr_clear_learn_entries(void)
58839 +{
58840 + char *tmp;
58841 +
58842 + mutex_lock(&gr_learn_user_mutex);
58843 + spin_lock(&gr_learn_lock);
58844 + tmp = learn_buffer;
58845 + learn_buffer = NULL;
58846 + spin_unlock(&gr_learn_lock);
58847 + if (tmp)
58848 + vfree(tmp);
58849 + if (learn_buffer_user != NULL) {
58850 + vfree(learn_buffer_user);
58851 + learn_buffer_user = NULL;
58852 + }
58853 + learn_buffer_len = 0;
58854 + mutex_unlock(&gr_learn_user_mutex);
58855 +
58856 + return;
58857 +}
58858 +
58859 +void
58860 +gr_add_learn_entry(const char *fmt, ...)
58861 +{
58862 + va_list args;
58863 + unsigned int len;
58864 +
58865 + if (!gr_learn_attached)
58866 + return;
58867 +
58868 + spin_lock(&gr_learn_lock);
58869 +
58870 + /* leave a gap at the end so we know when it's "full" but don't have to
58871 + compute the exact length of the string we're trying to append
58872 + */
58873 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
58874 + spin_unlock(&gr_learn_lock);
58875 + wake_up_interruptible(&learn_wait);
58876 + return;
58877 + }
58878 + if (learn_buffer == NULL) {
58879 + spin_unlock(&gr_learn_lock);
58880 + return;
58881 + }
58882 +
58883 + va_start(args, fmt);
58884 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
58885 + va_end(args);
58886 +
58887 + learn_buffer_len += len + 1;
58888 +
58889 + spin_unlock(&gr_learn_lock);
58890 + wake_up_interruptible(&learn_wait);
58891 +
58892 + return;
58893 +}
58894 +
58895 +static int
58896 +open_learn(struct inode *inode, struct file *file)
58897 +{
58898 + if (file->f_mode & FMODE_READ && gr_learn_attached)
58899 + return -EBUSY;
58900 + if (file->f_mode & FMODE_READ) {
58901 + int retval = 0;
58902 + mutex_lock(&gr_learn_user_mutex);
58903 + if (learn_buffer == NULL)
58904 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
58905 + if (learn_buffer_user == NULL)
58906 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
58907 + if (learn_buffer == NULL) {
58908 + retval = -ENOMEM;
58909 + goto out_error;
58910 + }
58911 + if (learn_buffer_user == NULL) {
58912 + retval = -ENOMEM;
58913 + goto out_error;
58914 + }
58915 + learn_buffer_len = 0;
58916 + learn_buffer_user_len = 0;
58917 + gr_learn_attached = 1;
58918 +out_error:
58919 + mutex_unlock(&gr_learn_user_mutex);
58920 + return retval;
58921 + }
58922 + return 0;
58923 +}
58924 +
58925 +static int
58926 +close_learn(struct inode *inode, struct file *file)
58927 +{
58928 + if (file->f_mode & FMODE_READ) {
58929 + char *tmp = NULL;
58930 + mutex_lock(&gr_learn_user_mutex);
58931 + spin_lock(&gr_learn_lock);
58932 + tmp = learn_buffer;
58933 + learn_buffer = NULL;
58934 + spin_unlock(&gr_learn_lock);
58935 + if (tmp)
58936 + vfree(tmp);
58937 + if (learn_buffer_user != NULL) {
58938 + vfree(learn_buffer_user);
58939 + learn_buffer_user = NULL;
58940 + }
58941 + learn_buffer_len = 0;
58942 + learn_buffer_user_len = 0;
58943 + gr_learn_attached = 0;
58944 + mutex_unlock(&gr_learn_user_mutex);
58945 + }
58946 +
58947 + return 0;
58948 +}
58949 +
58950 +const struct file_operations grsec_fops = {
58951 + .read = read_learn,
58952 + .write = write_grsec_handler,
58953 + .open = open_learn,
58954 + .release = close_learn,
58955 + .poll = poll_learn,
58956 +};
58957 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
58958 new file mode 100644
58959 index 0000000..39645c9
58960 --- /dev/null
58961 +++ b/grsecurity/gracl_res.c
58962 @@ -0,0 +1,68 @@
58963 +#include <linux/kernel.h>
58964 +#include <linux/sched.h>
58965 +#include <linux/gracl.h>
58966 +#include <linux/grinternal.h>
58967 +
58968 +static const char *restab_log[] = {
58969 + [RLIMIT_CPU] = "RLIMIT_CPU",
58970 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
58971 + [RLIMIT_DATA] = "RLIMIT_DATA",
58972 + [RLIMIT_STACK] = "RLIMIT_STACK",
58973 + [RLIMIT_CORE] = "RLIMIT_CORE",
58974 + [RLIMIT_RSS] = "RLIMIT_RSS",
58975 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
58976 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
58977 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
58978 + [RLIMIT_AS] = "RLIMIT_AS",
58979 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
58980 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
58981 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
58982 + [RLIMIT_NICE] = "RLIMIT_NICE",
58983 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
58984 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
58985 + [GR_CRASH_RES] = "RLIMIT_CRASH"
58986 +};
58987 +
58988 +void
58989 +gr_log_resource(const struct task_struct *task,
58990 + const int res, const unsigned long wanted, const int gt)
58991 +{
58992 + const struct cred *cred;
58993 + unsigned long rlim;
58994 +
58995 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
58996 + return;
58997 +
58998 + // not yet supported resource
58999 + if (unlikely(!restab_log[res]))
59000 + return;
59001 +
59002 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
59003 + rlim = task_rlimit_max(task, res);
59004 + else
59005 + rlim = task_rlimit(task, res);
59006 +
59007 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
59008 + return;
59009 +
59010 + rcu_read_lock();
59011 + cred = __task_cred(task);
59012 +
59013 + if (res == RLIMIT_NPROC &&
59014 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
59015 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
59016 + goto out_rcu_unlock;
59017 + else if (res == RLIMIT_MEMLOCK &&
59018 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
59019 + goto out_rcu_unlock;
59020 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
59021 + goto out_rcu_unlock;
59022 + rcu_read_unlock();
59023 +
59024 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
59025 +
59026 + return;
59027 +out_rcu_unlock:
59028 + rcu_read_unlock();
59029 + return;
59030 +}
59031 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
59032 new file mode 100644
59033 index 0000000..25197e9
59034 --- /dev/null
59035 +++ b/grsecurity/gracl_segv.c
59036 @@ -0,0 +1,299 @@
59037 +#include <linux/kernel.h>
59038 +#include <linux/mm.h>
59039 +#include <asm/uaccess.h>
59040 +#include <asm/errno.h>
59041 +#include <asm/mman.h>
59042 +#include <net/sock.h>
59043 +#include <linux/file.h>
59044 +#include <linux/fs.h>
59045 +#include <linux/net.h>
59046 +#include <linux/in.h>
59047 +#include <linux/slab.h>
59048 +#include <linux/types.h>
59049 +#include <linux/sched.h>
59050 +#include <linux/timer.h>
59051 +#include <linux/gracl.h>
59052 +#include <linux/grsecurity.h>
59053 +#include <linux/grinternal.h>
59054 +
59055 +static struct crash_uid *uid_set;
59056 +static unsigned short uid_used;
59057 +static DEFINE_SPINLOCK(gr_uid_lock);
59058 +extern rwlock_t gr_inode_lock;
59059 +extern struct acl_subject_label *
59060 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
59061 + struct acl_role_label *role);
59062 +
59063 +#ifdef CONFIG_BTRFS_FS
59064 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
59065 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
59066 +#endif
59067 +
59068 +static inline dev_t __get_dev(const struct dentry *dentry)
59069 +{
59070 +#ifdef CONFIG_BTRFS_FS
59071 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
59072 + return get_btrfs_dev_from_inode(dentry->d_inode);
59073 + else
59074 +#endif
59075 + return dentry->d_inode->i_sb->s_dev;
59076 +}
59077 +
59078 +int
59079 +gr_init_uidset(void)
59080 +{
59081 + uid_set =
59082 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
59083 + uid_used = 0;
59084 +
59085 + return uid_set ? 1 : 0;
59086 +}
59087 +
59088 +void
59089 +gr_free_uidset(void)
59090 +{
59091 + if (uid_set)
59092 + kfree(uid_set);
59093 +
59094 + return;
59095 +}
59096 +
59097 +int
59098 +gr_find_uid(const uid_t uid)
59099 +{
59100 + struct crash_uid *tmp = uid_set;
59101 + uid_t buid;
59102 + int low = 0, high = uid_used - 1, mid;
59103 +
59104 + while (high >= low) {
59105 + mid = (low + high) >> 1;
59106 + buid = tmp[mid].uid;
59107 + if (buid == uid)
59108 + return mid;
59109 + if (buid > uid)
59110 + high = mid - 1;
59111 + if (buid < uid)
59112 + low = mid + 1;
59113 + }
59114 +
59115 + return -1;
59116 +}
59117 +
59118 +static __inline__ void
59119 +gr_insertsort(void)
59120 +{
59121 + unsigned short i, j;
59122 + struct crash_uid index;
59123 +
59124 + for (i = 1; i < uid_used; i++) {
59125 + index = uid_set[i];
59126 + j = i;
59127 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
59128 + uid_set[j] = uid_set[j - 1];
59129 + j--;
59130 + }
59131 + uid_set[j] = index;
59132 + }
59133 +
59134 + return;
59135 +}
59136 +
59137 +static __inline__ void
59138 +gr_insert_uid(const uid_t uid, const unsigned long expires)
59139 +{
59140 + int loc;
59141 +
59142 + if (uid_used == GR_UIDTABLE_MAX)
59143 + return;
59144 +
59145 + loc = gr_find_uid(uid);
59146 +
59147 + if (loc >= 0) {
59148 + uid_set[loc].expires = expires;
59149 + return;
59150 + }
59151 +
59152 + uid_set[uid_used].uid = uid;
59153 + uid_set[uid_used].expires = expires;
59154 + uid_used++;
59155 +
59156 + gr_insertsort();
59157 +
59158 + return;
59159 +}
59160 +
59161 +void
59162 +gr_remove_uid(const unsigned short loc)
59163 +{
59164 + unsigned short i;
59165 +
59166 + for (i = loc + 1; i < uid_used; i++)
59167 + uid_set[i - 1] = uid_set[i];
59168 +
59169 + uid_used--;
59170 +
59171 + return;
59172 +}
59173 +
59174 +int
59175 +gr_check_crash_uid(const uid_t uid)
59176 +{
59177 + int loc;
59178 + int ret = 0;
59179 +
59180 + if (unlikely(!gr_acl_is_enabled()))
59181 + return 0;
59182 +
59183 + spin_lock(&gr_uid_lock);
59184 + loc = gr_find_uid(uid);
59185 +
59186 + if (loc < 0)
59187 + goto out_unlock;
59188 +
59189 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
59190 + gr_remove_uid(loc);
59191 + else
59192 + ret = 1;
59193 +
59194 +out_unlock:
59195 + spin_unlock(&gr_uid_lock);
59196 + return ret;
59197 +}
59198 +
59199 +static __inline__ int
59200 +proc_is_setxid(const struct cred *cred)
59201 +{
59202 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
59203 + !uid_eq(cred->uid, cred->fsuid))
59204 + return 1;
59205 + if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
59206 + !uid_eq(cred->gid, cred->fsgid))
59207 + return 1;
59208 +
59209 + return 0;
59210 +}
59211 +
59212 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
59213 +
59214 +void
59215 +gr_handle_crash(struct task_struct *task, const int sig)
59216 +{
59217 + struct acl_subject_label *curr;
59218 + struct task_struct *tsk, *tsk2;
59219 + const struct cred *cred;
59220 + const struct cred *cred2;
59221 +
59222 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
59223 + return;
59224 +
59225 + if (unlikely(!gr_acl_is_enabled()))
59226 + return;
59227 +
59228 + curr = task->acl;
59229 +
59230 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
59231 + return;
59232 +
59233 + if (time_before_eq(curr->expires, get_seconds())) {
59234 + curr->expires = 0;
59235 + curr->crashes = 0;
59236 + }
59237 +
59238 + curr->crashes++;
59239 +
59240 + if (!curr->expires)
59241 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
59242 +
59243 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
59244 + time_after(curr->expires, get_seconds())) {
59245 + rcu_read_lock();
59246 + cred = __task_cred(task);
59247 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
59248 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
59249 + spin_lock(&gr_uid_lock);
59250 + gr_insert_uid(cred->uid, curr->expires);
59251 + spin_unlock(&gr_uid_lock);
59252 + curr->expires = 0;
59253 + curr->crashes = 0;
59254 + read_lock(&tasklist_lock);
59255 + do_each_thread(tsk2, tsk) {
59256 + cred2 = __task_cred(tsk);
59257 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
59258 + gr_fake_force_sig(SIGKILL, tsk);
59259 + } while_each_thread(tsk2, tsk);
59260 + read_unlock(&tasklist_lock);
59261 + } else {
59262 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
59263 + read_lock(&tasklist_lock);
59264 + read_lock(&grsec_exec_file_lock);
59265 + do_each_thread(tsk2, tsk) {
59266 + if (likely(tsk != task)) {
59267 + // if this thread has the same subject as the one that triggered
59268 + // RES_CRASH and it's the same binary, kill it
59269 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
59270 + gr_fake_force_sig(SIGKILL, tsk);
59271 + }
59272 + } while_each_thread(tsk2, tsk);
59273 + read_unlock(&grsec_exec_file_lock);
59274 + read_unlock(&tasklist_lock);
59275 + }
59276 + rcu_read_unlock();
59277 + }
59278 +
59279 + return;
59280 +}
59281 +
59282 +int
59283 +gr_check_crash_exec(const struct file *filp)
59284 +{
59285 + struct acl_subject_label *curr;
59286 +
59287 + if (unlikely(!gr_acl_is_enabled()))
59288 + return 0;
59289 +
59290 + read_lock(&gr_inode_lock);
59291 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
59292 + __get_dev(filp->f_path.dentry),
59293 + current->role);
59294 + read_unlock(&gr_inode_lock);
59295 +
59296 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
59297 + (!curr->crashes && !curr->expires))
59298 + return 0;
59299 +
59300 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
59301 + time_after(curr->expires, get_seconds()))
59302 + return 1;
59303 + else if (time_before_eq(curr->expires, get_seconds())) {
59304 + curr->crashes = 0;
59305 + curr->expires = 0;
59306 + }
59307 +
59308 + return 0;
59309 +}
59310 +
59311 +void
59312 +gr_handle_alertkill(struct task_struct *task)
59313 +{
59314 + struct acl_subject_label *curracl;
59315 + __u32 curr_ip;
59316 + struct task_struct *p, *p2;
59317 +
59318 + if (unlikely(!gr_acl_is_enabled()))
59319 + return;
59320 +
59321 + curracl = task->acl;
59322 + curr_ip = task->signal->curr_ip;
59323 +
59324 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
59325 + read_lock(&tasklist_lock);
59326 + do_each_thread(p2, p) {
59327 + if (p->signal->curr_ip == curr_ip)
59328 + gr_fake_force_sig(SIGKILL, p);
59329 + } while_each_thread(p2, p);
59330 + read_unlock(&tasklist_lock);
59331 + } else if (curracl->mode & GR_KILLPROC)
59332 + gr_fake_force_sig(SIGKILL, task);
59333 +
59334 + return;
59335 +}
59336 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
59337 new file mode 100644
59338 index 0000000..9d83a69
59339 --- /dev/null
59340 +++ b/grsecurity/gracl_shm.c
59341 @@ -0,0 +1,40 @@
59342 +#include <linux/kernel.h>
59343 +#include <linux/mm.h>
59344 +#include <linux/sched.h>
59345 +#include <linux/file.h>
59346 +#include <linux/ipc.h>
59347 +#include <linux/gracl.h>
59348 +#include <linux/grsecurity.h>
59349 +#include <linux/grinternal.h>
59350 +
59351 +int
59352 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
59353 + const time_t shm_createtime, const uid_t cuid, const int shmid)
59354 +{
59355 + struct task_struct *task;
59356 +
59357 + if (!gr_acl_is_enabled())
59358 + return 1;
59359 +
59360 + rcu_read_lock();
59361 + read_lock(&tasklist_lock);
59362 +
59363 + task = find_task_by_vpid(shm_cprid);
59364 +
59365 + if (unlikely(!task))
59366 + task = find_task_by_vpid(shm_lapid);
59367 +
59368 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
59369 + (task->pid == shm_lapid)) &&
59370 + (task->acl->mode & GR_PROTSHM) &&
59371 + (task->acl != current->acl))) {
59372 + read_unlock(&tasklist_lock);
59373 + rcu_read_unlock();
59374 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
59375 + return 0;
59376 + }
59377 + read_unlock(&tasklist_lock);
59378 + rcu_read_unlock();
59379 +
59380 + return 1;
59381 +}
59382 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
59383 new file mode 100644
59384 index 0000000..bc0be01
59385 --- /dev/null
59386 +++ b/grsecurity/grsec_chdir.c
59387 @@ -0,0 +1,19 @@
59388 +#include <linux/kernel.h>
59389 +#include <linux/sched.h>
59390 +#include <linux/fs.h>
59391 +#include <linux/file.h>
59392 +#include <linux/grsecurity.h>
59393 +#include <linux/grinternal.h>
59394 +
59395 +void
59396 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
59397 +{
59398 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59399 + if ((grsec_enable_chdir && grsec_enable_group &&
59400 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
59401 + !grsec_enable_group)) {
59402 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
59403 + }
59404 +#endif
59405 + return;
59406 +}
59407 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
59408 new file mode 100644
59409 index 0000000..70fe0ae
59410 --- /dev/null
59411 +++ b/grsecurity/grsec_chroot.c
59412 @@ -0,0 +1,357 @@
59413 +#include <linux/kernel.h>
59414 +#include <linux/module.h>
59415 +#include <linux/sched.h>
59416 +#include <linux/file.h>
59417 +#include <linux/fs.h>
59418 +#include <linux/mount.h>
59419 +#include <linux/types.h>
59420 +#include "../fs/mount.h"
59421 +#include <linux/grsecurity.h>
59422 +#include <linux/grinternal.h>
59423 +
59424 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
59425 +{
59426 +#ifdef CONFIG_GRKERNSEC
59427 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
59428 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
59429 + task->gr_is_chrooted = 1;
59430 + else
59431 + task->gr_is_chrooted = 0;
59432 +
59433 + task->gr_chroot_dentry = path->dentry;
59434 +#endif
59435 + return;
59436 +}
59437 +
59438 +void gr_clear_chroot_entries(struct task_struct *task)
59439 +{
59440 +#ifdef CONFIG_GRKERNSEC
59441 + task->gr_is_chrooted = 0;
59442 + task->gr_chroot_dentry = NULL;
59443 +#endif
59444 + return;
59445 +}
59446 +
59447 +int
59448 +gr_handle_chroot_unix(const pid_t pid)
59449 +{
59450 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59451 + struct task_struct *p;
59452 +
59453 + if (unlikely(!grsec_enable_chroot_unix))
59454 + return 1;
59455 +
59456 + if (likely(!proc_is_chrooted(current)))
59457 + return 1;
59458 +
59459 + rcu_read_lock();
59460 + read_lock(&tasklist_lock);
59461 + p = find_task_by_vpid_unrestricted(pid);
59462 + if (unlikely(p && !have_same_root(current, p))) {
59463 + read_unlock(&tasklist_lock);
59464 + rcu_read_unlock();
59465 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
59466 + return 0;
59467 + }
59468 + read_unlock(&tasklist_lock);
59469 + rcu_read_unlock();
59470 +#endif
59471 + return 1;
59472 +}
59473 +
59474 +int
59475 +gr_handle_chroot_nice(void)
59476 +{
59477 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59478 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
59479 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
59480 + return -EPERM;
59481 + }
59482 +#endif
59483 + return 0;
59484 +}
59485 +
59486 +int
59487 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
59488 +{
59489 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59490 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
59491 + && proc_is_chrooted(current)) {
59492 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
59493 + return -EACCES;
59494 + }
59495 +#endif
59496 + return 0;
59497 +}
59498 +
59499 +int
59500 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
59501 +{
59502 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59503 + struct task_struct *p;
59504 + int ret = 0;
59505 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
59506 + return ret;
59507 +
59508 + read_lock(&tasklist_lock);
59509 + do_each_pid_task(pid, type, p) {
59510 + if (!have_same_root(current, p)) {
59511 + ret = 1;
59512 + goto out;
59513 + }
59514 + } while_each_pid_task(pid, type, p);
59515 +out:
59516 + read_unlock(&tasklist_lock);
59517 + return ret;
59518 +#endif
59519 + return 0;
59520 +}
59521 +
59522 +int
59523 +gr_pid_is_chrooted(struct task_struct *p)
59524 +{
59525 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59526 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
59527 + return 0;
59528 +
59529 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
59530 + !have_same_root(current, p)) {
59531 + return 1;
59532 + }
59533 +#endif
59534 + return 0;
59535 +}
59536 +
59537 +EXPORT_SYMBOL(gr_pid_is_chrooted);
59538 +
59539 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
59540 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
59541 +{
59542 + struct path path, currentroot;
59543 + int ret = 0;
59544 +
59545 + path.dentry = (struct dentry *)u_dentry;
59546 + path.mnt = (struct vfsmount *)u_mnt;
59547 + get_fs_root(current->fs, &currentroot);
59548 + if (path_is_under(&path, &currentroot))
59549 + ret = 1;
59550 + path_put(&currentroot);
59551 +
59552 + return ret;
59553 +}
59554 +#endif
59555 +
59556 +int
59557 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
59558 +{
59559 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59560 + if (!grsec_enable_chroot_fchdir)
59561 + return 1;
59562 +
59563 + if (!proc_is_chrooted(current))
59564 + return 1;
59565 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
59566 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
59567 + return 0;
59568 + }
59569 +#endif
59570 + return 1;
59571 +}
59572 +
59573 +int
59574 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
59575 + const time_t shm_createtime)
59576 +{
59577 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59578 + struct task_struct *p;
59579 + time_t starttime;
59580 +
59581 + if (unlikely(!grsec_enable_chroot_shmat))
59582 + return 1;
59583 +
59584 + if (likely(!proc_is_chrooted(current)))
59585 + return 1;
59586 +
59587 + rcu_read_lock();
59588 + read_lock(&tasklist_lock);
59589 +
59590 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
59591 + starttime = p->start_time.tv_sec;
59592 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
59593 + if (have_same_root(current, p)) {
59594 + goto allow;
59595 + } else {
59596 + read_unlock(&tasklist_lock);
59597 + rcu_read_unlock();
59598 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
59599 + return 0;
59600 + }
59601 + }
59602 + /* creator exited, pid reuse, fall through to next check */
59603 + }
59604 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
59605 + if (unlikely(!have_same_root(current, p))) {
59606 + read_unlock(&tasklist_lock);
59607 + rcu_read_unlock();
59608 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
59609 + return 0;
59610 + }
59611 + }
59612 +
59613 +allow:
59614 + read_unlock(&tasklist_lock);
59615 + rcu_read_unlock();
59616 +#endif
59617 + return 1;
59618 +}
59619 +
59620 +void
59621 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
59622 +{
59623 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59624 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
59625 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
59626 +#endif
59627 + return;
59628 +}
59629 +
59630 +int
59631 +gr_handle_chroot_mknod(const struct dentry *dentry,
59632 + const struct vfsmount *mnt, const int mode)
59633 +{
59634 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59635 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
59636 + proc_is_chrooted(current)) {
59637 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
59638 + return -EPERM;
59639 + }
59640 +#endif
59641 + return 0;
59642 +}
59643 +
59644 +int
59645 +gr_handle_chroot_mount(const struct dentry *dentry,
59646 + const struct vfsmount *mnt, const char *dev_name)
59647 +{
59648 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59649 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
59650 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
59651 + return -EPERM;
59652 + }
59653 +#endif
59654 + return 0;
59655 +}
59656 +
59657 +int
59658 +gr_handle_chroot_pivot(void)
59659 +{
59660 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59661 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
59662 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
59663 + return -EPERM;
59664 + }
59665 +#endif
59666 + return 0;
59667 +}
59668 +
59669 +int
59670 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
59671 +{
59672 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59673 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
59674 + !gr_is_outside_chroot(dentry, mnt)) {
59675 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
59676 + return -EPERM;
59677 + }
59678 +#endif
59679 + return 0;
59680 +}
59681 +
59682 +extern const char *captab_log[];
59683 +extern int captab_log_entries;
59684 +
59685 +int
59686 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
59687 +{
59688 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59689 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
59690 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
59691 + if (cap_raised(chroot_caps, cap)) {
59692 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
59693 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
59694 + }
59695 + return 0;
59696 + }
59697 + }
59698 +#endif
59699 + return 1;
59700 +}
59701 +
59702 +int
59703 +gr_chroot_is_capable(const int cap)
59704 +{
59705 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59706 + return gr_task_chroot_is_capable(current, current_cred(), cap);
59707 +#endif
59708 + return 1;
59709 +}
59710 +
59711 +int
59712 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
59713 +{
59714 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59715 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
59716 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
59717 + if (cap_raised(chroot_caps, cap)) {
59718 + return 0;
59719 + }
59720 + }
59721 +#endif
59722 + return 1;
59723 +}
59724 +
59725 +int
59726 +gr_chroot_is_capable_nolog(const int cap)
59727 +{
59728 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59729 + return gr_task_chroot_is_capable_nolog(current, cap);
59730 +#endif
59731 + return 1;
59732 +}
59733 +
59734 +int
59735 +gr_handle_chroot_sysctl(const int op)
59736 +{
59737 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59738 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
59739 + proc_is_chrooted(current))
59740 + return -EACCES;
59741 +#endif
59742 + return 0;
59743 +}
59744 +
59745 +void
59746 +gr_handle_chroot_chdir(struct path *path)
59747 +{
59748 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59749 + if (grsec_enable_chroot_chdir)
59750 + set_fs_pwd(current->fs, path);
59751 +#endif
59752 + return;
59753 +}
59754 +
59755 +int
59756 +gr_handle_chroot_chmod(const struct dentry *dentry,
59757 + const struct vfsmount *mnt, const int mode)
59758 +{
59759 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59760 + /* allow chmod +s on directories, but not files */
59761 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
59762 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
59763 + proc_is_chrooted(current)) {
59764 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
59765 + return -EPERM;
59766 + }
59767 +#endif
59768 + return 0;
59769 +}
59770 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
59771 new file mode 100644
59772 index 0000000..e6796b3
59773 --- /dev/null
59774 +++ b/grsecurity/grsec_disabled.c
59775 @@ -0,0 +1,434 @@
59776 +#include <linux/kernel.h>
59777 +#include <linux/module.h>
59778 +#include <linux/sched.h>
59779 +#include <linux/file.h>
59780 +#include <linux/fs.h>
59781 +#include <linux/kdev_t.h>
59782 +#include <linux/net.h>
59783 +#include <linux/in.h>
59784 +#include <linux/ip.h>
59785 +#include <linux/skbuff.h>
59786 +#include <linux/sysctl.h>
59787 +
59788 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
59789 +void
59790 +pax_set_initial_flags(struct linux_binprm *bprm)
59791 +{
59792 + return;
59793 +}
59794 +#endif
59795 +
59796 +#ifdef CONFIG_SYSCTL
59797 +__u32
59798 +gr_handle_sysctl(const struct ctl_table * table, const int op)
59799 +{
59800 + return 0;
59801 +}
59802 +#endif
59803 +
59804 +#ifdef CONFIG_TASKSTATS
59805 +int gr_is_taskstats_denied(int pid)
59806 +{
59807 + return 0;
59808 +}
59809 +#endif
59810 +
59811 +int
59812 +gr_acl_is_enabled(void)
59813 +{
59814 + return 0;
59815 +}
59816 +
59817 +void
59818 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
59819 +{
59820 + return;
59821 +}
59822 +
59823 +int
59824 +gr_handle_rawio(const struct inode *inode)
59825 +{
59826 + return 0;
59827 +}
59828 +
59829 +void
59830 +gr_acl_handle_psacct(struct task_struct *task, const long code)
59831 +{
59832 + return;
59833 +}
59834 +
59835 +int
59836 +gr_handle_ptrace(struct task_struct *task, const long request)
59837 +{
59838 + return 0;
59839 +}
59840 +
59841 +int
59842 +gr_handle_proc_ptrace(struct task_struct *task)
59843 +{
59844 + return 0;
59845 +}
59846 +
59847 +int
59848 +gr_set_acls(const int type)
59849 +{
59850 + return 0;
59851 +}
59852 +
59853 +int
59854 +gr_check_hidden_task(const struct task_struct *tsk)
59855 +{
59856 + return 0;
59857 +}
59858 +
59859 +int
59860 +gr_check_protected_task(const struct task_struct *task)
59861 +{
59862 + return 0;
59863 +}
59864 +
59865 +int
59866 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
59867 +{
59868 + return 0;
59869 +}
59870 +
59871 +void
59872 +gr_copy_label(struct task_struct *tsk)
59873 +{
59874 + return;
59875 +}
59876 +
59877 +void
59878 +gr_set_pax_flags(struct task_struct *task)
59879 +{
59880 + return;
59881 +}
59882 +
59883 +int
59884 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
59885 + const int unsafe_share)
59886 +{
59887 + return 0;
59888 +}
59889 +
59890 +void
59891 +gr_handle_delete(const ino_t ino, const dev_t dev)
59892 +{
59893 + return;
59894 +}
59895 +
59896 +void
59897 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
59898 +{
59899 + return;
59900 +}
59901 +
59902 +void
59903 +gr_handle_crash(struct task_struct *task, const int sig)
59904 +{
59905 + return;
59906 +}
59907 +
59908 +int
59909 +gr_check_crash_exec(const struct file *filp)
59910 +{
59911 + return 0;
59912 +}
59913 +
59914 +int
59915 +gr_check_crash_uid(const uid_t uid)
59916 +{
59917 + return 0;
59918 +}
59919 +
59920 +void
59921 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
59922 + struct dentry *old_dentry,
59923 + struct dentry *new_dentry,
59924 + struct vfsmount *mnt, const __u8 replace)
59925 +{
59926 + return;
59927 +}
59928 +
59929 +int
59930 +gr_search_socket(const int family, const int type, const int protocol)
59931 +{
59932 + return 1;
59933 +}
59934 +
59935 +int
59936 +gr_search_connectbind(const int mode, const struct socket *sock,
59937 + const struct sockaddr_in *addr)
59938 +{
59939 + return 0;
59940 +}
59941 +
59942 +void
59943 +gr_handle_alertkill(struct task_struct *task)
59944 +{
59945 + return;
59946 +}
59947 +
59948 +__u32
59949 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
59950 +{
59951 + return 1;
59952 +}
59953 +
59954 +__u32
59955 +gr_acl_handle_hidden_file(const struct dentry * dentry,
59956 + const struct vfsmount * mnt)
59957 +{
59958 + return 1;
59959 +}
59960 +
59961 +__u32
59962 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
59963 + int acc_mode)
59964 +{
59965 + return 1;
59966 +}
59967 +
59968 +__u32
59969 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
59970 +{
59971 + return 1;
59972 +}
59973 +
59974 +__u32
59975 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
59976 +{
59977 + return 1;
59978 +}
59979 +
59980 +int
59981 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
59982 + unsigned int *vm_flags)
59983 +{
59984 + return 1;
59985 +}
59986 +
59987 +__u32
59988 +gr_acl_handle_truncate(const struct dentry * dentry,
59989 + const struct vfsmount * mnt)
59990 +{
59991 + return 1;
59992 +}
59993 +
59994 +__u32
59995 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
59996 +{
59997 + return 1;
59998 +}
59999 +
60000 +__u32
60001 +gr_acl_handle_access(const struct dentry * dentry,
60002 + const struct vfsmount * mnt, const int fmode)
60003 +{
60004 + return 1;
60005 +}
60006 +
60007 +__u32
60008 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
60009 + umode_t *mode)
60010 +{
60011 + return 1;
60012 +}
60013 +
60014 +__u32
60015 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
60016 +{
60017 + return 1;
60018 +}
60019 +
60020 +__u32
60021 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
60022 +{
60023 + return 1;
60024 +}
60025 +
60026 +void
60027 +grsecurity_init(void)
60028 +{
60029 + return;
60030 +}
60031 +
60032 +umode_t gr_acl_umask(void)
60033 +{
60034 + return 0;
60035 +}
60036 +
60037 +__u32
60038 +gr_acl_handle_mknod(const struct dentry * new_dentry,
60039 + const struct dentry * parent_dentry,
60040 + const struct vfsmount * parent_mnt,
60041 + const int mode)
60042 +{
60043 + return 1;
60044 +}
60045 +
60046 +__u32
60047 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
60048 + const struct dentry * parent_dentry,
60049 + const struct vfsmount * parent_mnt)
60050 +{
60051 + return 1;
60052 +}
60053 +
60054 +__u32
60055 +gr_acl_handle_symlink(const struct dentry * new_dentry,
60056 + const struct dentry * parent_dentry,
60057 + const struct vfsmount * parent_mnt, const struct filename *from)
60058 +{
60059 + return 1;
60060 +}
60061 +
60062 +__u32
60063 +gr_acl_handle_link(const struct dentry * new_dentry,
60064 + const struct dentry * parent_dentry,
60065 + const struct vfsmount * parent_mnt,
60066 + const struct dentry * old_dentry,
60067 + const struct vfsmount * old_mnt, const struct filename *to)
60068 +{
60069 + return 1;
60070 +}
60071 +
60072 +int
60073 +gr_acl_handle_rename(const struct dentry *new_dentry,
60074 + const struct dentry *parent_dentry,
60075 + const struct vfsmount *parent_mnt,
60076 + const struct dentry *old_dentry,
60077 + const struct inode *old_parent_inode,
60078 + const struct vfsmount *old_mnt, const struct filename *newname)
60079 +{
60080 + return 0;
60081 +}
60082 +
60083 +int
60084 +gr_acl_handle_filldir(const struct file *file, const char *name,
60085 + const int namelen, const ino_t ino)
60086 +{
60087 + return 1;
60088 +}
60089 +
60090 +int
60091 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
60092 + const time_t shm_createtime, const uid_t cuid, const int shmid)
60093 +{
60094 + return 1;
60095 +}
60096 +
60097 +int
60098 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
60099 +{
60100 + return 0;
60101 +}
60102 +
60103 +int
60104 +gr_search_accept(const struct socket *sock)
60105 +{
60106 + return 0;
60107 +}
60108 +
60109 +int
60110 +gr_search_listen(const struct socket *sock)
60111 +{
60112 + return 0;
60113 +}
60114 +
60115 +int
60116 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
60117 +{
60118 + return 0;
60119 +}
60120 +
60121 +__u32
60122 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
60123 +{
60124 + return 1;
60125 +}
60126 +
60127 +__u32
60128 +gr_acl_handle_creat(const struct dentry * dentry,
60129 + const struct dentry * p_dentry,
60130 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
60131 + const int imode)
60132 +{
60133 + return 1;
60134 +}
60135 +
60136 +void
60137 +gr_acl_handle_exit(void)
60138 +{
60139 + return;
60140 +}
60141 +
60142 +int
60143 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
60144 +{
60145 + return 1;
60146 +}
60147 +
60148 +void
60149 +gr_set_role_label(const uid_t uid, const gid_t gid)
60150 +{
60151 + return;
60152 +}
60153 +
60154 +int
60155 +gr_acl_handle_procpidmem(const struct task_struct *task)
60156 +{
60157 + return 0;
60158 +}
60159 +
60160 +int
60161 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
60162 +{
60163 + return 0;
60164 +}
60165 +
60166 +int
60167 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
60168 +{
60169 + return 0;
60170 +}
60171 +
60172 +void
60173 +gr_set_kernel_label(struct task_struct *task)
60174 +{
60175 + return;
60176 +}
60177 +
60178 +int
60179 +gr_check_user_change(int real, int effective, int fs)
60180 +{
60181 + return 0;
60182 +}
60183 +
60184 +int
60185 +gr_check_group_change(int real, int effective, int fs)
60186 +{
60187 + return 0;
60188 +}
60189 +
60190 +int gr_acl_enable_at_secure(void)
60191 +{
60192 + return 0;
60193 +}
60194 +
60195 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
60196 +{
60197 + return dentry->d_inode->i_sb->s_dev;
60198 +}
60199 +
60200 +void gr_put_exec_file(struct task_struct *task)
60201 +{
60202 + return;
60203 +}
60204 +
60205 +EXPORT_SYMBOL(gr_set_kernel_label);
60206 +#ifdef CONFIG_SECURITY
60207 +EXPORT_SYMBOL(gr_check_user_change);
60208 +EXPORT_SYMBOL(gr_check_group_change);
60209 +#endif
60210 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
60211 new file mode 100644
60212 index 0000000..abfa971
60213 --- /dev/null
60214 +++ b/grsecurity/grsec_exec.c
60215 @@ -0,0 +1,174 @@
60216 +#include <linux/kernel.h>
60217 +#include <linux/sched.h>
60218 +#include <linux/file.h>
60219 +#include <linux/binfmts.h>
60220 +#include <linux/fs.h>
60221 +#include <linux/types.h>
60222 +#include <linux/grdefs.h>
60223 +#include <linux/grsecurity.h>
60224 +#include <linux/grinternal.h>
60225 +#include <linux/capability.h>
60226 +#include <linux/module.h>
60227 +
60228 +#include <asm/uaccess.h>
60229 +
60230 +#ifdef CONFIG_GRKERNSEC_EXECLOG
60231 +static char gr_exec_arg_buf[132];
60232 +static DEFINE_MUTEX(gr_exec_arg_mutex);
60233 +#endif
60234 +
60235 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
60236 +
60237 +void
60238 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
60239 +{
60240 +#ifdef CONFIG_GRKERNSEC_EXECLOG
60241 + char *grarg = gr_exec_arg_buf;
60242 + unsigned int i, x, execlen = 0;
60243 + char c;
60244 +
60245 + if (!((grsec_enable_execlog && grsec_enable_group &&
60246 + in_group_p(grsec_audit_gid))
60247 + || (grsec_enable_execlog && !grsec_enable_group)))
60248 + return;
60249 +
60250 + mutex_lock(&gr_exec_arg_mutex);
60251 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
60252 +
60253 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
60254 + const char __user *p;
60255 + unsigned int len;
60256 +
60257 + p = get_user_arg_ptr(argv, i);
60258 + if (IS_ERR(p))
60259 + goto log;
60260 +
60261 + len = strnlen_user(p, 128 - execlen);
60262 + if (len > 128 - execlen)
60263 + len = 128 - execlen;
60264 + else if (len > 0)
60265 + len--;
60266 + if (copy_from_user(grarg + execlen, p, len))
60267 + goto log;
60268 +
60269 + /* rewrite unprintable characters */
60270 + for (x = 0; x < len; x++) {
60271 + c = *(grarg + execlen + x);
60272 + if (c < 32 || c > 126)
60273 + *(grarg + execlen + x) = ' ';
60274 + }
60275 +
60276 + execlen += len;
60277 + *(grarg + execlen) = ' ';
60278 + *(grarg + execlen + 1) = '\0';
60279 + execlen++;
60280 + }
60281 +
60282 + log:
60283 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
60284 + bprm->file->f_path.mnt, grarg);
60285 + mutex_unlock(&gr_exec_arg_mutex);
60286 +#endif
60287 + return;
60288 +}
60289 +
60290 +#ifdef CONFIG_GRKERNSEC
60291 +extern int gr_acl_is_capable(const int cap);
60292 +extern int gr_acl_is_capable_nolog(const int cap);
60293 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
60294 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
60295 +extern int gr_chroot_is_capable(const int cap);
60296 +extern int gr_chroot_is_capable_nolog(const int cap);
60297 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
60298 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
60299 +#endif
60300 +
60301 +const char *captab_log[] = {
60302 + "CAP_CHOWN",
60303 + "CAP_DAC_OVERRIDE",
60304 + "CAP_DAC_READ_SEARCH",
60305 + "CAP_FOWNER",
60306 + "CAP_FSETID",
60307 + "CAP_KILL",
60308 + "CAP_SETGID",
60309 + "CAP_SETUID",
60310 + "CAP_SETPCAP",
60311 + "CAP_LINUX_IMMUTABLE",
60312 + "CAP_NET_BIND_SERVICE",
60313 + "CAP_NET_BROADCAST",
60314 + "CAP_NET_ADMIN",
60315 + "CAP_NET_RAW",
60316 + "CAP_IPC_LOCK",
60317 + "CAP_IPC_OWNER",
60318 + "CAP_SYS_MODULE",
60319 + "CAP_SYS_RAWIO",
60320 + "CAP_SYS_CHROOT",
60321 + "CAP_SYS_PTRACE",
60322 + "CAP_SYS_PACCT",
60323 + "CAP_SYS_ADMIN",
60324 + "CAP_SYS_BOOT",
60325 + "CAP_SYS_NICE",
60326 + "CAP_SYS_RESOURCE",
60327 + "CAP_SYS_TIME",
60328 + "CAP_SYS_TTY_CONFIG",
60329 + "CAP_MKNOD",
60330 + "CAP_LEASE",
60331 + "CAP_AUDIT_WRITE",
60332 + "CAP_AUDIT_CONTROL",
60333 + "CAP_SETFCAP",
60334 + "CAP_MAC_OVERRIDE",
60335 + "CAP_MAC_ADMIN",
60336 + "CAP_SYSLOG",
60337 + "CAP_WAKE_ALARM"
60338 +};
60339 +
60340 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
60341 +
60342 +int gr_is_capable(const int cap)
60343 +{
60344 +#ifdef CONFIG_GRKERNSEC
60345 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
60346 + return 1;
60347 + return 0;
60348 +#else
60349 + return 1;
60350 +#endif
60351 +}
60352 +
60353 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
60354 +{
60355 +#ifdef CONFIG_GRKERNSEC
60356 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
60357 + return 1;
60358 + return 0;
60359 +#else
60360 + return 1;
60361 +#endif
60362 +}
60363 +
60364 +int gr_is_capable_nolog(const int cap)
60365 +{
60366 +#ifdef CONFIG_GRKERNSEC
60367 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
60368 + return 1;
60369 + return 0;
60370 +#else
60371 + return 1;
60372 +#endif
60373 +}
60374 +
60375 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
60376 +{
60377 +#ifdef CONFIG_GRKERNSEC
60378 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
60379 + return 1;
60380 + return 0;
60381 +#else
60382 + return 1;
60383 +#endif
60384 +}
60385 +
60386 +EXPORT_SYMBOL(gr_is_capable);
60387 +EXPORT_SYMBOL(gr_is_capable_nolog);
60388 +EXPORT_SYMBOL(gr_task_is_capable);
60389 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
60390 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
60391 new file mode 100644
60392 index 0000000..d3ee748
60393 --- /dev/null
60394 +++ b/grsecurity/grsec_fifo.c
60395 @@ -0,0 +1,24 @@
60396 +#include <linux/kernel.h>
60397 +#include <linux/sched.h>
60398 +#include <linux/fs.h>
60399 +#include <linux/file.h>
60400 +#include <linux/grinternal.h>
60401 +
60402 +int
60403 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
60404 + const struct dentry *dir, const int flag, const int acc_mode)
60405 +{
60406 +#ifdef CONFIG_GRKERNSEC_FIFO
60407 + const struct cred *cred = current_cred();
60408 +
60409 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
60410 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
60411 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
60412 + (cred->fsuid != dentry->d_inode->i_uid)) {
60413 + if (!inode_permission(dentry->d_inode, acc_mode))
60414 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
60415 + return -EACCES;
60416 + }
60417 +#endif
60418 + return 0;
60419 +}
60420 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
60421 new file mode 100644
60422 index 0000000..8ca18bf
60423 --- /dev/null
60424 +++ b/grsecurity/grsec_fork.c
60425 @@ -0,0 +1,23 @@
60426 +#include <linux/kernel.h>
60427 +#include <linux/sched.h>
60428 +#include <linux/grsecurity.h>
60429 +#include <linux/grinternal.h>
60430 +#include <linux/errno.h>
60431 +
60432 +void
60433 +gr_log_forkfail(const int retval)
60434 +{
60435 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
60436 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
60437 + switch (retval) {
60438 + case -EAGAIN:
60439 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
60440 + break;
60441 + case -ENOMEM:
60442 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
60443 + break;
60444 + }
60445 + }
60446 +#endif
60447 + return;
60448 +}
60449 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
60450 new file mode 100644
60451 index 0000000..05a6015
60452 --- /dev/null
60453 +++ b/grsecurity/grsec_init.c
60454 @@ -0,0 +1,283 @@
60455 +#include <linux/kernel.h>
60456 +#include <linux/sched.h>
60457 +#include <linux/mm.h>
60458 +#include <linux/gracl.h>
60459 +#include <linux/slab.h>
60460 +#include <linux/vmalloc.h>
60461 +#include <linux/percpu.h>
60462 +#include <linux/module.h>
60463 +
60464 +int grsec_enable_ptrace_readexec;
60465 +int grsec_enable_setxid;
60466 +int grsec_enable_symlinkown;
60467 +int grsec_symlinkown_gid;
60468 +int grsec_enable_brute;
60469 +int grsec_enable_link;
60470 +int grsec_enable_dmesg;
60471 +int grsec_enable_harden_ptrace;
60472 +int grsec_enable_fifo;
60473 +int grsec_enable_execlog;
60474 +int grsec_enable_signal;
60475 +int grsec_enable_forkfail;
60476 +int grsec_enable_audit_ptrace;
60477 +int grsec_enable_time;
60478 +int grsec_enable_audit_textrel;
60479 +int grsec_enable_group;
60480 +int grsec_audit_gid;
60481 +int grsec_enable_chdir;
60482 +int grsec_enable_mount;
60483 +int grsec_enable_rofs;
60484 +int grsec_enable_chroot_findtask;
60485 +int grsec_enable_chroot_mount;
60486 +int grsec_enable_chroot_shmat;
60487 +int grsec_enable_chroot_fchdir;
60488 +int grsec_enable_chroot_double;
60489 +int grsec_enable_chroot_pivot;
60490 +int grsec_enable_chroot_chdir;
60491 +int grsec_enable_chroot_chmod;
60492 +int grsec_enable_chroot_mknod;
60493 +int grsec_enable_chroot_nice;
60494 +int grsec_enable_chroot_execlog;
60495 +int grsec_enable_chroot_caps;
60496 +int grsec_enable_chroot_sysctl;
60497 +int grsec_enable_chroot_unix;
60498 +int grsec_enable_tpe;
60499 +int grsec_tpe_gid;
60500 +int grsec_enable_blackhole;
60501 +#ifdef CONFIG_IPV6_MODULE
60502 +EXPORT_SYMBOL(grsec_enable_blackhole);
60503 +#endif
60504 +int grsec_lastack_retries;
60505 +int grsec_enable_tpe_all;
60506 +int grsec_enable_tpe_invert;
60507 +int grsec_enable_socket_all;
60508 +int grsec_socket_all_gid;
60509 +int grsec_enable_socket_client;
60510 +int grsec_socket_client_gid;
60511 +int grsec_enable_socket_server;
60512 +int grsec_socket_server_gid;
60513 +int grsec_resource_logging;
60514 +int grsec_disable_privio;
60515 +int grsec_enable_log_rwxmaps;
60516 +int grsec_lock;
60517 +
60518 +DEFINE_SPINLOCK(grsec_alert_lock);
60519 +unsigned long grsec_alert_wtime = 0;
60520 +unsigned long grsec_alert_fyet = 0;
60521 +
60522 +DEFINE_SPINLOCK(grsec_audit_lock);
60523 +
60524 +DEFINE_RWLOCK(grsec_exec_file_lock);
60525 +
60526 +char *gr_shared_page[4];
60527 +
60528 +char *gr_alert_log_fmt;
60529 +char *gr_audit_log_fmt;
60530 +char *gr_alert_log_buf;
60531 +char *gr_audit_log_buf;
60532 +
60533 +extern struct gr_arg *gr_usermode;
60534 +extern unsigned char *gr_system_salt;
60535 +extern unsigned char *gr_system_sum;
60536 +
60537 +void __init
60538 +grsecurity_init(void)
60539 +{
60540 + int j;
60541 + /* create the per-cpu shared pages */
60542 +
60543 +#ifdef CONFIG_X86
60544 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
60545 +#endif
60546 +
60547 + for (j = 0; j < 4; j++) {
60548 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
60549 + if (gr_shared_page[j] == NULL) {
60550 + panic("Unable to allocate grsecurity shared page");
60551 + return;
60552 + }
60553 + }
60554 +
60555 + /* allocate log buffers */
60556 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
60557 + if (!gr_alert_log_fmt) {
60558 + panic("Unable to allocate grsecurity alert log format buffer");
60559 + return;
60560 + }
60561 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
60562 + if (!gr_audit_log_fmt) {
60563 + panic("Unable to allocate grsecurity audit log format buffer");
60564 + return;
60565 + }
60566 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
60567 + if (!gr_alert_log_buf) {
60568 + panic("Unable to allocate grsecurity alert log buffer");
60569 + return;
60570 + }
60571 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
60572 + if (!gr_audit_log_buf) {
60573 + panic("Unable to allocate grsecurity audit log buffer");
60574 + return;
60575 + }
60576 +
60577 + /* allocate memory for authentication structure */
60578 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
60579 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
60580 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
60581 +
60582 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
60583 + panic("Unable to allocate grsecurity authentication structure");
60584 + return;
60585 + }
60586 +
60587 +
60588 +#ifdef CONFIG_GRKERNSEC_IO
60589 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
60590 + grsec_disable_privio = 1;
60591 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
60592 + grsec_disable_privio = 1;
60593 +#else
60594 + grsec_disable_privio = 0;
60595 +#endif
60596 +#endif
60597 +
60598 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60599 + /* for backward compatibility, tpe_invert always defaults to on if
60600 + enabled in the kernel
60601 + */
60602 + grsec_enable_tpe_invert = 1;
60603 +#endif
60604 +
60605 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
60606 +#ifndef CONFIG_GRKERNSEC_SYSCTL
60607 + grsec_lock = 1;
60608 +#endif
60609 +
60610 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60611 + grsec_enable_audit_textrel = 1;
60612 +#endif
60613 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60614 + grsec_enable_log_rwxmaps = 1;
60615 +#endif
60616 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60617 + grsec_enable_group = 1;
60618 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
60619 +#endif
60620 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
60621 + grsec_enable_ptrace_readexec = 1;
60622 +#endif
60623 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60624 + grsec_enable_chdir = 1;
60625 +#endif
60626 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60627 + grsec_enable_harden_ptrace = 1;
60628 +#endif
60629 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60630 + grsec_enable_mount = 1;
60631 +#endif
60632 +#ifdef CONFIG_GRKERNSEC_LINK
60633 + grsec_enable_link = 1;
60634 +#endif
60635 +#ifdef CONFIG_GRKERNSEC_BRUTE
60636 + grsec_enable_brute = 1;
60637 +#endif
60638 +#ifdef CONFIG_GRKERNSEC_DMESG
60639 + grsec_enable_dmesg = 1;
60640 +#endif
60641 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
60642 + grsec_enable_blackhole = 1;
60643 + grsec_lastack_retries = 4;
60644 +#endif
60645 +#ifdef CONFIG_GRKERNSEC_FIFO
60646 + grsec_enable_fifo = 1;
60647 +#endif
60648 +#ifdef CONFIG_GRKERNSEC_EXECLOG
60649 + grsec_enable_execlog = 1;
60650 +#endif
60651 +#ifdef CONFIG_GRKERNSEC_SETXID
60652 + grsec_enable_setxid = 1;
60653 +#endif
60654 +#ifdef CONFIG_GRKERNSEC_SIGNAL
60655 + grsec_enable_signal = 1;
60656 +#endif
60657 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
60658 + grsec_enable_forkfail = 1;
60659 +#endif
60660 +#ifdef CONFIG_GRKERNSEC_TIME
60661 + grsec_enable_time = 1;
60662 +#endif
60663 +#ifdef CONFIG_GRKERNSEC_RESLOG
60664 + grsec_resource_logging = 1;
60665 +#endif
60666 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60667 + grsec_enable_chroot_findtask = 1;
60668 +#endif
60669 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
60670 + grsec_enable_chroot_unix = 1;
60671 +#endif
60672 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
60673 + grsec_enable_chroot_mount = 1;
60674 +#endif
60675 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
60676 + grsec_enable_chroot_fchdir = 1;
60677 +#endif
60678 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
60679 + grsec_enable_chroot_shmat = 1;
60680 +#endif
60681 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60682 + grsec_enable_audit_ptrace = 1;
60683 +#endif
60684 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60685 + grsec_enable_chroot_double = 1;
60686 +#endif
60687 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60688 + grsec_enable_chroot_pivot = 1;
60689 +#endif
60690 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60691 + grsec_enable_chroot_chdir = 1;
60692 +#endif
60693 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60694 + grsec_enable_chroot_chmod = 1;
60695 +#endif
60696 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60697 + grsec_enable_chroot_mknod = 1;
60698 +#endif
60699 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60700 + grsec_enable_chroot_nice = 1;
60701 +#endif
60702 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60703 + grsec_enable_chroot_execlog = 1;
60704 +#endif
60705 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60706 + grsec_enable_chroot_caps = 1;
60707 +#endif
60708 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60709 + grsec_enable_chroot_sysctl = 1;
60710 +#endif
60711 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
60712 + grsec_enable_symlinkown = 1;
60713 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
60714 +#endif
60715 +#ifdef CONFIG_GRKERNSEC_TPE
60716 + grsec_enable_tpe = 1;
60717 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
60718 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60719 + grsec_enable_tpe_all = 1;
60720 +#endif
60721 +#endif
60722 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60723 + grsec_enable_socket_all = 1;
60724 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
60725 +#endif
60726 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60727 + grsec_enable_socket_client = 1;
60728 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
60729 +#endif
60730 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60731 + grsec_enable_socket_server = 1;
60732 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
60733 +#endif
60734 +#endif
60735 +
60736 + return;
60737 +}
60738 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
60739 new file mode 100644
60740 index 0000000..6095407
60741 --- /dev/null
60742 +++ b/grsecurity/grsec_link.c
60743 @@ -0,0 +1,58 @@
60744 +#include <linux/kernel.h>
60745 +#include <linux/sched.h>
60746 +#include <linux/fs.h>
60747 +#include <linux/file.h>
60748 +#include <linux/grinternal.h>
60749 +
60750 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
60751 +{
60752 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
60753 + const struct inode *link_inode = link->dentry->d_inode;
60754 +
60755 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
60756 + /* ignore root-owned links, e.g. /proc/self */
60757 + !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
60758 + !uid_eq(link_inode->i_uid, target->i_uid)) {
60759 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
60760 + return 1;
60761 + }
60762 +#endif
60763 + return 0;
60764 +}
60765 +
60766 +int
60767 +gr_handle_follow_link(const struct inode *parent,
60768 + const struct inode *inode,
60769 + const struct dentry *dentry, const struct vfsmount *mnt)
60770 +{
60771 +#ifdef CONFIG_GRKERNSEC_LINK
60772 + const struct cred *cred = current_cred();
60773 +
60774 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
60775 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
60776 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
60777 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
60778 + return -EACCES;
60779 + }
60780 +#endif
60781 + return 0;
60782 +}
60783 +
60784 +int
60785 +gr_handle_hardlink(const struct dentry *dentry,
60786 + const struct vfsmount *mnt,
60787 + struct inode *inode, const int mode, const struct filename *to)
60788 +{
60789 +#ifdef CONFIG_GRKERNSEC_LINK
60790 + const struct cred *cred = current_cred();
60791 +
60792 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
60793 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
60794 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
60795 + !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
60796 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
60797 + return -EPERM;
60798 + }
60799 +#endif
60800 + return 0;
60801 +}
60802 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
60803 new file mode 100644
60804 index 0000000..7bd6c2b
60805 --- /dev/null
60806 +++ b/grsecurity/grsec_log.c
60807 @@ -0,0 +1,329 @@
60808 +#include <linux/kernel.h>
60809 +#include <linux/sched.h>
60810 +#include <linux/file.h>
60811 +#include <linux/tty.h>
60812 +#include <linux/fs.h>
60813 +#include <linux/grinternal.h>
60814 +
60815 +#ifdef CONFIG_TREE_PREEMPT_RCU
60816 +#define DISABLE_PREEMPT() preempt_disable()
60817 +#define ENABLE_PREEMPT() preempt_enable()
60818 +#else
60819 +#define DISABLE_PREEMPT()
60820 +#define ENABLE_PREEMPT()
60821 +#endif
60822 +
60823 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
60824 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
60825 +
60826 +#define BEGIN_LOCKS(x) \
60827 + DISABLE_PREEMPT(); \
60828 + rcu_read_lock(); \
60829 + read_lock(&tasklist_lock); \
60830 + read_lock(&grsec_exec_file_lock); \
60831 + if (x != GR_DO_AUDIT) \
60832 + spin_lock(&grsec_alert_lock); \
60833 + else \
60834 + spin_lock(&grsec_audit_lock)
60835 +
60836 +#define END_LOCKS(x) \
60837 + if (x != GR_DO_AUDIT) \
60838 + spin_unlock(&grsec_alert_lock); \
60839 + else \
60840 + spin_unlock(&grsec_audit_lock); \
60841 + read_unlock(&grsec_exec_file_lock); \
60842 + read_unlock(&tasklist_lock); \
60843 + rcu_read_unlock(); \
60844 + ENABLE_PREEMPT(); \
60845 + if (x == GR_DONT_AUDIT) \
60846 + gr_handle_alertkill(current)
60847 +
60848 +enum {
60849 + FLOODING,
60850 + NO_FLOODING
60851 +};
60852 +
60853 +extern char *gr_alert_log_fmt;
60854 +extern char *gr_audit_log_fmt;
60855 +extern char *gr_alert_log_buf;
60856 +extern char *gr_audit_log_buf;
60857 +
60858 +static int gr_log_start(int audit)
60859 +{
60860 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
60861 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
60862 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60863 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
60864 + unsigned long curr_secs = get_seconds();
60865 +
60866 + if (audit == GR_DO_AUDIT)
60867 + goto set_fmt;
60868 +
60869 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
60870 + grsec_alert_wtime = curr_secs;
60871 + grsec_alert_fyet = 0;
60872 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
60873 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
60874 + grsec_alert_fyet++;
60875 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
60876 + grsec_alert_wtime = curr_secs;
60877 + grsec_alert_fyet++;
60878 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
60879 + return FLOODING;
60880 + }
60881 + else return FLOODING;
60882 +
60883 +set_fmt:
60884 +#endif
60885 + memset(buf, 0, PAGE_SIZE);
60886 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
60887 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
60888 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
60889 + } else if (current->signal->curr_ip) {
60890 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
60891 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
60892 + } else if (gr_acl_is_enabled()) {
60893 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
60894 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
60895 + } else {
60896 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
60897 + strcpy(buf, fmt);
60898 + }
60899 +
60900 + return NO_FLOODING;
60901 +}
60902 +
60903 +static void gr_log_middle(int audit, const char *msg, va_list ap)
60904 + __attribute__ ((format (printf, 2, 0)));
60905 +
60906 +static void gr_log_middle(int audit, const char *msg, va_list ap)
60907 +{
60908 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60909 + unsigned int len = strlen(buf);
60910 +
60911 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
60912 +
60913 + return;
60914 +}
60915 +
60916 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
60917 + __attribute__ ((format (printf, 2, 3)));
60918 +
60919 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
60920 +{
60921 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60922 + unsigned int len = strlen(buf);
60923 + va_list ap;
60924 +
60925 + va_start(ap, msg);
60926 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
60927 + va_end(ap);
60928 +
60929 + return;
60930 +}
60931 +
60932 +static void gr_log_end(int audit, int append_default)
60933 +{
60934 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60935 + if (append_default) {
60936 + struct task_struct *task = current;
60937 + struct task_struct *parent = task->real_parent;
60938 + const struct cred *cred = __task_cred(task);
60939 + const struct cred *pcred = __task_cred(parent);
60940 + unsigned int len = strlen(buf);
60941 +
60942 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
60943 + }
60944 +
60945 + printk("%s\n", buf);
60946 +
60947 + return;
60948 +}
60949 +
60950 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
60951 +{
60952 + int logtype;
60953 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
60954 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
60955 + void *voidptr = NULL;
60956 + int num1 = 0, num2 = 0;
60957 + unsigned long ulong1 = 0, ulong2 = 0;
60958 + struct dentry *dentry = NULL;
60959 + struct vfsmount *mnt = NULL;
60960 + struct file *file = NULL;
60961 + struct task_struct *task = NULL;
60962 + const struct cred *cred, *pcred;
60963 + va_list ap;
60964 +
60965 + BEGIN_LOCKS(audit);
60966 + logtype = gr_log_start(audit);
60967 + if (logtype == FLOODING) {
60968 + END_LOCKS(audit);
60969 + return;
60970 + }
60971 + va_start(ap, argtypes);
60972 + switch (argtypes) {
60973 + case GR_TTYSNIFF:
60974 + task = va_arg(ap, struct task_struct *);
60975 + gr_log_middle_varargs(audit, msg, &task->signal->curr_ip, gr_task_fullpath0(task), task->comm, task_pid_nr(task), gr_parent_task_fullpath0(task), task->real_parent->comm, task_pid_nr(task->real_parent));
60976 + break;
60977 + case GR_SYSCTL_HIDDEN:
60978 + str1 = va_arg(ap, char *);
60979 + gr_log_middle_varargs(audit, msg, result, str1);
60980 + break;
60981 + case GR_RBAC:
60982 + dentry = va_arg(ap, struct dentry *);
60983 + mnt = va_arg(ap, struct vfsmount *);
60984 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
60985 + break;
60986 + case GR_RBAC_STR:
60987 + dentry = va_arg(ap, struct dentry *);
60988 + mnt = va_arg(ap, struct vfsmount *);
60989 + str1 = va_arg(ap, char *);
60990 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
60991 + break;
60992 + case GR_STR_RBAC:
60993 + str1 = va_arg(ap, char *);
60994 + dentry = va_arg(ap, struct dentry *);
60995 + mnt = va_arg(ap, struct vfsmount *);
60996 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
60997 + break;
60998 + case GR_RBAC_MODE2:
60999 + dentry = va_arg(ap, struct dentry *);
61000 + mnt = va_arg(ap, struct vfsmount *);
61001 + str1 = va_arg(ap, char *);
61002 + str2 = va_arg(ap, char *);
61003 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
61004 + break;
61005 + case GR_RBAC_MODE3:
61006 + dentry = va_arg(ap, struct dentry *);
61007 + mnt = va_arg(ap, struct vfsmount *);
61008 + str1 = va_arg(ap, char *);
61009 + str2 = va_arg(ap, char *);
61010 + str3 = va_arg(ap, char *);
61011 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
61012 + break;
61013 + case GR_FILENAME:
61014 + dentry = va_arg(ap, struct dentry *);
61015 + mnt = va_arg(ap, struct vfsmount *);
61016 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
61017 + break;
61018 + case GR_STR_FILENAME:
61019 + str1 = va_arg(ap, char *);
61020 + dentry = va_arg(ap, struct dentry *);
61021 + mnt = va_arg(ap, struct vfsmount *);
61022 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
61023 + break;
61024 + case GR_FILENAME_STR:
61025 + dentry = va_arg(ap, struct dentry *);
61026 + mnt = va_arg(ap, struct vfsmount *);
61027 + str1 = va_arg(ap, char *);
61028 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
61029 + break;
61030 + case GR_FILENAME_TWO_INT:
61031 + dentry = va_arg(ap, struct dentry *);
61032 + mnt = va_arg(ap, struct vfsmount *);
61033 + num1 = va_arg(ap, int);
61034 + num2 = va_arg(ap, int);
61035 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
61036 + break;
61037 + case GR_FILENAME_TWO_INT_STR:
61038 + dentry = va_arg(ap, struct dentry *);
61039 + mnt = va_arg(ap, struct vfsmount *);
61040 + num1 = va_arg(ap, int);
61041 + num2 = va_arg(ap, int);
61042 + str1 = va_arg(ap, char *);
61043 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
61044 + break;
61045 + case GR_TEXTREL:
61046 + file = va_arg(ap, struct file *);
61047 + ulong1 = va_arg(ap, unsigned long);
61048 + ulong2 = va_arg(ap, unsigned long);
61049 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
61050 + break;
61051 + case GR_PTRACE:
61052 + task = va_arg(ap, struct task_struct *);
61053 + gr_log_middle_varargs(audit, msg, task->exec_file ? gr_to_filename(task->exec_file->f_path.dentry, task->exec_file->f_path.mnt) : "(none)", task->comm, task_pid_nr(task));
61054 + break;
61055 + case GR_RESOURCE:
61056 + task = va_arg(ap, struct task_struct *);
61057 + cred = __task_cred(task);
61058 + pcred = __task_cred(task->real_parent);
61059 + ulong1 = va_arg(ap, unsigned long);
61060 + str1 = va_arg(ap, char *);
61061 + ulong2 = va_arg(ap, unsigned long);
61062 + gr_log_middle_varargs(audit, msg, ulong1, str1, ulong2, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
61063 + break;
61064 + case GR_CAP:
61065 + task = va_arg(ap, struct task_struct *);
61066 + cred = __task_cred(task);
61067 + pcred = __task_cred(task->real_parent);
61068 + str1 = va_arg(ap, char *);
61069 + gr_log_middle_varargs(audit, msg, str1, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
61070 + break;
61071 + case GR_SIG:
61072 + str1 = va_arg(ap, char *);
61073 + voidptr = va_arg(ap, void *);
61074 + gr_log_middle_varargs(audit, msg, str1, voidptr);
61075 + break;
61076 + case GR_SIG2:
61077 + task = va_arg(ap, struct task_struct *);
61078 + cred = __task_cred(task);
61079 + pcred = __task_cred(task->real_parent);
61080 + num1 = va_arg(ap, int);
61081 + gr_log_middle_varargs(audit, msg, num1, gr_task_fullpath0(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath0(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
61082 + break;
61083 + case GR_CRASH1:
61084 + task = va_arg(ap, struct task_struct *);
61085 + cred = __task_cred(task);
61086 + pcred = __task_cred(task->real_parent);
61087 + ulong1 = va_arg(ap, unsigned long);
61088 + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid), GR_GLOBAL_UID(cred->uid), ulong1);
61089 + break;
61090 + case GR_CRASH2:
61091 + task = va_arg(ap, struct task_struct *);
61092 + cred = __task_cred(task);
61093 + pcred = __task_cred(task->real_parent);
61094 + ulong1 = va_arg(ap, unsigned long);
61095 + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid), ulong1);
61096 + break;
61097 + case GR_RWXMAP:
61098 + file = va_arg(ap, struct file *);
61099 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
61100 + break;
61101 + case GR_PSACCT:
61102 + {
61103 + unsigned int wday, cday;
61104 + __u8 whr, chr;
61105 + __u8 wmin, cmin;
61106 + __u8 wsec, csec;
61107 + char cur_tty[64] = { 0 };
61108 + char parent_tty[64] = { 0 };
61109 +
61110 + task = va_arg(ap, struct task_struct *);
61111 + wday = va_arg(ap, unsigned int);
61112 + cday = va_arg(ap, unsigned int);
61113 + whr = va_arg(ap, int);
61114 + chr = va_arg(ap, int);
61115 + wmin = va_arg(ap, int);
61116 + cmin = va_arg(ap, int);
61117 + wsec = va_arg(ap, int);
61118 + csec = va_arg(ap, int);
61119 + ulong1 = va_arg(ap, unsigned long);
61120 + cred = __task_cred(task);
61121 + pcred = __task_cred(task->real_parent);
61122 +
61123 + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task_pid_nr(task), &task->signal->curr_ip, tty_name(task->signal->tty, cur_tty), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), wday, whr, wmin, wsec, cday, chr, cmin, csec, (task->flags & PF_SIGNALED) ? "killed by signal" : "exited", ulong1, gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), &task->real_parent->signal->curr_ip, tty_name(task->real_parent->signal->tty, parent_tty), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
61124 + }
61125 + break;
61126 + default:
61127 + gr_log_middle(audit, msg, ap);
61128 + }
61129 + va_end(ap);
61130 + // these don't need DEFAULTSECARGS printed on the end
61131 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
61132 + gr_log_end(audit, 0);
61133 + else
61134 + gr_log_end(audit, 1);
61135 + END_LOCKS(audit);
61136 +}
61137 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
61138 new file mode 100644
61139 index 0000000..f536303
61140 --- /dev/null
61141 +++ b/grsecurity/grsec_mem.c
61142 @@ -0,0 +1,40 @@
61143 +#include <linux/kernel.h>
61144 +#include <linux/sched.h>
61145 +#include <linux/mm.h>
61146 +#include <linux/mman.h>
61147 +#include <linux/grinternal.h>
61148 +
61149 +void
61150 +gr_handle_ioperm(void)
61151 +{
61152 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
61153 + return;
61154 +}
61155 +
61156 +void
61157 +gr_handle_iopl(void)
61158 +{
61159 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
61160 + return;
61161 +}
61162 +
61163 +void
61164 +gr_handle_mem_readwrite(u64 from, u64 to)
61165 +{
61166 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
61167 + return;
61168 +}
61169 +
61170 +void
61171 +gr_handle_vm86(void)
61172 +{
61173 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
61174 + return;
61175 +}
61176 +
61177 +void
61178 +gr_log_badprocpid(const char *entry)
61179 +{
61180 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
61181 + return;
61182 +}
61183 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
61184 new file mode 100644
61185 index 0000000..2131422
61186 --- /dev/null
61187 +++ b/grsecurity/grsec_mount.c
61188 @@ -0,0 +1,62 @@
61189 +#include <linux/kernel.h>
61190 +#include <linux/sched.h>
61191 +#include <linux/mount.h>
61192 +#include <linux/grsecurity.h>
61193 +#include <linux/grinternal.h>
61194 +
61195 +void
61196 +gr_log_remount(const char *devname, const int retval)
61197 +{
61198 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61199 + if (grsec_enable_mount && (retval >= 0))
61200 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
61201 +#endif
61202 + return;
61203 +}
61204 +
61205 +void
61206 +gr_log_unmount(const char *devname, const int retval)
61207 +{
61208 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61209 + if (grsec_enable_mount && (retval >= 0))
61210 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
61211 +#endif
61212 + return;
61213 +}
61214 +
61215 +void
61216 +gr_log_mount(const char *from, const char *to, const int retval)
61217 +{
61218 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61219 + if (grsec_enable_mount && (retval >= 0))
61220 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
61221 +#endif
61222 + return;
61223 +}
61224 +
61225 +int
61226 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
61227 +{
61228 +#ifdef CONFIG_GRKERNSEC_ROFS
61229 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
61230 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
61231 + return -EPERM;
61232 + } else
61233 + return 0;
61234 +#endif
61235 + return 0;
61236 +}
61237 +
61238 +int
61239 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
61240 +{
61241 +#ifdef CONFIG_GRKERNSEC_ROFS
61242 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
61243 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
61244 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
61245 + return -EPERM;
61246 + } else
61247 + return 0;
61248 +#endif
61249 + return 0;
61250 +}
61251 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
61252 new file mode 100644
61253 index 0000000..a3b12a0
61254 --- /dev/null
61255 +++ b/grsecurity/grsec_pax.c
61256 @@ -0,0 +1,36 @@
61257 +#include <linux/kernel.h>
61258 +#include <linux/sched.h>
61259 +#include <linux/mm.h>
61260 +#include <linux/file.h>
61261 +#include <linux/grinternal.h>
61262 +#include <linux/grsecurity.h>
61263 +
61264 +void
61265 +gr_log_textrel(struct vm_area_struct * vma)
61266 +{
61267 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
61268 + if (grsec_enable_audit_textrel)
61269 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
61270 +#endif
61271 + return;
61272 +}
61273 +
61274 +void
61275 +gr_log_rwxmmap(struct file *file)
61276 +{
61277 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61278 + if (grsec_enable_log_rwxmaps)
61279 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
61280 +#endif
61281 + return;
61282 +}
61283 +
61284 +void
61285 +gr_log_rwxmprotect(struct file *file)
61286 +{
61287 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61288 + if (grsec_enable_log_rwxmaps)
61289 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
61290 +#endif
61291 + return;
61292 +}
61293 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
61294 new file mode 100644
61295 index 0000000..f7f29aa
61296 --- /dev/null
61297 +++ b/grsecurity/grsec_ptrace.c
61298 @@ -0,0 +1,30 @@
61299 +#include <linux/kernel.h>
61300 +#include <linux/sched.h>
61301 +#include <linux/grinternal.h>
61302 +#include <linux/security.h>
61303 +
61304 +void
61305 +gr_audit_ptrace(struct task_struct *task)
61306 +{
61307 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
61308 + if (grsec_enable_audit_ptrace)
61309 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
61310 +#endif
61311 + return;
61312 +}
61313 +
61314 +int
61315 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
61316 +{
61317 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
61318 + const struct dentry *dentry = file->f_path.dentry;
61319 + const struct vfsmount *mnt = file->f_path.mnt;
61320 +
61321 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
61322 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
61323 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
61324 + return -EACCES;
61325 + }
61326 +#endif
61327 + return 0;
61328 +}
61329 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
61330 new file mode 100644
61331 index 0000000..5c00416
61332 --- /dev/null
61333 +++ b/grsecurity/grsec_sig.c
61334 @@ -0,0 +1,222 @@
61335 +#include <linux/kernel.h>
61336 +#include <linux/sched.h>
61337 +#include <linux/delay.h>
61338 +#include <linux/grsecurity.h>
61339 +#include <linux/grinternal.h>
61340 +#include <linux/hardirq.h>
61341 +
61342 +char *signames[] = {
61343 + [SIGSEGV] = "Segmentation fault",
61344 + [SIGILL] = "Illegal instruction",
61345 + [SIGABRT] = "Abort",
61346 + [SIGBUS] = "Invalid alignment/Bus error"
61347 +};
61348 +
61349 +void
61350 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
61351 +{
61352 +#ifdef CONFIG_GRKERNSEC_SIGNAL
61353 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
61354 + (sig == SIGABRT) || (sig == SIGBUS))) {
61355 + if (t->pid == current->pid) {
61356 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
61357 + } else {
61358 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
61359 + }
61360 + }
61361 +#endif
61362 + return;
61363 +}
61364 +
61365 +int
61366 +gr_handle_signal(const struct task_struct *p, const int sig)
61367 +{
61368 +#ifdef CONFIG_GRKERNSEC
61369 + /* ignore the 0 signal for protected task checks */
61370 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
61371 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
61372 + return -EPERM;
61373 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
61374 + return -EPERM;
61375 + }
61376 +#endif
61377 + return 0;
61378 +}
61379 +
61380 +#ifdef CONFIG_GRKERNSEC
61381 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
61382 +
61383 +int gr_fake_force_sig(int sig, struct task_struct *t)
61384 +{
61385 + unsigned long int flags;
61386 + int ret, blocked, ignored;
61387 + struct k_sigaction *action;
61388 +
61389 + spin_lock_irqsave(&t->sighand->siglock, flags);
61390 + action = &t->sighand->action[sig-1];
61391 + ignored = action->sa.sa_handler == SIG_IGN;
61392 + blocked = sigismember(&t->blocked, sig);
61393 + if (blocked || ignored) {
61394 + action->sa.sa_handler = SIG_DFL;
61395 + if (blocked) {
61396 + sigdelset(&t->blocked, sig);
61397 + recalc_sigpending_and_wake(t);
61398 + }
61399 + }
61400 + if (action->sa.sa_handler == SIG_DFL)
61401 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
61402 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
61403 +
61404 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
61405 +
61406 + return ret;
61407 +}
61408 +#endif
61409 +
61410 +#ifdef CONFIG_GRKERNSEC_BRUTE
61411 +#define GR_USER_BAN_TIME (15 * 60)
61412 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
61413 +
61414 +static int __get_dumpable(unsigned long mm_flags)
61415 +{
61416 + int ret;
61417 +
61418 + ret = mm_flags & MMF_DUMPABLE_MASK;
61419 + return (ret >= 2) ? 2 : ret;
61420 +}
61421 +#endif
61422 +
61423 +void gr_handle_brute_attach(unsigned long mm_flags)
61424 +{
61425 +#ifdef CONFIG_GRKERNSEC_BRUTE
61426 + struct task_struct *p = current;
61427 + kuid_t uid = GLOBAL_ROOT_UID;
61428 + int daemon = 0;
61429 +
61430 + if (!grsec_enable_brute)
61431 + return;
61432 +
61433 + rcu_read_lock();
61434 + read_lock(&tasklist_lock);
61435 + read_lock(&grsec_exec_file_lock);
61436 + if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
61437 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
61438 + p->real_parent->brute = 1;
61439 + daemon = 1;
61440 + } else {
61441 + const struct cred *cred = __task_cred(p), *cred2;
61442 + struct task_struct *tsk, *tsk2;
61443 +
61444 + if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
61445 + struct user_struct *user;
61446 +
61447 + uid = cred->uid;
61448 +
61449 + /* this is put upon execution past expiration */
61450 + user = find_user(uid);
61451 + if (user == NULL)
61452 + goto unlock;
61453 + user->banned = 1;
61454 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
61455 + if (user->ban_expires == ~0UL)
61456 + user->ban_expires--;
61457 +
61458 + do_each_thread(tsk2, tsk) {
61459 + cred2 = __task_cred(tsk);
61460 + if (tsk != p && uid_eq(cred2->uid, uid))
61461 + gr_fake_force_sig(SIGKILL, tsk);
61462 + } while_each_thread(tsk2, tsk);
61463 + }
61464 + }
61465 +unlock:
61466 + read_unlock(&grsec_exec_file_lock);
61467 + read_unlock(&tasklist_lock);
61468 + rcu_read_unlock();
61469 +
61470 + if (!uid_eq(uid, GLOBAL_ROOT_UID))
61471 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
61472 + from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
61473 + else if (daemon)
61474 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
61475 +
61476 +#endif
61477 + return;
61478 +}
61479 +
61480 +void gr_handle_brute_check(void)
61481 +{
61482 +#ifdef CONFIG_GRKERNSEC_BRUTE
61483 + struct task_struct *p = current;
61484 +
61485 + if (unlikely(p->brute)) {
61486 + if (!grsec_enable_brute)
61487 + p->brute = 0;
61488 + else if (time_before(get_seconds(), p->brute_expires))
61489 + msleep(30 * 1000);
61490 + }
61491 +#endif
61492 + return;
61493 +}
61494 +
61495 +void gr_handle_kernel_exploit(void)
61496 +{
61497 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
61498 + const struct cred *cred;
61499 + struct task_struct *tsk, *tsk2;
61500 + struct user_struct *user;
61501 + kuid_t uid;
61502 +
61503 + if (in_irq() || in_serving_softirq() || in_nmi())
61504 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
61505 +
61506 + uid = current_uid();
61507 +
61508 + if (uid_eq(uid, GLOBAL_ROOT_UID))
61509 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
61510 + else {
61511 + /* kill all the processes of this user, hold a reference
61512 + to their creds struct, and prevent them from creating
61513 + another process until system reset
61514 + */
61515 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
61516 + from_kuid_munged(&init_user_ns, uid));
61517 + /* we intentionally leak this ref */
61518 + user = get_uid(current->cred->user);
61519 + if (user) {
61520 + user->banned = 1;
61521 + user->ban_expires = ~0UL;
61522 + }
61523 +
61524 + read_lock(&tasklist_lock);
61525 + do_each_thread(tsk2, tsk) {
61526 + cred = __task_cred(tsk);
61527 + if (uid_eq(cred->uid, uid))
61528 + gr_fake_force_sig(SIGKILL, tsk);
61529 + } while_each_thread(tsk2, tsk);
61530 + read_unlock(&tasklist_lock);
61531 + }
61532 +#endif
61533 +}
61534 +
61535 +int __gr_process_user_ban(struct user_struct *user)
61536 +{
61537 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
61538 + if (unlikely(user->banned)) {
61539 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
61540 + user->banned = 0;
61541 + user->ban_expires = 0;
61542 + free_uid(user);
61543 + } else
61544 + return -EPERM;
61545 + }
61546 +#endif
61547 + return 0;
61548 +}
61549 +
61550 +int gr_process_user_ban(void)
61551 +{
61552 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
61553 + return __gr_process_user_ban(current->cred->user);
61554 +#endif
61555 + return 0;
61556 +}
61557 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
61558 new file mode 100644
61559 index 0000000..4030d57
61560 --- /dev/null
61561 +++ b/grsecurity/grsec_sock.c
61562 @@ -0,0 +1,244 @@
61563 +#include <linux/kernel.h>
61564 +#include <linux/module.h>
61565 +#include <linux/sched.h>
61566 +#include <linux/file.h>
61567 +#include <linux/net.h>
61568 +#include <linux/in.h>
61569 +#include <linux/ip.h>
61570 +#include <net/sock.h>
61571 +#include <net/inet_sock.h>
61572 +#include <linux/grsecurity.h>
61573 +#include <linux/grinternal.h>
61574 +#include <linux/gracl.h>
61575 +
61576 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
61577 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
61578 +
61579 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
61580 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
61581 +
61582 +#ifdef CONFIG_UNIX_MODULE
61583 +EXPORT_SYMBOL(gr_acl_handle_unix);
61584 +EXPORT_SYMBOL(gr_acl_handle_mknod);
61585 +EXPORT_SYMBOL(gr_handle_chroot_unix);
61586 +EXPORT_SYMBOL(gr_handle_create);
61587 +#endif
61588 +
61589 +#ifdef CONFIG_GRKERNSEC
61590 +#define gr_conn_table_size 32749
61591 +struct conn_table_entry {
61592 + struct conn_table_entry *next;
61593 + struct signal_struct *sig;
61594 +};
61595 +
61596 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
61597 +DEFINE_SPINLOCK(gr_conn_table_lock);
61598 +
61599 +extern const char * gr_socktype_to_name(unsigned char type);
61600 +extern const char * gr_proto_to_name(unsigned char proto);
61601 +extern const char * gr_sockfamily_to_name(unsigned char family);
61602 +
61603 +static __inline__ int
61604 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
61605 +{
61606 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
61607 +}
61608 +
61609 +static __inline__ int
61610 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
61611 + __u16 sport, __u16 dport)
61612 +{
61613 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
61614 + sig->gr_sport == sport && sig->gr_dport == dport))
61615 + return 1;
61616 + else
61617 + return 0;
61618 +}
61619 +
61620 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
61621 +{
61622 + struct conn_table_entry **match;
61623 + unsigned int index;
61624 +
61625 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
61626 + sig->gr_sport, sig->gr_dport,
61627 + gr_conn_table_size);
61628 +
61629 + newent->sig = sig;
61630 +
61631 + match = &gr_conn_table[index];
61632 + newent->next = *match;
61633 + *match = newent;
61634 +
61635 + return;
61636 +}
61637 +
61638 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
61639 +{
61640 + struct conn_table_entry *match, *last = NULL;
61641 + unsigned int index;
61642 +
61643 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
61644 + sig->gr_sport, sig->gr_dport,
61645 + gr_conn_table_size);
61646 +
61647 + match = gr_conn_table[index];
61648 + while (match && !conn_match(match->sig,
61649 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
61650 + sig->gr_dport)) {
61651 + last = match;
61652 + match = match->next;
61653 + }
61654 +
61655 + if (match) {
61656 + if (last)
61657 + last->next = match->next;
61658 + else
61659 + gr_conn_table[index] = NULL;
61660 + kfree(match);
61661 + }
61662 +
61663 + return;
61664 +}
61665 +
61666 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
61667 + __u16 sport, __u16 dport)
61668 +{
61669 + struct conn_table_entry *match;
61670 + unsigned int index;
61671 +
61672 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
61673 +
61674 + match = gr_conn_table[index];
61675 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
61676 + match = match->next;
61677 +
61678 + if (match)
61679 + return match->sig;
61680 + else
61681 + return NULL;
61682 +}
61683 +
61684 +#endif
61685 +
61686 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
61687 +{
61688 +#ifdef CONFIG_GRKERNSEC
61689 + struct signal_struct *sig = task->signal;
61690 + struct conn_table_entry *newent;
61691 +
61692 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
61693 + if (newent == NULL)
61694 + return;
61695 + /* no bh lock needed since we are called with bh disabled */
61696 + spin_lock(&gr_conn_table_lock);
61697 + gr_del_task_from_ip_table_nolock(sig);
61698 + sig->gr_saddr = inet->inet_rcv_saddr;
61699 + sig->gr_daddr = inet->inet_daddr;
61700 + sig->gr_sport = inet->inet_sport;
61701 + sig->gr_dport = inet->inet_dport;
61702 + gr_add_to_task_ip_table_nolock(sig, newent);
61703 + spin_unlock(&gr_conn_table_lock);
61704 +#endif
61705 + return;
61706 +}
61707 +
61708 +void gr_del_task_from_ip_table(struct task_struct *task)
61709 +{
61710 +#ifdef CONFIG_GRKERNSEC
61711 + spin_lock_bh(&gr_conn_table_lock);
61712 + gr_del_task_from_ip_table_nolock(task->signal);
61713 + spin_unlock_bh(&gr_conn_table_lock);
61714 +#endif
61715 + return;
61716 +}
61717 +
61718 +void
61719 +gr_attach_curr_ip(const struct sock *sk)
61720 +{
61721 +#ifdef CONFIG_GRKERNSEC
61722 + struct signal_struct *p, *set;
61723 + const struct inet_sock *inet = inet_sk(sk);
61724 +
61725 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
61726 + return;
61727 +
61728 + set = current->signal;
61729 +
61730 + spin_lock_bh(&gr_conn_table_lock);
61731 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
61732 + inet->inet_dport, inet->inet_sport);
61733 + if (unlikely(p != NULL)) {
61734 + set->curr_ip = p->curr_ip;
61735 + set->used_accept = 1;
61736 + gr_del_task_from_ip_table_nolock(p);
61737 + spin_unlock_bh(&gr_conn_table_lock);
61738 + return;
61739 + }
61740 + spin_unlock_bh(&gr_conn_table_lock);
61741 +
61742 + set->curr_ip = inet->inet_daddr;
61743 + set->used_accept = 1;
61744 +#endif
61745 + return;
61746 +}
61747 +
61748 +int
61749 +gr_handle_sock_all(const int family, const int type, const int protocol)
61750 +{
61751 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
61752 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
61753 + (family != AF_UNIX)) {
61754 + if (family == AF_INET)
61755 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
61756 + else
61757 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
61758 + return -EACCES;
61759 + }
61760 +#endif
61761 + return 0;
61762 +}
61763 +
61764 +int
61765 +gr_handle_sock_server(const struct sockaddr *sck)
61766 +{
61767 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61768 + if (grsec_enable_socket_server &&
61769 + in_group_p(grsec_socket_server_gid) &&
61770 + sck && (sck->sa_family != AF_UNIX) &&
61771 + (sck->sa_family != AF_LOCAL)) {
61772 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
61773 + return -EACCES;
61774 + }
61775 +#endif
61776 + return 0;
61777 +}
61778 +
61779 +int
61780 +gr_handle_sock_server_other(const struct sock *sck)
61781 +{
61782 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61783 + if (grsec_enable_socket_server &&
61784 + in_group_p(grsec_socket_server_gid) &&
61785 + sck && (sck->sk_family != AF_UNIX) &&
61786 + (sck->sk_family != AF_LOCAL)) {
61787 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
61788 + return -EACCES;
61789 + }
61790 +#endif
61791 + return 0;
61792 +}
61793 +
61794 +int
61795 +gr_handle_sock_client(const struct sockaddr *sck)
61796 +{
61797 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
61798 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
61799 + sck && (sck->sa_family != AF_UNIX) &&
61800 + (sck->sa_family != AF_LOCAL)) {
61801 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
61802 + return -EACCES;
61803 + }
61804 +#endif
61805 + return 0;
61806 +}
61807 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
61808 new file mode 100644
61809 index 0000000..f55ef0f
61810 --- /dev/null
61811 +++ b/grsecurity/grsec_sysctl.c
61812 @@ -0,0 +1,469 @@
61813 +#include <linux/kernel.h>
61814 +#include <linux/sched.h>
61815 +#include <linux/sysctl.h>
61816 +#include <linux/grsecurity.h>
61817 +#include <linux/grinternal.h>
61818 +
61819 +int
61820 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
61821 +{
61822 +#ifdef CONFIG_GRKERNSEC_SYSCTL
61823 + if (dirname == NULL || name == NULL)
61824 + return 0;
61825 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
61826 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
61827 + return -EACCES;
61828 + }
61829 +#endif
61830 + return 0;
61831 +}
61832 +
61833 +#ifdef CONFIG_GRKERNSEC_ROFS
61834 +static int __maybe_unused one = 1;
61835 +#endif
61836 +
61837 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
61838 +struct ctl_table grsecurity_table[] = {
61839 +#ifdef CONFIG_GRKERNSEC_SYSCTL
61840 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
61841 +#ifdef CONFIG_GRKERNSEC_IO
61842 + {
61843 + .procname = "disable_priv_io",
61844 + .data = &grsec_disable_privio,
61845 + .maxlen = sizeof(int),
61846 + .mode = 0600,
61847 + .proc_handler = &proc_dointvec,
61848 + },
61849 +#endif
61850 +#endif
61851 +#ifdef CONFIG_GRKERNSEC_LINK
61852 + {
61853 + .procname = "linking_restrictions",
61854 + .data = &grsec_enable_link,
61855 + .maxlen = sizeof(int),
61856 + .mode = 0600,
61857 + .proc_handler = &proc_dointvec,
61858 + },
61859 +#endif
61860 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
61861 + {
61862 + .procname = "enforce_symlinksifowner",
61863 + .data = &grsec_enable_symlinkown,
61864 + .maxlen = sizeof(int),
61865 + .mode = 0600,
61866 + .proc_handler = &proc_dointvec,
61867 + },
61868 + {
61869 + .procname = "symlinkown_gid",
61870 + .data = &grsec_symlinkown_gid,
61871 + .maxlen = sizeof(int),
61872 + .mode = 0600,
61873 + .proc_handler = &proc_dointvec,
61874 + },
61875 +#endif
61876 +#ifdef CONFIG_GRKERNSEC_BRUTE
61877 + {
61878 + .procname = "deter_bruteforce",
61879 + .data = &grsec_enable_brute,
61880 + .maxlen = sizeof(int),
61881 + .mode = 0600,
61882 + .proc_handler = &proc_dointvec,
61883 + },
61884 +#endif
61885 +#ifdef CONFIG_GRKERNSEC_FIFO
61886 + {
61887 + .procname = "fifo_restrictions",
61888 + .data = &grsec_enable_fifo,
61889 + .maxlen = sizeof(int),
61890 + .mode = 0600,
61891 + .proc_handler = &proc_dointvec,
61892 + },
61893 +#endif
61894 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
61895 + {
61896 + .procname = "ptrace_readexec",
61897 + .data = &grsec_enable_ptrace_readexec,
61898 + .maxlen = sizeof(int),
61899 + .mode = 0600,
61900 + .proc_handler = &proc_dointvec,
61901 + },
61902 +#endif
61903 +#ifdef CONFIG_GRKERNSEC_SETXID
61904 + {
61905 + .procname = "consistent_setxid",
61906 + .data = &grsec_enable_setxid,
61907 + .maxlen = sizeof(int),
61908 + .mode = 0600,
61909 + .proc_handler = &proc_dointvec,
61910 + },
61911 +#endif
61912 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
61913 + {
61914 + .procname = "ip_blackhole",
61915 + .data = &grsec_enable_blackhole,
61916 + .maxlen = sizeof(int),
61917 + .mode = 0600,
61918 + .proc_handler = &proc_dointvec,
61919 + },
61920 + {
61921 + .procname = "lastack_retries",
61922 + .data = &grsec_lastack_retries,
61923 + .maxlen = sizeof(int),
61924 + .mode = 0600,
61925 + .proc_handler = &proc_dointvec,
61926 + },
61927 +#endif
61928 +#ifdef CONFIG_GRKERNSEC_EXECLOG
61929 + {
61930 + .procname = "exec_logging",
61931 + .data = &grsec_enable_execlog,
61932 + .maxlen = sizeof(int),
61933 + .mode = 0600,
61934 + .proc_handler = &proc_dointvec,
61935 + },
61936 +#endif
61937 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61938 + {
61939 + .procname = "rwxmap_logging",
61940 + .data = &grsec_enable_log_rwxmaps,
61941 + .maxlen = sizeof(int),
61942 + .mode = 0600,
61943 + .proc_handler = &proc_dointvec,
61944 + },
61945 +#endif
61946 +#ifdef CONFIG_GRKERNSEC_SIGNAL
61947 + {
61948 + .procname = "signal_logging",
61949 + .data = &grsec_enable_signal,
61950 + .maxlen = sizeof(int),
61951 + .mode = 0600,
61952 + .proc_handler = &proc_dointvec,
61953 + },
61954 +#endif
61955 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
61956 + {
61957 + .procname = "forkfail_logging",
61958 + .data = &grsec_enable_forkfail,
61959 + .maxlen = sizeof(int),
61960 + .mode = 0600,
61961 + .proc_handler = &proc_dointvec,
61962 + },
61963 +#endif
61964 +#ifdef CONFIG_GRKERNSEC_TIME
61965 + {
61966 + .procname = "timechange_logging",
61967 + .data = &grsec_enable_time,
61968 + .maxlen = sizeof(int),
61969 + .mode = 0600,
61970 + .proc_handler = &proc_dointvec,
61971 + },
61972 +#endif
61973 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
61974 + {
61975 + .procname = "chroot_deny_shmat",
61976 + .data = &grsec_enable_chroot_shmat,
61977 + .maxlen = sizeof(int),
61978 + .mode = 0600,
61979 + .proc_handler = &proc_dointvec,
61980 + },
61981 +#endif
61982 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
61983 + {
61984 + .procname = "chroot_deny_unix",
61985 + .data = &grsec_enable_chroot_unix,
61986 + .maxlen = sizeof(int),
61987 + .mode = 0600,
61988 + .proc_handler = &proc_dointvec,
61989 + },
61990 +#endif
61991 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
61992 + {
61993 + .procname = "chroot_deny_mount",
61994 + .data = &grsec_enable_chroot_mount,
61995 + .maxlen = sizeof(int),
61996 + .mode = 0600,
61997 + .proc_handler = &proc_dointvec,
61998 + },
61999 +#endif
62000 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
62001 + {
62002 + .procname = "chroot_deny_fchdir",
62003 + .data = &grsec_enable_chroot_fchdir,
62004 + .maxlen = sizeof(int),
62005 + .mode = 0600,
62006 + .proc_handler = &proc_dointvec,
62007 + },
62008 +#endif
62009 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
62010 + {
62011 + .procname = "chroot_deny_chroot",
62012 + .data = &grsec_enable_chroot_double,
62013 + .maxlen = sizeof(int),
62014 + .mode = 0600,
62015 + .proc_handler = &proc_dointvec,
62016 + },
62017 +#endif
62018 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
62019 + {
62020 + .procname = "chroot_deny_pivot",
62021 + .data = &grsec_enable_chroot_pivot,
62022 + .maxlen = sizeof(int),
62023 + .mode = 0600,
62024 + .proc_handler = &proc_dointvec,
62025 + },
62026 +#endif
62027 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
62028 + {
62029 + .procname = "chroot_enforce_chdir",
62030 + .data = &grsec_enable_chroot_chdir,
62031 + .maxlen = sizeof(int),
62032 + .mode = 0600,
62033 + .proc_handler = &proc_dointvec,
62034 + },
62035 +#endif
62036 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
62037 + {
62038 + .procname = "chroot_deny_chmod",
62039 + .data = &grsec_enable_chroot_chmod,
62040 + .maxlen = sizeof(int),
62041 + .mode = 0600,
62042 + .proc_handler = &proc_dointvec,
62043 + },
62044 +#endif
62045 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
62046 + {
62047 + .procname = "chroot_deny_mknod",
62048 + .data = &grsec_enable_chroot_mknod,
62049 + .maxlen = sizeof(int),
62050 + .mode = 0600,
62051 + .proc_handler = &proc_dointvec,
62052 + },
62053 +#endif
62054 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
62055 + {
62056 + .procname = "chroot_restrict_nice",
62057 + .data = &grsec_enable_chroot_nice,
62058 + .maxlen = sizeof(int),
62059 + .mode = 0600,
62060 + .proc_handler = &proc_dointvec,
62061 + },
62062 +#endif
62063 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
62064 + {
62065 + .procname = "chroot_execlog",
62066 + .data = &grsec_enable_chroot_execlog,
62067 + .maxlen = sizeof(int),
62068 + .mode = 0600,
62069 + .proc_handler = &proc_dointvec,
62070 + },
62071 +#endif
62072 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62073 + {
62074 + .procname = "chroot_caps",
62075 + .data = &grsec_enable_chroot_caps,
62076 + .maxlen = sizeof(int),
62077 + .mode = 0600,
62078 + .proc_handler = &proc_dointvec,
62079 + },
62080 +#endif
62081 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
62082 + {
62083 + .procname = "chroot_deny_sysctl",
62084 + .data = &grsec_enable_chroot_sysctl,
62085 + .maxlen = sizeof(int),
62086 + .mode = 0600,
62087 + .proc_handler = &proc_dointvec,
62088 + },
62089 +#endif
62090 +#ifdef CONFIG_GRKERNSEC_TPE
62091 + {
62092 + .procname = "tpe",
62093 + .data = &grsec_enable_tpe,
62094 + .maxlen = sizeof(int),
62095 + .mode = 0600,
62096 + .proc_handler = &proc_dointvec,
62097 + },
62098 + {
62099 + .procname = "tpe_gid",
62100 + .data = &grsec_tpe_gid,
62101 + .maxlen = sizeof(int),
62102 + .mode = 0600,
62103 + .proc_handler = &proc_dointvec,
62104 + },
62105 +#endif
62106 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
62107 + {
62108 + .procname = "tpe_invert",
62109 + .data = &grsec_enable_tpe_invert,
62110 + .maxlen = sizeof(int),
62111 + .mode = 0600,
62112 + .proc_handler = &proc_dointvec,
62113 + },
62114 +#endif
62115 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
62116 + {
62117 + .procname = "tpe_restrict_all",
62118 + .data = &grsec_enable_tpe_all,
62119 + .maxlen = sizeof(int),
62120 + .mode = 0600,
62121 + .proc_handler = &proc_dointvec,
62122 + },
62123 +#endif
62124 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
62125 + {
62126 + .procname = "socket_all",
62127 + .data = &grsec_enable_socket_all,
62128 + .maxlen = sizeof(int),
62129 + .mode = 0600,
62130 + .proc_handler = &proc_dointvec,
62131 + },
62132 + {
62133 + .procname = "socket_all_gid",
62134 + .data = &grsec_socket_all_gid,
62135 + .maxlen = sizeof(int),
62136 + .mode = 0600,
62137 + .proc_handler = &proc_dointvec,
62138 + },
62139 +#endif
62140 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
62141 + {
62142 + .procname = "socket_client",
62143 + .data = &grsec_enable_socket_client,
62144 + .maxlen = sizeof(int),
62145 + .mode = 0600,
62146 + .proc_handler = &proc_dointvec,
62147 + },
62148 + {
62149 + .procname = "socket_client_gid",
62150 + .data = &grsec_socket_client_gid,
62151 + .maxlen = sizeof(int),
62152 + .mode = 0600,
62153 + .proc_handler = &proc_dointvec,
62154 + },
62155 +#endif
62156 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
62157 + {
62158 + .procname = "socket_server",
62159 + .data = &grsec_enable_socket_server,
62160 + .maxlen = sizeof(int),
62161 + .mode = 0600,
62162 + .proc_handler = &proc_dointvec,
62163 + },
62164 + {
62165 + .procname = "socket_server_gid",
62166 + .data = &grsec_socket_server_gid,
62167 + .maxlen = sizeof(int),
62168 + .mode = 0600,
62169 + .proc_handler = &proc_dointvec,
62170 + },
62171 +#endif
62172 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
62173 + {
62174 + .procname = "audit_group",
62175 + .data = &grsec_enable_group,
62176 + .maxlen = sizeof(int),
62177 + .mode = 0600,
62178 + .proc_handler = &proc_dointvec,
62179 + },
62180 + {
62181 + .procname = "audit_gid",
62182 + .data = &grsec_audit_gid,
62183 + .maxlen = sizeof(int),
62184 + .mode = 0600,
62185 + .proc_handler = &proc_dointvec,
62186 + },
62187 +#endif
62188 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
62189 + {
62190 + .procname = "audit_chdir",
62191 + .data = &grsec_enable_chdir,
62192 + .maxlen = sizeof(int),
62193 + .mode = 0600,
62194 + .proc_handler = &proc_dointvec,
62195 + },
62196 +#endif
62197 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
62198 + {
62199 + .procname = "audit_mount",
62200 + .data = &grsec_enable_mount,
62201 + .maxlen = sizeof(int),
62202 + .mode = 0600,
62203 + .proc_handler = &proc_dointvec,
62204 + },
62205 +#endif
62206 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
62207 + {
62208 + .procname = "audit_textrel",
62209 + .data = &grsec_enable_audit_textrel,
62210 + .maxlen = sizeof(int),
62211 + .mode = 0600,
62212 + .proc_handler = &proc_dointvec,
62213 + },
62214 +#endif
62215 +#ifdef CONFIG_GRKERNSEC_DMESG
62216 + {
62217 + .procname = "dmesg",
62218 + .data = &grsec_enable_dmesg,
62219 + .maxlen = sizeof(int),
62220 + .mode = 0600,
62221 + .proc_handler = &proc_dointvec,
62222 + },
62223 +#endif
62224 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62225 + {
62226 + .procname = "chroot_findtask",
62227 + .data = &grsec_enable_chroot_findtask,
62228 + .maxlen = sizeof(int),
62229 + .mode = 0600,
62230 + .proc_handler = &proc_dointvec,
62231 + },
62232 +#endif
62233 +#ifdef CONFIG_GRKERNSEC_RESLOG
62234 + {
62235 + .procname = "resource_logging",
62236 + .data = &grsec_resource_logging,
62237 + .maxlen = sizeof(int),
62238 + .mode = 0600,
62239 + .proc_handler = &proc_dointvec,
62240 + },
62241 +#endif
62242 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
62243 + {
62244 + .procname = "audit_ptrace",
62245 + .data = &grsec_enable_audit_ptrace,
62246 + .maxlen = sizeof(int),
62247 + .mode = 0600,
62248 + .proc_handler = &proc_dointvec,
62249 + },
62250 +#endif
62251 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
62252 + {
62253 + .procname = "harden_ptrace",
62254 + .data = &grsec_enable_harden_ptrace,
62255 + .maxlen = sizeof(int),
62256 + .mode = 0600,
62257 + .proc_handler = &proc_dointvec,
62258 + },
62259 +#endif
62260 + {
62261 + .procname = "grsec_lock",
62262 + .data = &grsec_lock,
62263 + .maxlen = sizeof(int),
62264 + .mode = 0600,
62265 + .proc_handler = &proc_dointvec,
62266 + },
62267 +#endif
62268 +#ifdef CONFIG_GRKERNSEC_ROFS
62269 + {
62270 + .procname = "romount_protect",
62271 + .data = &grsec_enable_rofs,
62272 + .maxlen = sizeof(int),
62273 + .mode = 0600,
62274 + .proc_handler = &proc_dointvec_minmax,
62275 + .extra1 = &one,
62276 + .extra2 = &one,
62277 + },
62278 +#endif
62279 + { }
62280 +};
62281 +#endif
62282 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
62283 new file mode 100644
62284 index 0000000..0dc13c3
62285 --- /dev/null
62286 +++ b/grsecurity/grsec_time.c
62287 @@ -0,0 +1,16 @@
62288 +#include <linux/kernel.h>
62289 +#include <linux/sched.h>
62290 +#include <linux/grinternal.h>
62291 +#include <linux/module.h>
62292 +
62293 +void
62294 +gr_log_timechange(void)
62295 +{
62296 +#ifdef CONFIG_GRKERNSEC_TIME
62297 + if (grsec_enable_time)
62298 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
62299 +#endif
62300 + return;
62301 +}
62302 +
62303 +EXPORT_SYMBOL(gr_log_timechange);
62304 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
62305 new file mode 100644
62306 index 0000000..07e0dc0
62307 --- /dev/null
62308 +++ b/grsecurity/grsec_tpe.c
62309 @@ -0,0 +1,73 @@
62310 +#include <linux/kernel.h>
62311 +#include <linux/sched.h>
62312 +#include <linux/file.h>
62313 +#include <linux/fs.h>
62314 +#include <linux/grinternal.h>
62315 +
62316 +extern int gr_acl_tpe_check(void);
62317 +
62318 +int
62319 +gr_tpe_allow(const struct file *file)
62320 +{
62321 +#ifdef CONFIG_GRKERNSEC
62322 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
62323 + const struct cred *cred = current_cred();
62324 + char *msg = NULL;
62325 + char *msg2 = NULL;
62326 +
62327 + // never restrict root
62328 + if (!cred->uid)
62329 + return 1;
62330 +
62331 + if (grsec_enable_tpe) {
62332 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
62333 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
62334 + msg = "not being in trusted group";
62335 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
62336 + msg = "being in untrusted group";
62337 +#else
62338 + if (in_group_p(grsec_tpe_gid))
62339 + msg = "being in untrusted group";
62340 +#endif
62341 + }
62342 + if (!msg && gr_acl_tpe_check())
62343 + msg = "being in untrusted role";
62344 +
62345 + // not in any affected group/role
62346 + if (!msg)
62347 + goto next_check;
62348 +
62349 + if (inode->i_uid)
62350 + msg2 = "file in non-root-owned directory";
62351 + else if (inode->i_mode & S_IWOTH)
62352 + msg2 = "file in world-writable directory";
62353 + else if (inode->i_mode & S_IWGRP)
62354 + msg2 = "file in group-writable directory";
62355 +
62356 + if (msg && msg2) {
62357 + char fullmsg[70] = {0};
62358 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
62359 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
62360 + return 0;
62361 + }
62362 + msg = NULL;
62363 +next_check:
62364 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
62365 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
62366 + return 1;
62367 +
62368 + if (inode->i_uid && (inode->i_uid != cred->uid))
62369 + msg = "directory not owned by user";
62370 + else if (inode->i_mode & S_IWOTH)
62371 + msg = "file in world-writable directory";
62372 + else if (inode->i_mode & S_IWGRP)
62373 + msg = "file in group-writable directory";
62374 +
62375 + if (msg) {
62376 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
62377 + return 0;
62378 + }
62379 +#endif
62380 +#endif
62381 + return 1;
62382 +}
62383 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
62384 new file mode 100644
62385 index 0000000..9f7b1ac
62386 --- /dev/null
62387 +++ b/grsecurity/grsum.c
62388 @@ -0,0 +1,61 @@
62389 +#include <linux/err.h>
62390 +#include <linux/kernel.h>
62391 +#include <linux/sched.h>
62392 +#include <linux/mm.h>
62393 +#include <linux/scatterlist.h>
62394 +#include <linux/crypto.h>
62395 +#include <linux/gracl.h>
62396 +
62397 +
62398 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
62399 +#error "crypto and sha256 must be built into the kernel"
62400 +#endif
62401 +
62402 +int
62403 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
62404 +{
62405 + char *p;
62406 + struct crypto_hash *tfm;
62407 + struct hash_desc desc;
62408 + struct scatterlist sg;
62409 + unsigned char temp_sum[GR_SHA_LEN];
62410 + volatile int retval = 0;
62411 + volatile int dummy = 0;
62412 + unsigned int i;
62413 +
62414 + sg_init_table(&sg, 1);
62415 +
62416 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
62417 + if (IS_ERR(tfm)) {
62418 + /* should never happen, since sha256 should be built in */
62419 + return 1;
62420 + }
62421 +
62422 + desc.tfm = tfm;
62423 + desc.flags = 0;
62424 +
62425 + crypto_hash_init(&desc);
62426 +
62427 + p = salt;
62428 + sg_set_buf(&sg, p, GR_SALT_LEN);
62429 + crypto_hash_update(&desc, &sg, sg.length);
62430 +
62431 + p = entry->pw;
62432 + sg_set_buf(&sg, p, strlen(p));
62433 +
62434 + crypto_hash_update(&desc, &sg, sg.length);
62435 +
62436 + crypto_hash_final(&desc, temp_sum);
62437 +
62438 + memset(entry->pw, 0, GR_PW_LEN);
62439 +
62440 + for (i = 0; i < GR_SHA_LEN; i++)
62441 + if (sum[i] != temp_sum[i])
62442 + retval = 1;
62443 + else
62444 + dummy = 1; // waste a cycle
62445 +
62446 + crypto_free_hash(tfm);
62447 +
62448 + return retval;
62449 +}
62450 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
62451 index 77ff547..181834f 100644
62452 --- a/include/asm-generic/4level-fixup.h
62453 +++ b/include/asm-generic/4level-fixup.h
62454 @@ -13,8 +13,10 @@
62455 #define pmd_alloc(mm, pud, address) \
62456 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
62457 NULL: pmd_offset(pud, address))
62458 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
62459
62460 #define pud_alloc(mm, pgd, address) (pgd)
62461 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
62462 #define pud_offset(pgd, start) (pgd)
62463 #define pud_none(pud) 0
62464 #define pud_bad(pud) 0
62465 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
62466 index b7babf0..04ad282 100644
62467 --- a/include/asm-generic/atomic-long.h
62468 +++ b/include/asm-generic/atomic-long.h
62469 @@ -22,6 +22,12 @@
62470
62471 typedef atomic64_t atomic_long_t;
62472
62473 +#ifdef CONFIG_PAX_REFCOUNT
62474 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
62475 +#else
62476 +typedef atomic64_t atomic_long_unchecked_t;
62477 +#endif
62478 +
62479 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
62480
62481 static inline long atomic_long_read(atomic_long_t *l)
62482 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
62483 return (long)atomic64_read(v);
62484 }
62485
62486 +#ifdef CONFIG_PAX_REFCOUNT
62487 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
62488 +{
62489 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62490 +
62491 + return (long)atomic64_read_unchecked(v);
62492 +}
62493 +#endif
62494 +
62495 static inline void atomic_long_set(atomic_long_t *l, long i)
62496 {
62497 atomic64_t *v = (atomic64_t *)l;
62498 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
62499 atomic64_set(v, i);
62500 }
62501
62502 +#ifdef CONFIG_PAX_REFCOUNT
62503 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
62504 +{
62505 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62506 +
62507 + atomic64_set_unchecked(v, i);
62508 +}
62509 +#endif
62510 +
62511 static inline void atomic_long_inc(atomic_long_t *l)
62512 {
62513 atomic64_t *v = (atomic64_t *)l;
62514 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
62515 atomic64_inc(v);
62516 }
62517
62518 +#ifdef CONFIG_PAX_REFCOUNT
62519 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
62520 +{
62521 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62522 +
62523 + atomic64_inc_unchecked(v);
62524 +}
62525 +#endif
62526 +
62527 static inline void atomic_long_dec(atomic_long_t *l)
62528 {
62529 atomic64_t *v = (atomic64_t *)l;
62530 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
62531 atomic64_dec(v);
62532 }
62533
62534 +#ifdef CONFIG_PAX_REFCOUNT
62535 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
62536 +{
62537 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62538 +
62539 + atomic64_dec_unchecked(v);
62540 +}
62541 +#endif
62542 +
62543 static inline void atomic_long_add(long i, atomic_long_t *l)
62544 {
62545 atomic64_t *v = (atomic64_t *)l;
62546 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
62547 atomic64_add(i, v);
62548 }
62549
62550 +#ifdef CONFIG_PAX_REFCOUNT
62551 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
62552 +{
62553 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62554 +
62555 + atomic64_add_unchecked(i, v);
62556 +}
62557 +#endif
62558 +
62559 static inline void atomic_long_sub(long i, atomic_long_t *l)
62560 {
62561 atomic64_t *v = (atomic64_t *)l;
62562 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
62563 atomic64_sub(i, v);
62564 }
62565
62566 +#ifdef CONFIG_PAX_REFCOUNT
62567 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
62568 +{
62569 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62570 +
62571 + atomic64_sub_unchecked(i, v);
62572 +}
62573 +#endif
62574 +
62575 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
62576 {
62577 atomic64_t *v = (atomic64_t *)l;
62578 @@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
62579 return (long)atomic64_add_return(i, v);
62580 }
62581
62582 +#ifdef CONFIG_PAX_REFCOUNT
62583 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
62584 +{
62585 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62586 +
62587 + return (long)atomic64_add_return_unchecked(i, v);
62588 +}
62589 +#endif
62590 +
62591 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
62592 {
62593 atomic64_t *v = (atomic64_t *)l;
62594 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
62595 return (long)atomic64_inc_return(v);
62596 }
62597
62598 +#ifdef CONFIG_PAX_REFCOUNT
62599 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
62600 +{
62601 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62602 +
62603 + return (long)atomic64_inc_return_unchecked(v);
62604 +}
62605 +#endif
62606 +
62607 static inline long atomic_long_dec_return(atomic_long_t *l)
62608 {
62609 atomic64_t *v = (atomic64_t *)l;
62610 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
62611
62612 typedef atomic_t atomic_long_t;
62613
62614 +#ifdef CONFIG_PAX_REFCOUNT
62615 +typedef atomic_unchecked_t atomic_long_unchecked_t;
62616 +#else
62617 +typedef atomic_t atomic_long_unchecked_t;
62618 +#endif
62619 +
62620 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
62621 static inline long atomic_long_read(atomic_long_t *l)
62622 {
62623 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
62624 return (long)atomic_read(v);
62625 }
62626
62627 +#ifdef CONFIG_PAX_REFCOUNT
62628 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
62629 +{
62630 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62631 +
62632 + return (long)atomic_read_unchecked(v);
62633 +}
62634 +#endif
62635 +
62636 static inline void atomic_long_set(atomic_long_t *l, long i)
62637 {
62638 atomic_t *v = (atomic_t *)l;
62639 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
62640 atomic_set(v, i);
62641 }
62642
62643 +#ifdef CONFIG_PAX_REFCOUNT
62644 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
62645 +{
62646 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62647 +
62648 + atomic_set_unchecked(v, i);
62649 +}
62650 +#endif
62651 +
62652 static inline void atomic_long_inc(atomic_long_t *l)
62653 {
62654 atomic_t *v = (atomic_t *)l;
62655 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
62656 atomic_inc(v);
62657 }
62658
62659 +#ifdef CONFIG_PAX_REFCOUNT
62660 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
62661 +{
62662 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62663 +
62664 + atomic_inc_unchecked(v);
62665 +}
62666 +#endif
62667 +
62668 static inline void atomic_long_dec(atomic_long_t *l)
62669 {
62670 atomic_t *v = (atomic_t *)l;
62671 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
62672 atomic_dec(v);
62673 }
62674
62675 +#ifdef CONFIG_PAX_REFCOUNT
62676 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
62677 +{
62678 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62679 +
62680 + atomic_dec_unchecked(v);
62681 +}
62682 +#endif
62683 +
62684 static inline void atomic_long_add(long i, atomic_long_t *l)
62685 {
62686 atomic_t *v = (atomic_t *)l;
62687 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
62688 atomic_add(i, v);
62689 }
62690
62691 +#ifdef CONFIG_PAX_REFCOUNT
62692 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
62693 +{
62694 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62695 +
62696 + atomic_add_unchecked(i, v);
62697 +}
62698 +#endif
62699 +
62700 static inline void atomic_long_sub(long i, atomic_long_t *l)
62701 {
62702 atomic_t *v = (atomic_t *)l;
62703 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
62704 atomic_sub(i, v);
62705 }
62706
62707 +#ifdef CONFIG_PAX_REFCOUNT
62708 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
62709 +{
62710 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62711 +
62712 + atomic_sub_unchecked(i, v);
62713 +}
62714 +#endif
62715 +
62716 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
62717 {
62718 atomic_t *v = (atomic_t *)l;
62719 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
62720 return (long)atomic_add_return(i, v);
62721 }
62722
62723 +#ifdef CONFIG_PAX_REFCOUNT
62724 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
62725 +{
62726 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62727 +
62728 + return (long)atomic_add_return_unchecked(i, v);
62729 +}
62730 +
62731 +#endif
62732 +
62733 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
62734 {
62735 atomic_t *v = (atomic_t *)l;
62736 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
62737 return (long)atomic_inc_return(v);
62738 }
62739
62740 +#ifdef CONFIG_PAX_REFCOUNT
62741 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
62742 +{
62743 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62744 +
62745 + return (long)atomic_inc_return_unchecked(v);
62746 +}
62747 +#endif
62748 +
62749 static inline long atomic_long_dec_return(atomic_long_t *l)
62750 {
62751 atomic_t *v = (atomic_t *)l;
62752 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
62753
62754 #endif /* BITS_PER_LONG == 64 */
62755
62756 +#ifdef CONFIG_PAX_REFCOUNT
62757 +static inline void pax_refcount_needs_these_functions(void)
62758 +{
62759 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
62760 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
62761 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
62762 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
62763 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
62764 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
62765 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
62766 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
62767 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
62768 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
62769 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
62770 +#ifdef CONFIG_X86
62771 + atomic_clear_mask_unchecked(0, NULL);
62772 + atomic_set_mask_unchecked(0, NULL);
62773 +#endif
62774 +
62775 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
62776 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
62777 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
62778 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
62779 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
62780 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
62781 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
62782 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
62783 +}
62784 +#else
62785 +#define atomic_read_unchecked(v) atomic_read(v)
62786 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
62787 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
62788 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
62789 +#define atomic_inc_unchecked(v) atomic_inc(v)
62790 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
62791 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
62792 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
62793 +#define atomic_dec_unchecked(v) atomic_dec(v)
62794 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
62795 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
62796 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
62797 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
62798 +
62799 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
62800 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
62801 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
62802 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
62803 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
62804 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
62805 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
62806 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
62807 +#endif
62808 +
62809 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
62810 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
62811 index 1ced641..c896ee8 100644
62812 --- a/include/asm-generic/atomic.h
62813 +++ b/include/asm-generic/atomic.h
62814 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
62815 * Atomically clears the bits set in @mask from @v
62816 */
62817 #ifndef atomic_clear_mask
62818 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
62819 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
62820 {
62821 unsigned long flags;
62822
62823 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
62824 index b18ce4f..2ee2843 100644
62825 --- a/include/asm-generic/atomic64.h
62826 +++ b/include/asm-generic/atomic64.h
62827 @@ -16,6 +16,8 @@ typedef struct {
62828 long long counter;
62829 } atomic64_t;
62830
62831 +typedef atomic64_t atomic64_unchecked_t;
62832 +
62833 #define ATOMIC64_INIT(i) { (i) }
62834
62835 extern long long atomic64_read(const atomic64_t *v);
62836 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
62837 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
62838 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
62839
62840 +#define atomic64_read_unchecked(v) atomic64_read(v)
62841 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
62842 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
62843 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
62844 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
62845 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
62846 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
62847 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
62848 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
62849 +
62850 #endif /* _ASM_GENERIC_ATOMIC64_H */
62851 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
62852 index 1bfcfe5..e04c5c9 100644
62853 --- a/include/asm-generic/cache.h
62854 +++ b/include/asm-generic/cache.h
62855 @@ -6,7 +6,7 @@
62856 * cache lines need to provide their own cache.h.
62857 */
62858
62859 -#define L1_CACHE_SHIFT 5
62860 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
62861 +#define L1_CACHE_SHIFT 5UL
62862 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
62863
62864 #endif /* __ASM_GENERIC_CACHE_H */
62865 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
62866 index 0d68a1e..b74a761 100644
62867 --- a/include/asm-generic/emergency-restart.h
62868 +++ b/include/asm-generic/emergency-restart.h
62869 @@ -1,7 +1,7 @@
62870 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
62871 #define _ASM_GENERIC_EMERGENCY_RESTART_H
62872
62873 -static inline void machine_emergency_restart(void)
62874 +static inline __noreturn void machine_emergency_restart(void)
62875 {
62876 machine_restart(NULL);
62877 }
62878 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
62879 index 90f99c7..00ce236 100644
62880 --- a/include/asm-generic/kmap_types.h
62881 +++ b/include/asm-generic/kmap_types.h
62882 @@ -2,9 +2,9 @@
62883 #define _ASM_GENERIC_KMAP_TYPES_H
62884
62885 #ifdef __WITH_KM_FENCE
62886 -# define KM_TYPE_NR 41
62887 +# define KM_TYPE_NR 42
62888 #else
62889 -# define KM_TYPE_NR 20
62890 +# define KM_TYPE_NR 21
62891 #endif
62892
62893 #endif
62894 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
62895 index 9ceb03b..62b0b8f 100644
62896 --- a/include/asm-generic/local.h
62897 +++ b/include/asm-generic/local.h
62898 @@ -23,24 +23,37 @@ typedef struct
62899 atomic_long_t a;
62900 } local_t;
62901
62902 +typedef struct {
62903 + atomic_long_unchecked_t a;
62904 +} local_unchecked_t;
62905 +
62906 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
62907
62908 #define local_read(l) atomic_long_read(&(l)->a)
62909 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
62910 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
62911 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
62912 #define local_inc(l) atomic_long_inc(&(l)->a)
62913 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
62914 #define local_dec(l) atomic_long_dec(&(l)->a)
62915 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
62916 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
62917 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
62918 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
62919 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
62920
62921 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
62922 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
62923 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
62924 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
62925 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
62926 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
62927 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
62928 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
62929 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
62930
62931 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
62932 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
62933 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
62934 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
62935 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
62936 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
62937 index 725612b..9cc513a 100644
62938 --- a/include/asm-generic/pgtable-nopmd.h
62939 +++ b/include/asm-generic/pgtable-nopmd.h
62940 @@ -1,14 +1,19 @@
62941 #ifndef _PGTABLE_NOPMD_H
62942 #define _PGTABLE_NOPMD_H
62943
62944 -#ifndef __ASSEMBLY__
62945 -
62946 #include <asm-generic/pgtable-nopud.h>
62947
62948 -struct mm_struct;
62949 -
62950 #define __PAGETABLE_PMD_FOLDED
62951
62952 +#define PMD_SHIFT PUD_SHIFT
62953 +#define PTRS_PER_PMD 1
62954 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
62955 +#define PMD_MASK (~(PMD_SIZE-1))
62956 +
62957 +#ifndef __ASSEMBLY__
62958 +
62959 +struct mm_struct;
62960 +
62961 /*
62962 * Having the pmd type consist of a pud gets the size right, and allows
62963 * us to conceptually access the pud entry that this pmd is folded into
62964 @@ -16,11 +21,6 @@ struct mm_struct;
62965 */
62966 typedef struct { pud_t pud; } pmd_t;
62967
62968 -#define PMD_SHIFT PUD_SHIFT
62969 -#define PTRS_PER_PMD 1
62970 -#define PMD_SIZE (1UL << PMD_SHIFT)
62971 -#define PMD_MASK (~(PMD_SIZE-1))
62972 -
62973 /*
62974 * The "pud_xxx()" functions here are trivial for a folded two-level
62975 * setup: the pmd is never bad, and a pmd always exists (as it's folded
62976 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
62977 index 810431d..0ec4804f 100644
62978 --- a/include/asm-generic/pgtable-nopud.h
62979 +++ b/include/asm-generic/pgtable-nopud.h
62980 @@ -1,10 +1,15 @@
62981 #ifndef _PGTABLE_NOPUD_H
62982 #define _PGTABLE_NOPUD_H
62983
62984 -#ifndef __ASSEMBLY__
62985 -
62986 #define __PAGETABLE_PUD_FOLDED
62987
62988 +#define PUD_SHIFT PGDIR_SHIFT
62989 +#define PTRS_PER_PUD 1
62990 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
62991 +#define PUD_MASK (~(PUD_SIZE-1))
62992 +
62993 +#ifndef __ASSEMBLY__
62994 +
62995 /*
62996 * Having the pud type consist of a pgd gets the size right, and allows
62997 * us to conceptually access the pgd entry that this pud is folded into
62998 @@ -12,11 +17,6 @@
62999 */
63000 typedef struct { pgd_t pgd; } pud_t;
63001
63002 -#define PUD_SHIFT PGDIR_SHIFT
63003 -#define PTRS_PER_PUD 1
63004 -#define PUD_SIZE (1UL << PUD_SHIFT)
63005 -#define PUD_MASK (~(PUD_SIZE-1))
63006 -
63007 /*
63008 * The "pgd_xxx()" functions here are trivial for a folded two-level
63009 * setup: the pud is never bad, and a pud always exists (as it's folded
63010 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
63011 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
63012
63013 #define pgd_populate(mm, pgd, pud) do { } while (0)
63014 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
63015 /*
63016 * (puds are folded into pgds so this doesn't get actually called,
63017 * but the define is needed for a generic inline function.)
63018 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
63019 index b36ce40..019426d 100644
63020 --- a/include/asm-generic/pgtable.h
63021 +++ b/include/asm-generic/pgtable.h
63022 @@ -554,6 +554,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
63023 #endif
63024 }
63025
63026 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
63027 +static inline unsigned long pax_open_kernel(void) { return 0; }
63028 +#endif
63029 +
63030 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
63031 +static inline unsigned long pax_close_kernel(void) { return 0; }
63032 +#endif
63033 +
63034 #endif /* CONFIG_MMU */
63035
63036 #endif /* !__ASSEMBLY__ */
63037 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
63038 index d1ea7ce..b1ebf2a 100644
63039 --- a/include/asm-generic/vmlinux.lds.h
63040 +++ b/include/asm-generic/vmlinux.lds.h
63041 @@ -218,6 +218,7 @@
63042 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
63043 VMLINUX_SYMBOL(__start_rodata) = .; \
63044 *(.rodata) *(.rodata.*) \
63045 + *(.data..read_only) \
63046 *(__vermagic) /* Kernel version magic */ \
63047 . = ALIGN(8); \
63048 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
63049 @@ -725,17 +726,18 @@
63050 * section in the linker script will go there too. @phdr should have
63051 * a leading colon.
63052 *
63053 - * Note that this macros defines __per_cpu_load as an absolute symbol.
63054 + * Note that this macros defines per_cpu_load as an absolute symbol.
63055 * If there is no need to put the percpu section at a predetermined
63056 * address, use PERCPU_SECTION.
63057 */
63058 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
63059 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
63060 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
63061 + per_cpu_load = .; \
63062 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
63063 - LOAD_OFFSET) { \
63064 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
63065 PERCPU_INPUT(cacheline) \
63066 } phdr \
63067 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
63068 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
63069
63070 /**
63071 * PERCPU_SECTION - define output section for percpu area, simple version
63072 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
63073 index 418d270..bfd2794 100644
63074 --- a/include/crypto/algapi.h
63075 +++ b/include/crypto/algapi.h
63076 @@ -34,7 +34,7 @@ struct crypto_type {
63077 unsigned int maskclear;
63078 unsigned int maskset;
63079 unsigned int tfmsize;
63080 -};
63081 +} __do_const;
63082
63083 struct crypto_instance {
63084 struct crypto_alg alg;
63085 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
63086 index 3fd8280..2b3c415 100644
63087 --- a/include/drm/drmP.h
63088 +++ b/include/drm/drmP.h
63089 @@ -72,6 +72,7 @@
63090 #include <linux/workqueue.h>
63091 #include <linux/poll.h>
63092 #include <asm/pgalloc.h>
63093 +#include <asm/local.h>
63094 #include <drm/drm.h>
63095 #include <drm/drm_sarea.h>
63096
63097 @@ -1068,7 +1069,7 @@ struct drm_device {
63098
63099 /** \name Usage Counters */
63100 /*@{ */
63101 - int open_count; /**< Outstanding files open */
63102 + local_t open_count; /**< Outstanding files open */
63103 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
63104 atomic_t vma_count; /**< Outstanding vma areas open */
63105 int buf_use; /**< Buffers in use -- cannot alloc */
63106 @@ -1079,7 +1080,7 @@ struct drm_device {
63107 /*@{ */
63108 unsigned long counters;
63109 enum drm_stat_type types[15];
63110 - atomic_t counts[15];
63111 + atomic_unchecked_t counts[15];
63112 /*@} */
63113
63114 struct list_head filelist;
63115 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
63116 index e01cc80..6fb6f25 100644
63117 --- a/include/drm/drm_crtc_helper.h
63118 +++ b/include/drm/drm_crtc_helper.h
63119 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
63120 struct drm_connector *connector);
63121 /* disable encoder when not in use - more explicit than dpms off */
63122 void (*disable)(struct drm_encoder *encoder);
63123 -};
63124 +} __no_const;
63125
63126 /**
63127 * drm_connector_helper_funcs - helper operations for connectors
63128 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
63129 index d6d1da4..fdd1ac5 100644
63130 --- a/include/drm/ttm/ttm_memory.h
63131 +++ b/include/drm/ttm/ttm_memory.h
63132 @@ -48,7 +48,7 @@
63133
63134 struct ttm_mem_shrink {
63135 int (*do_shrink) (struct ttm_mem_shrink *);
63136 -};
63137 +} __no_const;
63138
63139 /**
63140 * struct ttm_mem_global - Global memory accounting structure.
63141 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
63142 index 22ef21c..75904ba 100644
63143 --- a/include/linux/atmdev.h
63144 +++ b/include/linux/atmdev.h
63145 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
63146 #endif
63147
63148 struct k_atm_aal_stats {
63149 -#define __HANDLE_ITEM(i) atomic_t i
63150 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
63151 __AAL_STAT_ITEMS
63152 #undef __HANDLE_ITEM
63153 };
63154 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
63155 index de0628e..38f42eb 100644
63156 --- a/include/linux/binfmts.h
63157 +++ b/include/linux/binfmts.h
63158 @@ -75,6 +75,7 @@ struct linux_binfmt {
63159 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
63160 int (*load_shlib)(struct file *);
63161 int (*core_dump)(struct coredump_params *cprm);
63162 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
63163 unsigned long min_coredump; /* minimal dump size */
63164 };
63165
63166 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
63167 index 1756001..ab117ec 100644
63168 --- a/include/linux/blkdev.h
63169 +++ b/include/linux/blkdev.h
63170 @@ -1478,7 +1478,7 @@ struct block_device_operations {
63171 /* this callback is with swap_lock and sometimes page table lock held */
63172 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
63173 struct module *owner;
63174 -};
63175 +} __do_const;
63176
63177 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
63178 unsigned long);
63179 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
63180 index 7c2e030..b72475d 100644
63181 --- a/include/linux/blktrace_api.h
63182 +++ b/include/linux/blktrace_api.h
63183 @@ -23,7 +23,7 @@ struct blk_trace {
63184 struct dentry *dir;
63185 struct dentry *dropped_file;
63186 struct dentry *msg_file;
63187 - atomic_t dropped;
63188 + atomic_unchecked_t dropped;
63189 };
63190
63191 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
63192 diff --git a/include/linux/cache.h b/include/linux/cache.h
63193 index 4c57065..4307975 100644
63194 --- a/include/linux/cache.h
63195 +++ b/include/linux/cache.h
63196 @@ -16,6 +16,10 @@
63197 #define __read_mostly
63198 #endif
63199
63200 +#ifndef __read_only
63201 +#define __read_only __read_mostly
63202 +#endif
63203 +
63204 #ifndef ____cacheline_aligned
63205 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
63206 #endif
63207 diff --git a/include/linux/capability.h b/include/linux/capability.h
63208 index 98503b7..cc36d18 100644
63209 --- a/include/linux/capability.h
63210 +++ b/include/linux/capability.h
63211 @@ -211,8 +211,13 @@ extern bool capable(int cap);
63212 extern bool ns_capable(struct user_namespace *ns, int cap);
63213 extern bool nsown_capable(int cap);
63214 extern bool inode_capable(const struct inode *inode, int cap);
63215 +extern bool capable_nolog(int cap);
63216 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
63217 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
63218
63219 /* audit system wants to get cap info from files as well */
63220 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
63221
63222 +extern int is_privileged_binary(const struct dentry *dentry);
63223 +
63224 #endif /* !_LINUX_CAPABILITY_H */
63225 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
63226 index 8609d57..86e4d79 100644
63227 --- a/include/linux/cdrom.h
63228 +++ b/include/linux/cdrom.h
63229 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
63230
63231 /* driver specifications */
63232 const int capability; /* capability flags */
63233 - int n_minors; /* number of active minor devices */
63234 /* handle uniform packets for scsi type devices (scsi,atapi) */
63235 int (*generic_packet) (struct cdrom_device_info *,
63236 struct packet_command *);
63237 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
63238 index 42e55de..1cd0e66 100644
63239 --- a/include/linux/cleancache.h
63240 +++ b/include/linux/cleancache.h
63241 @@ -31,7 +31,7 @@ struct cleancache_ops {
63242 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
63243 void (*invalidate_inode)(int, struct cleancache_filekey);
63244 void (*invalidate_fs)(int);
63245 -};
63246 +} __no_const;
63247
63248 extern struct cleancache_ops
63249 cleancache_register_ops(struct cleancache_ops *ops);
63250 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
63251 index 412bc6c..c31666e 100644
63252 --- a/include/linux/compiler-gcc4.h
63253 +++ b/include/linux/compiler-gcc4.h
63254 @@ -32,6 +32,21 @@
63255 #define __linktime_error(message) __attribute__((__error__(message)))
63256
63257 #if __GNUC_MINOR__ >= 5
63258 +
63259 +#ifdef CONSTIFY_PLUGIN
63260 +#define __no_const __attribute__((no_const))
63261 +#define __do_const __attribute__((do_const))
63262 +#endif
63263 +
63264 +#ifdef SIZE_OVERFLOW_PLUGIN
63265 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
63266 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
63267 +#endif
63268 +
63269 +#ifdef LATENT_ENTROPY_PLUGIN
63270 +#define __latent_entropy __attribute__((latent_entropy))
63271 +#endif
63272 +
63273 /*
63274 * Mark a position in code as unreachable. This can be used to
63275 * suppress control flow warnings after asm blocks that transfer
63276 @@ -47,6 +62,11 @@
63277 #define __noclone __attribute__((__noclone__))
63278
63279 #endif
63280 +
63281 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
63282 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
63283 +#define __bos0(ptr) __bos((ptr), 0)
63284 +#define __bos1(ptr) __bos((ptr), 1)
63285 #endif
63286
63287 #if __GNUC_MINOR__ >= 6
63288 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
63289 index f430e41..38be90f 100644
63290 --- a/include/linux/compiler.h
63291 +++ b/include/linux/compiler.h
63292 @@ -5,31 +5,62 @@
63293
63294 #ifdef __CHECKER__
63295 # define __user __attribute__((noderef, address_space(1)))
63296 +# define __force_user __force __user
63297 # define __kernel __attribute__((address_space(0)))
63298 +# define __force_kernel __force __kernel
63299 # define __safe __attribute__((safe))
63300 # define __force __attribute__((force))
63301 # define __nocast __attribute__((nocast))
63302 # define __iomem __attribute__((noderef, address_space(2)))
63303 +# define __force_iomem __force __iomem
63304 # define __acquires(x) __attribute__((context(x,0,1)))
63305 # define __releases(x) __attribute__((context(x,1,0)))
63306 # define __acquire(x) __context__(x,1)
63307 # define __release(x) __context__(x,-1)
63308 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
63309 # define __percpu __attribute__((noderef, address_space(3)))
63310 +# define __force_percpu __force __percpu
63311 #ifdef CONFIG_SPARSE_RCU_POINTER
63312 # define __rcu __attribute__((noderef, address_space(4)))
63313 +# define __force_rcu __force __rcu
63314 #else
63315 # define __rcu
63316 +# define __force_rcu
63317 #endif
63318 extern void __chk_user_ptr(const volatile void __user *);
63319 extern void __chk_io_ptr(const volatile void __iomem *);
63320 +#elif defined(CHECKER_PLUGIN)
63321 +//# define __user
63322 +//# define __force_user
63323 +//# define __kernel
63324 +//# define __force_kernel
63325 +# define __safe
63326 +# define __force
63327 +# define __nocast
63328 +# define __iomem
63329 +# define __force_iomem
63330 +# define __chk_user_ptr(x) (void)0
63331 +# define __chk_io_ptr(x) (void)0
63332 +# define __builtin_warning(x, y...) (1)
63333 +# define __acquires(x)
63334 +# define __releases(x)
63335 +# define __acquire(x) (void)0
63336 +# define __release(x) (void)0
63337 +# define __cond_lock(x,c) (c)
63338 +# define __percpu
63339 +# define __force_percpu
63340 +# define __rcu
63341 +# define __force_rcu
63342 #else
63343 # define __user
63344 +# define __force_user
63345 # define __kernel
63346 +# define __force_kernel
63347 # define __safe
63348 # define __force
63349 # define __nocast
63350 # define __iomem
63351 +# define __force_iomem
63352 # define __chk_user_ptr(x) (void)0
63353 # define __chk_io_ptr(x) (void)0
63354 # define __builtin_warning(x, y...) (1)
63355 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
63356 # define __release(x) (void)0
63357 # define __cond_lock(x,c) (c)
63358 # define __percpu
63359 +# define __force_percpu
63360 # define __rcu
63361 +# define __force_rcu
63362 #endif
63363
63364 #ifdef __KERNEL__
63365 @@ -264,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
63366 # define __attribute_const__ /* unimplemented */
63367 #endif
63368
63369 +#ifndef __no_const
63370 +# define __no_const
63371 +#endif
63372 +
63373 +#ifndef __do_const
63374 +# define __do_const
63375 +#endif
63376 +
63377 +#ifndef __size_overflow
63378 +# define __size_overflow(...)
63379 +#endif
63380 +
63381 +#ifndef __intentional_overflow
63382 +# define __intentional_overflow(...)
63383 +#endif
63384 +
63385 +#ifndef __latent_entropy
63386 +# define __latent_entropy
63387 +#endif
63388 +
63389 /*
63390 * Tell gcc if a function is cold. The compiler will assume any path
63391 * directly leading to the call is unlikely.
63392 @@ -273,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
63393 #define __cold
63394 #endif
63395
63396 +#ifndef __alloc_size
63397 +#define __alloc_size(...)
63398 +#endif
63399 +
63400 +#ifndef __bos
63401 +#define __bos(ptr, arg)
63402 +#endif
63403 +
63404 +#ifndef __bos0
63405 +#define __bos0(ptr)
63406 +#endif
63407 +
63408 +#ifndef __bos1
63409 +#define __bos1(ptr)
63410 +#endif
63411 +
63412 /* Simple shorthand for a section definition */
63413 #ifndef __section
63414 # define __section(S) __attribute__ ((__section__(#S)))
63415 @@ -312,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
63416 * use is to mediate communication between process-level code and irq/NMI
63417 * handlers, all running on the same CPU.
63418 */
63419 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
63420 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
63421 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
63422
63423 #endif /* __LINUX_COMPILER_H */
63424 diff --git a/include/linux/cred.h b/include/linux/cred.h
63425 index ebbed2c..908cc2c 100644
63426 --- a/include/linux/cred.h
63427 +++ b/include/linux/cred.h
63428 @@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
63429 static inline void validate_process_creds(void)
63430 {
63431 }
63432 +static inline void validate_task_creds(struct task_struct *task)
63433 +{
63434 +}
63435 #endif
63436
63437 /**
63438 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
63439 index b92eadf..b4ecdc1 100644
63440 --- a/include/linux/crypto.h
63441 +++ b/include/linux/crypto.h
63442 @@ -373,7 +373,7 @@ struct cipher_tfm {
63443 const u8 *key, unsigned int keylen);
63444 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
63445 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
63446 -};
63447 +} __no_const;
63448
63449 struct hash_tfm {
63450 int (*init)(struct hash_desc *desc);
63451 @@ -394,13 +394,13 @@ struct compress_tfm {
63452 int (*cot_decompress)(struct crypto_tfm *tfm,
63453 const u8 *src, unsigned int slen,
63454 u8 *dst, unsigned int *dlen);
63455 -};
63456 +} __no_const;
63457
63458 struct rng_tfm {
63459 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
63460 unsigned int dlen);
63461 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
63462 -};
63463 +} __no_const;
63464
63465 #define crt_ablkcipher crt_u.ablkcipher
63466 #define crt_aead crt_u.aead
63467 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
63468 index 7925bf0..d5143d2 100644
63469 --- a/include/linux/decompress/mm.h
63470 +++ b/include/linux/decompress/mm.h
63471 @@ -77,7 +77,7 @@ static void free(void *where)
63472 * warnings when not needed (indeed large_malloc / large_free are not
63473 * needed by inflate */
63474
63475 -#define malloc(a) kmalloc(a, GFP_KERNEL)
63476 +#define malloc(a) kmalloc((a), GFP_KERNEL)
63477 #define free(a) kfree(a)
63478
63479 #define large_malloc(a) vmalloc(a)
63480 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
63481 index 94af418..b1ca7a2 100644
63482 --- a/include/linux/dma-mapping.h
63483 +++ b/include/linux/dma-mapping.h
63484 @@ -54,7 +54,7 @@ struct dma_map_ops {
63485 u64 (*get_required_mask)(struct device *dev);
63486 #endif
63487 int is_phys;
63488 -};
63489 +} __do_const;
63490
63491 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
63492
63493 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
63494 index d3201e4..8281e63 100644
63495 --- a/include/linux/dmaengine.h
63496 +++ b/include/linux/dmaengine.h
63497 @@ -1018,9 +1018,9 @@ struct dma_pinned_list {
63498 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
63499 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
63500
63501 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
63502 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
63503 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
63504 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
63505 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
63506 struct dma_pinned_list *pinned_list, struct page *page,
63507 unsigned int offset, size_t len);
63508
63509 diff --git a/include/linux/elf.h b/include/linux/elf.h
63510 index 8c9048e..16a4665 100644
63511 --- a/include/linux/elf.h
63512 +++ b/include/linux/elf.h
63513 @@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
63514 #define elf_note elf32_note
63515 #define elf_addr_t Elf32_Off
63516 #define Elf_Half Elf32_Half
63517 +#define elf_dyn Elf32_Dyn
63518
63519 #else
63520
63521 @@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
63522 #define elf_note elf64_note
63523 #define elf_addr_t Elf64_Off
63524 #define Elf_Half Elf64_Half
63525 +#define elf_dyn Elf64_Dyn
63526
63527 #endif
63528
63529 diff --git a/include/linux/filter.h b/include/linux/filter.h
63530 index 24d251f..7afb83d 100644
63531 --- a/include/linux/filter.h
63532 +++ b/include/linux/filter.h
63533 @@ -20,6 +20,7 @@ struct compat_sock_fprog {
63534
63535 struct sk_buff;
63536 struct sock;
63537 +struct bpf_jit_work;
63538
63539 struct sk_filter
63540 {
63541 @@ -27,6 +28,9 @@ struct sk_filter
63542 unsigned int len; /* Number of filter blocks */
63543 unsigned int (*bpf_func)(const struct sk_buff *skb,
63544 const struct sock_filter *filter);
63545 +#ifdef CONFIG_BPF_JIT
63546 + struct bpf_jit_work *work;
63547 +#endif
63548 struct rcu_head rcu;
63549 struct sock_filter insns[0];
63550 };
63551 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
63552 index 3044254..9767f41 100644
63553 --- a/include/linux/frontswap.h
63554 +++ b/include/linux/frontswap.h
63555 @@ -11,7 +11,7 @@ struct frontswap_ops {
63556 int (*load)(unsigned, pgoff_t, struct page *);
63557 void (*invalidate_page)(unsigned, pgoff_t);
63558 void (*invalidate_area)(unsigned);
63559 -};
63560 +} __no_const;
63561
63562 extern bool frontswap_enabled;
63563 extern struct frontswap_ops
63564 diff --git a/include/linux/fs.h b/include/linux/fs.h
63565 index 75fe9a1..8417cac 100644
63566 --- a/include/linux/fs.h
63567 +++ b/include/linux/fs.h
63568 @@ -1543,7 +1543,8 @@ struct file_operations {
63569 int (*setlease)(struct file *, long, struct file_lock **);
63570 long (*fallocate)(struct file *file, int mode, loff_t offset,
63571 loff_t len);
63572 -};
63573 +} __do_const;
63574 +typedef struct file_operations __no_const file_operations_no_const;
63575
63576 struct inode_operations {
63577 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
63578 @@ -2667,4 +2668,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
63579 inode->i_flags |= S_NOSEC;
63580 }
63581
63582 +static inline bool is_sidechannel_device(const struct inode *inode)
63583 +{
63584 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
63585 + umode_t mode = inode->i_mode;
63586 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
63587 +#else
63588 + return false;
63589 +#endif
63590 +}
63591 +
63592 #endif /* _LINUX_FS_H */
63593 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
63594 index 003dc0f..3c4ea97 100644
63595 --- a/include/linux/fs_struct.h
63596 +++ b/include/linux/fs_struct.h
63597 @@ -6,7 +6,7 @@
63598 #include <linux/seqlock.h>
63599
63600 struct fs_struct {
63601 - int users;
63602 + atomic_t users;
63603 spinlock_t lock;
63604 seqcount_t seq;
63605 int umask;
63606 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
63607 index ce31408..b1ad003 100644
63608 --- a/include/linux/fscache-cache.h
63609 +++ b/include/linux/fscache-cache.h
63610 @@ -102,7 +102,7 @@ struct fscache_operation {
63611 fscache_operation_release_t release;
63612 };
63613
63614 -extern atomic_t fscache_op_debug_id;
63615 +extern atomic_unchecked_t fscache_op_debug_id;
63616 extern void fscache_op_work_func(struct work_struct *work);
63617
63618 extern void fscache_enqueue_operation(struct fscache_operation *);
63619 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
63620 {
63621 INIT_WORK(&op->work, fscache_op_work_func);
63622 atomic_set(&op->usage, 1);
63623 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
63624 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
63625 op->processor = processor;
63626 op->release = release;
63627 INIT_LIST_HEAD(&op->pend_link);
63628 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
63629 index 0fbfb46..508eb0d 100644
63630 --- a/include/linux/fsnotify.h
63631 +++ b/include/linux/fsnotify.h
63632 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
63633 struct inode *inode = path->dentry->d_inode;
63634 __u32 mask = FS_ACCESS;
63635
63636 + if (is_sidechannel_device(inode))
63637 + return;
63638 +
63639 if (S_ISDIR(inode->i_mode))
63640 mask |= FS_ISDIR;
63641
63642 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
63643 struct inode *inode = path->dentry->d_inode;
63644 __u32 mask = FS_MODIFY;
63645
63646 + if (is_sidechannel_device(inode))
63647 + return;
63648 +
63649 if (S_ISDIR(inode->i_mode))
63650 mask |= FS_ISDIR;
63651
63652 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
63653 */
63654 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
63655 {
63656 - return kstrdup(name, GFP_KERNEL);
63657 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
63658 }
63659
63660 /*
63661 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
63662 index 642928c..93afe6a 100644
63663 --- a/include/linux/ftrace_event.h
63664 +++ b/include/linux/ftrace_event.h
63665 @@ -266,7 +266,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
63666 extern int trace_add_event_call(struct ftrace_event_call *call);
63667 extern void trace_remove_event_call(struct ftrace_event_call *call);
63668
63669 -#define is_signed_type(type) (((type)(-1)) < 0)
63670 +#define is_signed_type(type) (((type)(-1)) < (type)1)
63671
63672 int trace_set_clr_event(const char *system, const char *event, int set);
63673
63674 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
63675 index 4f440b3..342233a 100644
63676 --- a/include/linux/genhd.h
63677 +++ b/include/linux/genhd.h
63678 @@ -190,7 +190,7 @@ struct gendisk {
63679 struct kobject *slave_dir;
63680
63681 struct timer_rand_state *random;
63682 - atomic_t sync_io; /* RAID */
63683 + atomic_unchecked_t sync_io; /* RAID */
63684 struct disk_events *ev;
63685 #ifdef CONFIG_BLK_DEV_INTEGRITY
63686 struct blk_integrity *integrity;
63687 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
63688 index d0a7967..63c4c47 100644
63689 --- a/include/linux/gfp.h
63690 +++ b/include/linux/gfp.h
63691 @@ -35,6 +35,12 @@ struct vm_area_struct;
63692 #define ___GFP_OTHER_NODE 0x800000u
63693 #define ___GFP_WRITE 0x1000000u
63694
63695 +#ifdef CONFIG_PAX_USERCOPY_SLABS
63696 +#define ___GFP_USERCOPY 0x2000000u
63697 +#else
63698 +#define ___GFP_USERCOPY 0
63699 +#endif
63700 +
63701 /*
63702 * GFP bitmasks..
63703 *
63704 @@ -89,6 +95,7 @@ struct vm_area_struct;
63705 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
63706 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
63707 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
63708 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
63709
63710 /*
63711 * This may seem redundant, but it's a way of annotating false positives vs.
63712 @@ -96,7 +103,7 @@ struct vm_area_struct;
63713 */
63714 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
63715
63716 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
63717 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
63718 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
63719
63720 /* This equals 0, but use constants in case they ever change */
63721 @@ -150,6 +157,8 @@ struct vm_area_struct;
63722 /* 4GB DMA on some platforms */
63723 #define GFP_DMA32 __GFP_DMA32
63724
63725 +#define GFP_USERCOPY __GFP_USERCOPY
63726 +
63727 /* Convert GFP flags to their corresponding migrate type */
63728 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
63729 {
63730 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
63731 new file mode 100644
63732 index 0000000..ebe6d72
63733 --- /dev/null
63734 +++ b/include/linux/gracl.h
63735 @@ -0,0 +1,319 @@
63736 +#ifndef GR_ACL_H
63737 +#define GR_ACL_H
63738 +
63739 +#include <linux/grdefs.h>
63740 +#include <linux/resource.h>
63741 +#include <linux/capability.h>
63742 +#include <linux/dcache.h>
63743 +#include <asm/resource.h>
63744 +
63745 +/* Major status information */
63746 +
63747 +#define GR_VERSION "grsecurity 2.9.1"
63748 +#define GRSECURITY_VERSION 0x2901
63749 +
63750 +enum {
63751 + GR_SHUTDOWN = 0,
63752 + GR_ENABLE = 1,
63753 + GR_SPROLE = 2,
63754 + GR_RELOAD = 3,
63755 + GR_SEGVMOD = 4,
63756 + GR_STATUS = 5,
63757 + GR_UNSPROLE = 6,
63758 + GR_PASSSET = 7,
63759 + GR_SPROLEPAM = 8,
63760 +};
63761 +
63762 +/* Password setup definitions
63763 + * kernel/grhash.c */
63764 +enum {
63765 + GR_PW_LEN = 128,
63766 + GR_SALT_LEN = 16,
63767 + GR_SHA_LEN = 32,
63768 +};
63769 +
63770 +enum {
63771 + GR_SPROLE_LEN = 64,
63772 +};
63773 +
63774 +enum {
63775 + GR_NO_GLOB = 0,
63776 + GR_REG_GLOB,
63777 + GR_CREATE_GLOB
63778 +};
63779 +
63780 +#define GR_NLIMITS 32
63781 +
63782 +/* Begin Data Structures */
63783 +
63784 +struct sprole_pw {
63785 + unsigned char *rolename;
63786 + unsigned char salt[GR_SALT_LEN];
63787 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
63788 +};
63789 +
63790 +struct name_entry {
63791 + __u32 key;
63792 + ino_t inode;
63793 + dev_t device;
63794 + char *name;
63795 + __u16 len;
63796 + __u8 deleted;
63797 + struct name_entry *prev;
63798 + struct name_entry *next;
63799 +};
63800 +
63801 +struct inodev_entry {
63802 + struct name_entry *nentry;
63803 + struct inodev_entry *prev;
63804 + struct inodev_entry *next;
63805 +};
63806 +
63807 +struct acl_role_db {
63808 + struct acl_role_label **r_hash;
63809 + __u32 r_size;
63810 +};
63811 +
63812 +struct inodev_db {
63813 + struct inodev_entry **i_hash;
63814 + __u32 i_size;
63815 +};
63816 +
63817 +struct name_db {
63818 + struct name_entry **n_hash;
63819 + __u32 n_size;
63820 +};
63821 +
63822 +struct crash_uid {
63823 + uid_t uid;
63824 + unsigned long expires;
63825 +};
63826 +
63827 +struct gr_hash_struct {
63828 + void **table;
63829 + void **nametable;
63830 + void *first;
63831 + __u32 table_size;
63832 + __u32 used_size;
63833 + int type;
63834 +};
63835 +
63836 +/* Userspace Grsecurity ACL data structures */
63837 +
63838 +struct acl_subject_label {
63839 + char *filename;
63840 + ino_t inode;
63841 + dev_t device;
63842 + __u32 mode;
63843 + kernel_cap_t cap_mask;
63844 + kernel_cap_t cap_lower;
63845 + kernel_cap_t cap_invert_audit;
63846 +
63847 + struct rlimit res[GR_NLIMITS];
63848 + __u32 resmask;
63849 +
63850 + __u8 user_trans_type;
63851 + __u8 group_trans_type;
63852 + uid_t *user_transitions;
63853 + gid_t *group_transitions;
63854 + __u16 user_trans_num;
63855 + __u16 group_trans_num;
63856 +
63857 + __u32 sock_families[2];
63858 + __u32 ip_proto[8];
63859 + __u32 ip_type;
63860 + struct acl_ip_label **ips;
63861 + __u32 ip_num;
63862 + __u32 inaddr_any_override;
63863 +
63864 + __u32 crashes;
63865 + unsigned long expires;
63866 +
63867 + struct acl_subject_label *parent_subject;
63868 + struct gr_hash_struct *hash;
63869 + struct acl_subject_label *prev;
63870 + struct acl_subject_label *next;
63871 +
63872 + struct acl_object_label **obj_hash;
63873 + __u32 obj_hash_size;
63874 + __u16 pax_flags;
63875 +};
63876 +
63877 +struct role_allowed_ip {
63878 + __u32 addr;
63879 + __u32 netmask;
63880 +
63881 + struct role_allowed_ip *prev;
63882 + struct role_allowed_ip *next;
63883 +};
63884 +
63885 +struct role_transition {
63886 + char *rolename;
63887 +
63888 + struct role_transition *prev;
63889 + struct role_transition *next;
63890 +};
63891 +
63892 +struct acl_role_label {
63893 + char *rolename;
63894 + uid_t uidgid;
63895 + __u16 roletype;
63896 +
63897 + __u16 auth_attempts;
63898 + unsigned long expires;
63899 +
63900 + struct acl_subject_label *root_label;
63901 + struct gr_hash_struct *hash;
63902 +
63903 + struct acl_role_label *prev;
63904 + struct acl_role_label *next;
63905 +
63906 + struct role_transition *transitions;
63907 + struct role_allowed_ip *allowed_ips;
63908 + uid_t *domain_children;
63909 + __u16 domain_child_num;
63910 +
63911 + umode_t umask;
63912 +
63913 + struct acl_subject_label **subj_hash;
63914 + __u32 subj_hash_size;
63915 +};
63916 +
63917 +struct user_acl_role_db {
63918 + struct acl_role_label **r_table;
63919 + __u32 num_pointers; /* Number of allocations to track */
63920 + __u32 num_roles; /* Number of roles */
63921 + __u32 num_domain_children; /* Number of domain children */
63922 + __u32 num_subjects; /* Number of subjects */
63923 + __u32 num_objects; /* Number of objects */
63924 +};
63925 +
63926 +struct acl_object_label {
63927 + char *filename;
63928 + ino_t inode;
63929 + dev_t device;
63930 + __u32 mode;
63931 +
63932 + struct acl_subject_label *nested;
63933 + struct acl_object_label *globbed;
63934 +
63935 + /* next two structures not used */
63936 +
63937 + struct acl_object_label *prev;
63938 + struct acl_object_label *next;
63939 +};
63940 +
63941 +struct acl_ip_label {
63942 + char *iface;
63943 + __u32 addr;
63944 + __u32 netmask;
63945 + __u16 low, high;
63946 + __u8 mode;
63947 + __u32 type;
63948 + __u32 proto[8];
63949 +
63950 + /* next two structures not used */
63951 +
63952 + struct acl_ip_label *prev;
63953 + struct acl_ip_label *next;
63954 +};
63955 +
63956 +struct gr_arg {
63957 + struct user_acl_role_db role_db;
63958 + unsigned char pw[GR_PW_LEN];
63959 + unsigned char salt[GR_SALT_LEN];
63960 + unsigned char sum[GR_SHA_LEN];
63961 + unsigned char sp_role[GR_SPROLE_LEN];
63962 + struct sprole_pw *sprole_pws;
63963 + dev_t segv_device;
63964 + ino_t segv_inode;
63965 + uid_t segv_uid;
63966 + __u16 num_sprole_pws;
63967 + __u16 mode;
63968 +};
63969 +
63970 +struct gr_arg_wrapper {
63971 + struct gr_arg *arg;
63972 + __u32 version;
63973 + __u32 size;
63974 +};
63975 +
63976 +struct subject_map {
63977 + struct acl_subject_label *user;
63978 + struct acl_subject_label *kernel;
63979 + struct subject_map *prev;
63980 + struct subject_map *next;
63981 +};
63982 +
63983 +struct acl_subj_map_db {
63984 + struct subject_map **s_hash;
63985 + __u32 s_size;
63986 +};
63987 +
63988 +/* End Data Structures Section */
63989 +
63990 +/* Hash functions generated by empirical testing by Brad Spengler
63991 + Makes good use of the low bits of the inode. Generally 0-1 times
63992 + in loop for successful match. 0-3 for unsuccessful match.
63993 + Shift/add algorithm with modulus of table size and an XOR*/
63994 +
63995 +static __inline__ unsigned int
63996 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
63997 +{
63998 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
63999 +}
64000 +
64001 + static __inline__ unsigned int
64002 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
64003 +{
64004 + return ((const unsigned long)userp % sz);
64005 +}
64006 +
64007 +static __inline__ unsigned int
64008 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
64009 +{
64010 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
64011 +}
64012 +
64013 +static __inline__ unsigned int
64014 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
64015 +{
64016 + return full_name_hash((const unsigned char *)name, len) % sz;
64017 +}
64018 +
64019 +#define FOR_EACH_ROLE_START(role) \
64020 + role = role_list; \
64021 + while (role) {
64022 +
64023 +#define FOR_EACH_ROLE_END(role) \
64024 + role = role->prev; \
64025 + }
64026 +
64027 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
64028 + subj = NULL; \
64029 + iter = 0; \
64030 + while (iter < role->subj_hash_size) { \
64031 + if (subj == NULL) \
64032 + subj = role->subj_hash[iter]; \
64033 + if (subj == NULL) { \
64034 + iter++; \
64035 + continue; \
64036 + }
64037 +
64038 +#define FOR_EACH_SUBJECT_END(subj,iter) \
64039 + subj = subj->next; \
64040 + if (subj == NULL) \
64041 + iter++; \
64042 + }
64043 +
64044 +
64045 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
64046 + subj = role->hash->first; \
64047 + while (subj != NULL) {
64048 +
64049 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
64050 + subj = subj->next; \
64051 + }
64052 +
64053 +#endif
64054 +
64055 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
64056 new file mode 100644
64057 index 0000000..323ecf2
64058 --- /dev/null
64059 +++ b/include/linux/gralloc.h
64060 @@ -0,0 +1,9 @@
64061 +#ifndef __GRALLOC_H
64062 +#define __GRALLOC_H
64063 +
64064 +void acl_free_all(void);
64065 +int acl_alloc_stack_init(unsigned long size);
64066 +void *acl_alloc(unsigned long len);
64067 +void *acl_alloc_num(unsigned long num, unsigned long len);
64068 +
64069 +#endif
64070 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
64071 new file mode 100644
64072 index 0000000..be66033
64073 --- /dev/null
64074 +++ b/include/linux/grdefs.h
64075 @@ -0,0 +1,140 @@
64076 +#ifndef GRDEFS_H
64077 +#define GRDEFS_H
64078 +
64079 +/* Begin grsecurity status declarations */
64080 +
64081 +enum {
64082 + GR_READY = 0x01,
64083 + GR_STATUS_INIT = 0x00 // disabled state
64084 +};
64085 +
64086 +/* Begin ACL declarations */
64087 +
64088 +/* Role flags */
64089 +
64090 +enum {
64091 + GR_ROLE_USER = 0x0001,
64092 + GR_ROLE_GROUP = 0x0002,
64093 + GR_ROLE_DEFAULT = 0x0004,
64094 + GR_ROLE_SPECIAL = 0x0008,
64095 + GR_ROLE_AUTH = 0x0010,
64096 + GR_ROLE_NOPW = 0x0020,
64097 + GR_ROLE_GOD = 0x0040,
64098 + GR_ROLE_LEARN = 0x0080,
64099 + GR_ROLE_TPE = 0x0100,
64100 + GR_ROLE_DOMAIN = 0x0200,
64101 + GR_ROLE_PAM = 0x0400,
64102 + GR_ROLE_PERSIST = 0x0800
64103 +};
64104 +
64105 +/* ACL Subject and Object mode flags */
64106 +enum {
64107 + GR_DELETED = 0x80000000
64108 +};
64109 +
64110 +/* ACL Object-only mode flags */
64111 +enum {
64112 + GR_READ = 0x00000001,
64113 + GR_APPEND = 0x00000002,
64114 + GR_WRITE = 0x00000004,
64115 + GR_EXEC = 0x00000008,
64116 + GR_FIND = 0x00000010,
64117 + GR_INHERIT = 0x00000020,
64118 + GR_SETID = 0x00000040,
64119 + GR_CREATE = 0x00000080,
64120 + GR_DELETE = 0x00000100,
64121 + GR_LINK = 0x00000200,
64122 + GR_AUDIT_READ = 0x00000400,
64123 + GR_AUDIT_APPEND = 0x00000800,
64124 + GR_AUDIT_WRITE = 0x00001000,
64125 + GR_AUDIT_EXEC = 0x00002000,
64126 + GR_AUDIT_FIND = 0x00004000,
64127 + GR_AUDIT_INHERIT= 0x00008000,
64128 + GR_AUDIT_SETID = 0x00010000,
64129 + GR_AUDIT_CREATE = 0x00020000,
64130 + GR_AUDIT_DELETE = 0x00040000,
64131 + GR_AUDIT_LINK = 0x00080000,
64132 + GR_PTRACERD = 0x00100000,
64133 + GR_NOPTRACE = 0x00200000,
64134 + GR_SUPPRESS = 0x00400000,
64135 + GR_NOLEARN = 0x00800000,
64136 + GR_INIT_TRANSFER= 0x01000000
64137 +};
64138 +
64139 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
64140 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
64141 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
64142 +
64143 +/* ACL subject-only mode flags */
64144 +enum {
64145 + GR_KILL = 0x00000001,
64146 + GR_VIEW = 0x00000002,
64147 + GR_PROTECTED = 0x00000004,
64148 + GR_LEARN = 0x00000008,
64149 + GR_OVERRIDE = 0x00000010,
64150 + /* just a placeholder, this mode is only used in userspace */
64151 + GR_DUMMY = 0x00000020,
64152 + GR_PROTSHM = 0x00000040,
64153 + GR_KILLPROC = 0x00000080,
64154 + GR_KILLIPPROC = 0x00000100,
64155 + /* just a placeholder, this mode is only used in userspace */
64156 + GR_NOTROJAN = 0x00000200,
64157 + GR_PROTPROCFD = 0x00000400,
64158 + GR_PROCACCT = 0x00000800,
64159 + GR_RELAXPTRACE = 0x00001000,
64160 + //GR_NESTED = 0x00002000,
64161 + GR_INHERITLEARN = 0x00004000,
64162 + GR_PROCFIND = 0x00008000,
64163 + GR_POVERRIDE = 0x00010000,
64164 + GR_KERNELAUTH = 0x00020000,
64165 + GR_ATSECURE = 0x00040000,
64166 + GR_SHMEXEC = 0x00080000
64167 +};
64168 +
64169 +enum {
64170 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
64171 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
64172 + GR_PAX_ENABLE_MPROTECT = 0x0004,
64173 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
64174 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
64175 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
64176 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
64177 + GR_PAX_DISABLE_MPROTECT = 0x0400,
64178 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
64179 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
64180 +};
64181 +
64182 +enum {
64183 + GR_ID_USER = 0x01,
64184 + GR_ID_GROUP = 0x02,
64185 +};
64186 +
64187 +enum {
64188 + GR_ID_ALLOW = 0x01,
64189 + GR_ID_DENY = 0x02,
64190 +};
64191 +
64192 +#define GR_CRASH_RES 31
64193 +#define GR_UIDTABLE_MAX 500
64194 +
64195 +/* begin resource learning section */
64196 +enum {
64197 + GR_RLIM_CPU_BUMP = 60,
64198 + GR_RLIM_FSIZE_BUMP = 50000,
64199 + GR_RLIM_DATA_BUMP = 10000,
64200 + GR_RLIM_STACK_BUMP = 1000,
64201 + GR_RLIM_CORE_BUMP = 10000,
64202 + GR_RLIM_RSS_BUMP = 500000,
64203 + GR_RLIM_NPROC_BUMP = 1,
64204 + GR_RLIM_NOFILE_BUMP = 5,
64205 + GR_RLIM_MEMLOCK_BUMP = 50000,
64206 + GR_RLIM_AS_BUMP = 500000,
64207 + GR_RLIM_LOCKS_BUMP = 2,
64208 + GR_RLIM_SIGPENDING_BUMP = 5,
64209 + GR_RLIM_MSGQUEUE_BUMP = 10000,
64210 + GR_RLIM_NICE_BUMP = 1,
64211 + GR_RLIM_RTPRIO_BUMP = 1,
64212 + GR_RLIM_RTTIME_BUMP = 1000000
64213 +};
64214 +
64215 +#endif
64216 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
64217 new file mode 100644
64218 index 0000000..baa6e96
64219 --- /dev/null
64220 +++ b/include/linux/grinternal.h
64221 @@ -0,0 +1,215 @@
64222 +#ifndef __GRINTERNAL_H
64223 +#define __GRINTERNAL_H
64224 +
64225 +#ifdef CONFIG_GRKERNSEC
64226 +
64227 +#include <linux/fs.h>
64228 +#include <linux/mnt_namespace.h>
64229 +#include <linux/nsproxy.h>
64230 +#include <linux/gracl.h>
64231 +#include <linux/grdefs.h>
64232 +#include <linux/grmsg.h>
64233 +
64234 +void gr_add_learn_entry(const char *fmt, ...)
64235 + __attribute__ ((format (printf, 1, 2)));
64236 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
64237 + const struct vfsmount *mnt);
64238 +__u32 gr_check_create(const struct dentry *new_dentry,
64239 + const struct dentry *parent,
64240 + const struct vfsmount *mnt, const __u32 mode);
64241 +int gr_check_protected_task(const struct task_struct *task);
64242 +__u32 to_gr_audit(const __u32 reqmode);
64243 +int gr_set_acls(const int type);
64244 +int gr_apply_subject_to_task(struct task_struct *task);
64245 +int gr_acl_is_enabled(void);
64246 +char gr_roletype_to_char(void);
64247 +
64248 +void gr_handle_alertkill(struct task_struct *task);
64249 +char *gr_to_filename(const struct dentry *dentry,
64250 + const struct vfsmount *mnt);
64251 +char *gr_to_filename1(const struct dentry *dentry,
64252 + const struct vfsmount *mnt);
64253 +char *gr_to_filename2(const struct dentry *dentry,
64254 + const struct vfsmount *mnt);
64255 +char *gr_to_filename3(const struct dentry *dentry,
64256 + const struct vfsmount *mnt);
64257 +
64258 +extern int grsec_enable_ptrace_readexec;
64259 +extern int grsec_enable_harden_ptrace;
64260 +extern int grsec_enable_link;
64261 +extern int grsec_enable_fifo;
64262 +extern int grsec_enable_execve;
64263 +extern int grsec_enable_shm;
64264 +extern int grsec_enable_execlog;
64265 +extern int grsec_enable_signal;
64266 +extern int grsec_enable_audit_ptrace;
64267 +extern int grsec_enable_forkfail;
64268 +extern int grsec_enable_time;
64269 +extern int grsec_enable_rofs;
64270 +extern int grsec_enable_chroot_shmat;
64271 +extern int grsec_enable_chroot_mount;
64272 +extern int grsec_enable_chroot_double;
64273 +extern int grsec_enable_chroot_pivot;
64274 +extern int grsec_enable_chroot_chdir;
64275 +extern int grsec_enable_chroot_chmod;
64276 +extern int grsec_enable_chroot_mknod;
64277 +extern int grsec_enable_chroot_fchdir;
64278 +extern int grsec_enable_chroot_nice;
64279 +extern int grsec_enable_chroot_execlog;
64280 +extern int grsec_enable_chroot_caps;
64281 +extern int grsec_enable_chroot_sysctl;
64282 +extern int grsec_enable_chroot_unix;
64283 +extern int grsec_enable_symlinkown;
64284 +extern int grsec_symlinkown_gid;
64285 +extern int grsec_enable_tpe;
64286 +extern int grsec_tpe_gid;
64287 +extern int grsec_enable_tpe_all;
64288 +extern int grsec_enable_tpe_invert;
64289 +extern int grsec_enable_socket_all;
64290 +extern int grsec_socket_all_gid;
64291 +extern int grsec_enable_socket_client;
64292 +extern int grsec_socket_client_gid;
64293 +extern int grsec_enable_socket_server;
64294 +extern int grsec_socket_server_gid;
64295 +extern int grsec_audit_gid;
64296 +extern int grsec_enable_group;
64297 +extern int grsec_enable_audit_textrel;
64298 +extern int grsec_enable_log_rwxmaps;
64299 +extern int grsec_enable_mount;
64300 +extern int grsec_enable_chdir;
64301 +extern int grsec_resource_logging;
64302 +extern int grsec_enable_blackhole;
64303 +extern int grsec_lastack_retries;
64304 +extern int grsec_enable_brute;
64305 +extern int grsec_lock;
64306 +
64307 +extern spinlock_t grsec_alert_lock;
64308 +extern unsigned long grsec_alert_wtime;
64309 +extern unsigned long grsec_alert_fyet;
64310 +
64311 +extern spinlock_t grsec_audit_lock;
64312 +
64313 +extern rwlock_t grsec_exec_file_lock;
64314 +
64315 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
64316 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
64317 + (tsk)->exec_file->f_vfsmnt) : "/")
64318 +
64319 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
64320 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
64321 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
64322 +
64323 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
64324 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
64325 + (tsk)->exec_file->f_vfsmnt) : "/")
64326 +
64327 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
64328 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
64329 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
64330 +
64331 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
64332 +
64333 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
64334 +
64335 +#define GR_CHROOT_CAPS {{ \
64336 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
64337 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
64338 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
64339 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
64340 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
64341 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
64342 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
64343 +
64344 +#define security_learn(normal_msg,args...) \
64345 +({ \
64346 + read_lock(&grsec_exec_file_lock); \
64347 + gr_add_learn_entry(normal_msg "\n", ## args); \
64348 + read_unlock(&grsec_exec_file_lock); \
64349 +})
64350 +
64351 +enum {
64352 + GR_DO_AUDIT,
64353 + GR_DONT_AUDIT,
64354 + /* used for non-audit messages that we shouldn't kill the task on */
64355 + GR_DONT_AUDIT_GOOD
64356 +};
64357 +
64358 +enum {
64359 + GR_TTYSNIFF,
64360 + GR_RBAC,
64361 + GR_RBAC_STR,
64362 + GR_STR_RBAC,
64363 + GR_RBAC_MODE2,
64364 + GR_RBAC_MODE3,
64365 + GR_FILENAME,
64366 + GR_SYSCTL_HIDDEN,
64367 + GR_NOARGS,
64368 + GR_ONE_INT,
64369 + GR_ONE_INT_TWO_STR,
64370 + GR_ONE_STR,
64371 + GR_STR_INT,
64372 + GR_TWO_STR_INT,
64373 + GR_TWO_INT,
64374 + GR_TWO_U64,
64375 + GR_THREE_INT,
64376 + GR_FIVE_INT_TWO_STR,
64377 + GR_TWO_STR,
64378 + GR_THREE_STR,
64379 + GR_FOUR_STR,
64380 + GR_STR_FILENAME,
64381 + GR_FILENAME_STR,
64382 + GR_FILENAME_TWO_INT,
64383 + GR_FILENAME_TWO_INT_STR,
64384 + GR_TEXTREL,
64385 + GR_PTRACE,
64386 + GR_RESOURCE,
64387 + GR_CAP,
64388 + GR_SIG,
64389 + GR_SIG2,
64390 + GR_CRASH1,
64391 + GR_CRASH2,
64392 + GR_PSACCT,
64393 + GR_RWXMAP
64394 +};
64395 +
64396 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
64397 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
64398 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
64399 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
64400 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
64401 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
64402 +#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)
64403 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
64404 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
64405 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
64406 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
64407 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
64408 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
64409 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
64410 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
64411 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
64412 +#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)
64413 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
64414 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
64415 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
64416 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
64417 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
64418 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
64419 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
64420 +#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)
64421 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
64422 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
64423 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
64424 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
64425 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
64426 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
64427 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
64428 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
64429 +#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)
64430 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
64431 +
64432 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
64433 +
64434 +#endif
64435 +
64436 +#endif
64437 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
64438 new file mode 100644
64439 index 0000000..2bd4c8d
64440 --- /dev/null
64441 +++ b/include/linux/grmsg.h
64442 @@ -0,0 +1,111 @@
64443 +#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"
64444 +#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"
64445 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
64446 +#define GR_STOPMOD_MSG "denied modification of module state by "
64447 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
64448 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
64449 +#define GR_IOPERM_MSG "denied use of ioperm() by "
64450 +#define GR_IOPL_MSG "denied use of iopl() by "
64451 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
64452 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
64453 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
64454 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
64455 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
64456 +#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"
64457 +#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"
64458 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
64459 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
64460 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
64461 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
64462 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
64463 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
64464 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
64465 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
64466 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
64467 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
64468 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
64469 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
64470 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
64471 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
64472 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
64473 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
64474 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
64475 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
64476 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
64477 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
64478 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
64479 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
64480 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
64481 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
64482 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
64483 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
64484 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
64485 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
64486 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
64487 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
64488 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
64489 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
64490 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
64491 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
64492 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
64493 +#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"
64494 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
64495 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
64496 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
64497 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
64498 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
64499 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
64500 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
64501 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
64502 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
64503 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
64504 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
64505 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
64506 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
64507 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
64508 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
64509 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
64510 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
64511 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
64512 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
64513 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
64514 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
64515 +#define GR_NICE_CHROOT_MSG "denied priority change by "
64516 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
64517 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
64518 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
64519 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
64520 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
64521 +#define GR_TIME_MSG "time set by "
64522 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
64523 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
64524 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
64525 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
64526 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
64527 +#define GR_BIND_MSG "denied bind() by "
64528 +#define GR_CONNECT_MSG "denied connect() by "
64529 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
64530 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
64531 +#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"
64532 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
64533 +#define GR_CAP_ACL_MSG "use of %s denied for "
64534 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
64535 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
64536 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
64537 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
64538 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
64539 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
64540 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
64541 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
64542 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
64543 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
64544 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
64545 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
64546 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
64547 +#define GR_VM86_MSG "denied use of vm86 by "
64548 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
64549 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
64550 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
64551 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
64552 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
64553 +#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 "
64554 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
64555 new file mode 100644
64556 index 0000000..c5e5913
64557 --- /dev/null
64558 +++ b/include/linux/grsecurity.h
64559 @@ -0,0 +1,257 @@
64560 +#ifndef GR_SECURITY_H
64561 +#define GR_SECURITY_H
64562 +#include <linux/fs.h>
64563 +#include <linux/fs_struct.h>
64564 +#include <linux/binfmts.h>
64565 +#include <linux/gracl.h>
64566 +
64567 +/* notify of brain-dead configs */
64568 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64569 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
64570 +#endif
64571 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
64572 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
64573 +#endif
64574 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
64575 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
64576 +#endif
64577 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
64578 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
64579 +#endif
64580 +
64581 +#include <linux/compat.h>
64582 +
64583 +struct user_arg_ptr {
64584 +#ifdef CONFIG_COMPAT
64585 + bool is_compat;
64586 +#endif
64587 + union {
64588 + const char __user *const __user *native;
64589 +#ifdef CONFIG_COMPAT
64590 + const compat_uptr_t __user *compat;
64591 +#endif
64592 + } ptr;
64593 +};
64594 +
64595 +void gr_handle_brute_attach(unsigned long mm_flags);
64596 +void gr_handle_brute_check(void);
64597 +void gr_handle_kernel_exploit(void);
64598 +int gr_process_user_ban(void);
64599 +
64600 +char gr_roletype_to_char(void);
64601 +
64602 +int gr_acl_enable_at_secure(void);
64603 +
64604 +int gr_check_user_change(int real, int effective, int fs);
64605 +int gr_check_group_change(int real, int effective, int fs);
64606 +
64607 +void gr_del_task_from_ip_table(struct task_struct *p);
64608 +
64609 +int gr_pid_is_chrooted(struct task_struct *p);
64610 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
64611 +int gr_handle_chroot_nice(void);
64612 +int gr_handle_chroot_sysctl(const int op);
64613 +int gr_handle_chroot_setpriority(struct task_struct *p,
64614 + const int niceval);
64615 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
64616 +int gr_handle_chroot_chroot(const struct dentry *dentry,
64617 + const struct vfsmount *mnt);
64618 +void gr_handle_chroot_chdir(struct path *path);
64619 +int gr_handle_chroot_chmod(const struct dentry *dentry,
64620 + const struct vfsmount *mnt, const int mode);
64621 +int gr_handle_chroot_mknod(const struct dentry *dentry,
64622 + const struct vfsmount *mnt, const int mode);
64623 +int gr_handle_chroot_mount(const struct dentry *dentry,
64624 + const struct vfsmount *mnt,
64625 + const char *dev_name);
64626 +int gr_handle_chroot_pivot(void);
64627 +int gr_handle_chroot_unix(const pid_t pid);
64628 +
64629 +int gr_handle_rawio(const struct inode *inode);
64630 +
64631 +void gr_handle_ioperm(void);
64632 +void gr_handle_iopl(void);
64633 +
64634 +umode_t gr_acl_umask(void);
64635 +
64636 +int gr_tpe_allow(const struct file *file);
64637 +
64638 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
64639 +void gr_clear_chroot_entries(struct task_struct *task);
64640 +
64641 +void gr_log_forkfail(const int retval);
64642 +void gr_log_timechange(void);
64643 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
64644 +void gr_log_chdir(const struct dentry *dentry,
64645 + const struct vfsmount *mnt);
64646 +void gr_log_chroot_exec(const struct dentry *dentry,
64647 + const struct vfsmount *mnt);
64648 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
64649 +void gr_log_remount(const char *devname, const int retval);
64650 +void gr_log_unmount(const char *devname, const int retval);
64651 +void gr_log_mount(const char *from, const char *to, const int retval);
64652 +void gr_log_textrel(struct vm_area_struct *vma);
64653 +void gr_log_rwxmmap(struct file *file);
64654 +void gr_log_rwxmprotect(struct file *file);
64655 +
64656 +int gr_handle_follow_link(const struct inode *parent,
64657 + const struct inode *inode,
64658 + const struct dentry *dentry,
64659 + const struct vfsmount *mnt);
64660 +int gr_handle_fifo(const struct dentry *dentry,
64661 + const struct vfsmount *mnt,
64662 + const struct dentry *dir, const int flag,
64663 + const int acc_mode);
64664 +int gr_handle_hardlink(const struct dentry *dentry,
64665 + const struct vfsmount *mnt,
64666 + struct inode *inode,
64667 + const int mode, const struct filename *to);
64668 +
64669 +int gr_is_capable(const int cap);
64670 +int gr_is_capable_nolog(const int cap);
64671 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
64672 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
64673 +
64674 +void gr_copy_label(struct task_struct *tsk);
64675 +void gr_handle_crash(struct task_struct *task, const int sig);
64676 +int gr_handle_signal(const struct task_struct *p, const int sig);
64677 +int gr_check_crash_uid(const uid_t uid);
64678 +int gr_check_protected_task(const struct task_struct *task);
64679 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
64680 +int gr_acl_handle_mmap(const struct file *file,
64681 + const unsigned long prot);
64682 +int gr_acl_handle_mprotect(const struct file *file,
64683 + const unsigned long prot);
64684 +int gr_check_hidden_task(const struct task_struct *tsk);
64685 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
64686 + const struct vfsmount *mnt);
64687 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
64688 + const struct vfsmount *mnt);
64689 +__u32 gr_acl_handle_access(const struct dentry *dentry,
64690 + const struct vfsmount *mnt, const int fmode);
64691 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
64692 + const struct vfsmount *mnt, umode_t *mode);
64693 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
64694 + const struct vfsmount *mnt);
64695 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
64696 + const struct vfsmount *mnt);
64697 +int gr_handle_ptrace(struct task_struct *task, const long request);
64698 +int gr_handle_proc_ptrace(struct task_struct *task);
64699 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
64700 + const struct vfsmount *mnt);
64701 +int gr_check_crash_exec(const struct file *filp);
64702 +int gr_acl_is_enabled(void);
64703 +void gr_set_kernel_label(struct task_struct *task);
64704 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
64705 + const gid_t gid);
64706 +int gr_set_proc_label(const struct dentry *dentry,
64707 + const struct vfsmount *mnt,
64708 + const int unsafe_flags);
64709 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
64710 + const struct vfsmount *mnt);
64711 +__u32 gr_acl_handle_open(const struct dentry *dentry,
64712 + const struct vfsmount *mnt, int acc_mode);
64713 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
64714 + const struct dentry *p_dentry,
64715 + const struct vfsmount *p_mnt,
64716 + int open_flags, int acc_mode, const int imode);
64717 +void gr_handle_create(const struct dentry *dentry,
64718 + const struct vfsmount *mnt);
64719 +void gr_handle_proc_create(const struct dentry *dentry,
64720 + const struct inode *inode);
64721 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
64722 + const struct dentry *parent_dentry,
64723 + const struct vfsmount *parent_mnt,
64724 + const int mode);
64725 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
64726 + const struct dentry *parent_dentry,
64727 + const struct vfsmount *parent_mnt);
64728 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
64729 + const struct vfsmount *mnt);
64730 +void gr_handle_delete(const ino_t ino, const dev_t dev);
64731 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
64732 + const struct vfsmount *mnt);
64733 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
64734 + const struct dentry *parent_dentry,
64735 + const struct vfsmount *parent_mnt,
64736 + const struct filename *from);
64737 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
64738 + const struct dentry *parent_dentry,
64739 + const struct vfsmount *parent_mnt,
64740 + const struct dentry *old_dentry,
64741 + const struct vfsmount *old_mnt, const struct filename *to);
64742 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
64743 +int gr_acl_handle_rename(struct dentry *new_dentry,
64744 + struct dentry *parent_dentry,
64745 + const struct vfsmount *parent_mnt,
64746 + struct dentry *old_dentry,
64747 + struct inode *old_parent_inode,
64748 + struct vfsmount *old_mnt, const struct filename *newname);
64749 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
64750 + struct dentry *old_dentry,
64751 + struct dentry *new_dentry,
64752 + struct vfsmount *mnt, const __u8 replace);
64753 +__u32 gr_check_link(const struct dentry *new_dentry,
64754 + const struct dentry *parent_dentry,
64755 + const struct vfsmount *parent_mnt,
64756 + const struct dentry *old_dentry,
64757 + const struct vfsmount *old_mnt);
64758 +int gr_acl_handle_filldir(const struct file *file, const char *name,
64759 + const unsigned int namelen, const ino_t ino);
64760 +
64761 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
64762 + const struct vfsmount *mnt);
64763 +void gr_acl_handle_exit(void);
64764 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
64765 +int gr_acl_handle_procpidmem(const struct task_struct *task);
64766 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
64767 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
64768 +void gr_audit_ptrace(struct task_struct *task);
64769 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
64770 +void gr_put_exec_file(struct task_struct *task);
64771 +
64772 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
64773 +
64774 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
64775 +extern void gr_learn_resource(const struct task_struct *task, const int res,
64776 + const unsigned long wanted, const int gt);
64777 +#else
64778 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
64779 + const unsigned long wanted, const int gt)
64780 +{
64781 +}
64782 +#endif
64783 +
64784 +#ifdef CONFIG_GRKERNSEC_RESLOG
64785 +extern void gr_log_resource(const struct task_struct *task, const int res,
64786 + const unsigned long wanted, const int gt);
64787 +#else
64788 +static inline void gr_log_resource(const struct task_struct *task, const int res,
64789 + const unsigned long wanted, const int gt)
64790 +{
64791 +}
64792 +#endif
64793 +
64794 +#ifdef CONFIG_GRKERNSEC
64795 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
64796 +void gr_handle_vm86(void);
64797 +void gr_handle_mem_readwrite(u64 from, u64 to);
64798 +
64799 +void gr_log_badprocpid(const char *entry);
64800 +
64801 +extern int grsec_enable_dmesg;
64802 +extern int grsec_disable_privio;
64803 +
64804 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64805 +extern int grsec_proc_gid;
64806 +#endif
64807 +
64808 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64809 +extern int grsec_enable_chroot_findtask;
64810 +#endif
64811 +#ifdef CONFIG_GRKERNSEC_SETXID
64812 +extern int grsec_enable_setxid;
64813 +#endif
64814 +#endif
64815 +
64816 +#endif
64817 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
64818 new file mode 100644
64819 index 0000000..e7ffaaf
64820 --- /dev/null
64821 +++ b/include/linux/grsock.h
64822 @@ -0,0 +1,19 @@
64823 +#ifndef __GRSOCK_H
64824 +#define __GRSOCK_H
64825 +
64826 +extern void gr_attach_curr_ip(const struct sock *sk);
64827 +extern int gr_handle_sock_all(const int family, const int type,
64828 + const int protocol);
64829 +extern int gr_handle_sock_server(const struct sockaddr *sck);
64830 +extern int gr_handle_sock_server_other(const struct sock *sck);
64831 +extern int gr_handle_sock_client(const struct sockaddr *sck);
64832 +extern int gr_search_connect(struct socket * sock,
64833 + struct sockaddr_in * addr);
64834 +extern int gr_search_bind(struct socket * sock,
64835 + struct sockaddr_in * addr);
64836 +extern int gr_search_listen(struct socket * sock);
64837 +extern int gr_search_accept(struct socket * sock);
64838 +extern int gr_search_socket(const int domain, const int type,
64839 + const int protocol);
64840 +
64841 +#endif
64842 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
64843 index ef788b5..ac41b7b 100644
64844 --- a/include/linux/highmem.h
64845 +++ b/include/linux/highmem.h
64846 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
64847 kunmap_atomic(kaddr);
64848 }
64849
64850 +static inline void sanitize_highpage(struct page *page)
64851 +{
64852 + void *kaddr;
64853 + unsigned long flags;
64854 +
64855 + local_irq_save(flags);
64856 + kaddr = kmap_atomic(page);
64857 + clear_page(kaddr);
64858 + kunmap_atomic(kaddr);
64859 + local_irq_restore(flags);
64860 +}
64861 +
64862 static inline void zero_user_segments(struct page *page,
64863 unsigned start1, unsigned end1,
64864 unsigned start2, unsigned end2)
64865 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
64866 index 800de22..7a2fa46 100644
64867 --- a/include/linux/i2c.h
64868 +++ b/include/linux/i2c.h
64869 @@ -367,6 +367,7 @@ struct i2c_algorithm {
64870 /* To determine what the adapter supports */
64871 u32 (*functionality) (struct i2c_adapter *);
64872 };
64873 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
64874
64875 /*
64876 * i2c_adapter is the structure used to identify a physical i2c bus along
64877 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
64878 index d23c3c2..eb63c81 100644
64879 --- a/include/linux/i2o.h
64880 +++ b/include/linux/i2o.h
64881 @@ -565,7 +565,7 @@ struct i2o_controller {
64882 struct i2o_device *exec; /* Executive */
64883 #if BITS_PER_LONG == 64
64884 spinlock_t context_list_lock; /* lock for context_list */
64885 - atomic_t context_list_counter; /* needed for unique contexts */
64886 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
64887 struct list_head context_list; /* list of context id's
64888 and pointers */
64889 #endif
64890 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
64891 index aff7ad8..3942bbd 100644
64892 --- a/include/linux/if_pppox.h
64893 +++ b/include/linux/if_pppox.h
64894 @@ -76,7 +76,7 @@ struct pppox_proto {
64895 int (*ioctl)(struct socket *sock, unsigned int cmd,
64896 unsigned long arg);
64897 struct module *owner;
64898 -};
64899 +} __do_const;
64900
64901 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
64902 extern void unregister_pppox_proto(int proto_num);
64903 diff --git a/include/linux/init.h b/include/linux/init.h
64904 index e59041e..df0a975 100644
64905 --- a/include/linux/init.h
64906 +++ b/include/linux/init.h
64907 @@ -39,9 +39,36 @@
64908 * Also note, that this data cannot be "const".
64909 */
64910
64911 +#ifdef MODULE
64912 +#define add_init_latent_entropy
64913 +#define add_devinit_latent_entropy
64914 +#define add_cpuinit_latent_entropy
64915 +#define add_meminit_latent_entropy
64916 +#else
64917 +#define add_init_latent_entropy __latent_entropy
64918 +
64919 +#ifdef CONFIG_HOTPLUG
64920 +#define add_devinit_latent_entropy
64921 +#else
64922 +#define add_devinit_latent_entropy __latent_entropy
64923 +#endif
64924 +
64925 +#ifdef CONFIG_HOTPLUG_CPU
64926 +#define add_cpuinit_latent_entropy
64927 +#else
64928 +#define add_cpuinit_latent_entropy __latent_entropy
64929 +#endif
64930 +
64931 +#ifdef CONFIG_MEMORY_HOTPLUG
64932 +#define add_meminit_latent_entropy
64933 +#else
64934 +#define add_meminit_latent_entropy __latent_entropy
64935 +#endif
64936 +#endif
64937 +
64938 /* These are for everybody (although not all archs will actually
64939 discard it in modules) */
64940 -#define __init __section(.init.text) __cold notrace
64941 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
64942 #define __initdata __section(.init.data)
64943 #define __initconst __constsection(.init.rodata)
64944 #define __exitdata __section(.exit.data)
64945 @@ -94,7 +121,7 @@
64946 #define __exit __section(.exit.text) __exitused __cold notrace
64947
64948 /* Used for HOTPLUG */
64949 -#define __devinit __section(.devinit.text) __cold notrace
64950 +#define __devinit __section(.devinit.text) __cold notrace add_devinit_latent_entropy
64951 #define __devinitdata __section(.devinit.data)
64952 #define __devinitconst __constsection(.devinit.rodata)
64953 #define __devexit __section(.devexit.text) __exitused __cold notrace
64954 @@ -102,7 +129,7 @@
64955 #define __devexitconst __constsection(.devexit.rodata)
64956
64957 /* Used for HOTPLUG_CPU */
64958 -#define __cpuinit __section(.cpuinit.text) __cold notrace
64959 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
64960 #define __cpuinitdata __section(.cpuinit.data)
64961 #define __cpuinitconst __constsection(.cpuinit.rodata)
64962 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
64963 @@ -110,7 +137,7 @@
64964 #define __cpuexitconst __constsection(.cpuexit.rodata)
64965
64966 /* Used for MEMORY_HOTPLUG */
64967 -#define __meminit __section(.meminit.text) __cold notrace
64968 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
64969 #define __meminitdata __section(.meminit.data)
64970 #define __meminitconst __constsection(.meminit.rodata)
64971 #define __memexit __section(.memexit.text) __exitused __cold notrace
64972 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
64973 index 6d087c5..401cab8 100644
64974 --- a/include/linux/init_task.h
64975 +++ b/include/linux/init_task.h
64976 @@ -143,6 +143,12 @@ extern struct task_group root_task_group;
64977
64978 #define INIT_TASK_COMM "swapper"
64979
64980 +#ifdef CONFIG_X86
64981 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
64982 +#else
64983 +#define INIT_TASK_THREAD_INFO
64984 +#endif
64985 +
64986 /*
64987 * INIT_TASK is used to set up the first task table, touch at
64988 * your own risk!. Base=0, limit=0x1fffff (=2MB)
64989 @@ -182,6 +188,7 @@ extern struct task_group root_task_group;
64990 RCU_POINTER_INITIALIZER(cred, &init_cred), \
64991 .comm = INIT_TASK_COMM, \
64992 .thread = INIT_THREAD, \
64993 + INIT_TASK_THREAD_INFO \
64994 .fs = &init_fs, \
64995 .files = &init_files, \
64996 .signal = &init_signals, \
64997 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
64998 index 5e4e617..eee383d 100644
64999 --- a/include/linux/interrupt.h
65000 +++ b/include/linux/interrupt.h
65001 @@ -435,7 +435,7 @@ enum
65002 /* map softirq index to softirq name. update 'softirq_to_name' in
65003 * kernel/softirq.c when adding a new softirq.
65004 */
65005 -extern char *softirq_to_name[NR_SOFTIRQS];
65006 +extern const char * const softirq_to_name[NR_SOFTIRQS];
65007
65008 /* softirq mask and active fields moved to irq_cpustat_t in
65009 * asm/hardirq.h to get better cache usage. KAO
65010 @@ -443,12 +443,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
65011
65012 struct softirq_action
65013 {
65014 - void (*action)(struct softirq_action *);
65015 + void (*action)(void);
65016 };
65017
65018 asmlinkage void do_softirq(void);
65019 asmlinkage void __do_softirq(void);
65020 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
65021 +extern void open_softirq(int nr, void (*action)(void));
65022 extern void softirq_init(void);
65023 extern void __raise_softirq_irqoff(unsigned int nr);
65024
65025 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
65026 index 6883e19..06992b1 100644
65027 --- a/include/linux/kallsyms.h
65028 +++ b/include/linux/kallsyms.h
65029 @@ -15,7 +15,8 @@
65030
65031 struct module;
65032
65033 -#ifdef CONFIG_KALLSYMS
65034 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
65035 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65036 /* Lookup the address for a symbol. Returns 0 if not found. */
65037 unsigned long kallsyms_lookup_name(const char *name);
65038
65039 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
65040 /* Stupid that this does nothing, but I didn't create this mess. */
65041 #define __print_symbol(fmt, addr)
65042 #endif /*CONFIG_KALLSYMS*/
65043 +#else /* when included by kallsyms.c, vsnprintf.c, or
65044 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
65045 +extern void __print_symbol(const char *fmt, unsigned long address);
65046 +extern int sprint_backtrace(char *buffer, unsigned long address);
65047 +extern int sprint_symbol(char *buffer, unsigned long address);
65048 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
65049 +const char *kallsyms_lookup(unsigned long addr,
65050 + unsigned long *symbolsize,
65051 + unsigned long *offset,
65052 + char **modname, char *namebuf);
65053 +#endif
65054
65055 /* This macro allows us to keep printk typechecking */
65056 static __printf(1, 2)
65057 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
65058 index 4dff0c6..1ca9b72 100644
65059 --- a/include/linux/kgdb.h
65060 +++ b/include/linux/kgdb.h
65061 @@ -53,7 +53,7 @@ extern int kgdb_connected;
65062 extern int kgdb_io_module_registered;
65063
65064 extern atomic_t kgdb_setting_breakpoint;
65065 -extern atomic_t kgdb_cpu_doing_single_step;
65066 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
65067
65068 extern struct task_struct *kgdb_usethread;
65069 extern struct task_struct *kgdb_contthread;
65070 @@ -255,7 +255,7 @@ struct kgdb_arch {
65071 void (*correct_hw_break)(void);
65072
65073 void (*enable_nmi)(bool on);
65074 -};
65075 +} __do_const;
65076
65077 /**
65078 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
65079 @@ -280,7 +280,7 @@ struct kgdb_io {
65080 void (*pre_exception) (void);
65081 void (*post_exception) (void);
65082 int is_console;
65083 -};
65084 +} __do_const;
65085
65086 extern struct kgdb_arch arch_kgdb_ops;
65087
65088 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
65089 index 5398d58..5883a34 100644
65090 --- a/include/linux/kmod.h
65091 +++ b/include/linux/kmod.h
65092 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
65093 * usually useless though. */
65094 extern __printf(2, 3)
65095 int __request_module(bool wait, const char *name, ...);
65096 +extern __printf(3, 4)
65097 +int ___request_module(bool wait, char *param_name, const char *name, ...);
65098 #define request_module(mod...) __request_module(true, mod)
65099 #define request_module_nowait(mod...) __request_module(false, mod)
65100 #define try_then_request_module(x, mod...) \
65101 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
65102 index 1e57449..4fede7b 100644
65103 --- a/include/linux/kobject.h
65104 +++ b/include/linux/kobject.h
65105 @@ -111,7 +111,7 @@ struct kobj_type {
65106 struct attribute **default_attrs;
65107 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
65108 const void *(*namespace)(struct kobject *kobj);
65109 -};
65110 +} __do_const;
65111
65112 struct kobj_uevent_env {
65113 char *envp[UEVENT_NUM_ENVP];
65114 diff --git a/include/linux/kref.h b/include/linux/kref.h
65115 index 65af688..0592677 100644
65116 --- a/include/linux/kref.h
65117 +++ b/include/linux/kref.h
65118 @@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
65119 static inline int kref_sub(struct kref *kref, unsigned int count,
65120 void (*release)(struct kref *kref))
65121 {
65122 - WARN_ON(release == NULL);
65123 + BUG_ON(release == NULL);
65124
65125 if (atomic_sub_and_test((int) count, &kref->refcount)) {
65126 release(kref);
65127 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
65128 index ecc5543..0e96bcc 100644
65129 --- a/include/linux/kvm_host.h
65130 +++ b/include/linux/kvm_host.h
65131 @@ -403,7 +403,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
65132 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
65133 void vcpu_put(struct kvm_vcpu *vcpu);
65134
65135 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
65136 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
65137 struct module *module);
65138 void kvm_exit(void);
65139
65140 @@ -558,7 +558,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
65141 struct kvm_guest_debug *dbg);
65142 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
65143
65144 -int kvm_arch_init(void *opaque);
65145 +int kvm_arch_init(const void *opaque);
65146 void kvm_arch_exit(void);
65147
65148 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
65149 diff --git a/include/linux/libata.h b/include/linux/libata.h
65150 index 1e36c63..0c5046e 100644
65151 --- a/include/linux/libata.h
65152 +++ b/include/linux/libata.h
65153 @@ -915,7 +915,7 @@ struct ata_port_operations {
65154 * fields must be pointers.
65155 */
65156 const struct ata_port_operations *inherits;
65157 -};
65158 +} __do_const;
65159
65160 struct ata_port_info {
65161 unsigned long flags;
65162 diff --git a/include/linux/list.h b/include/linux/list.h
65163 index cc6d2aa..71febca 100644
65164 --- a/include/linux/list.h
65165 +++ b/include/linux/list.h
65166 @@ -112,6 +112,9 @@ extern void __list_del_entry(struct list_head *entry);
65167 extern void list_del(struct list_head *entry);
65168 #endif
65169
65170 +extern void pax_list_add_tail(struct list_head *new, struct list_head *head);
65171 +extern void pax_list_del(struct list_head *entry);
65172 +
65173 /**
65174 * list_replace - replace old entry by new one
65175 * @old : the element to be replaced
65176 diff --git a/include/linux/mm.h b/include/linux/mm.h
65177 index 280dae5..39046ec 100644
65178 --- a/include/linux/mm.h
65179 +++ b/include/linux/mm.h
65180 @@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
65181 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
65182 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
65183 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
65184 +
65185 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
65186 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
65187 +#endif
65188 +
65189 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
65190
65191 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
65192 @@ -1039,34 +1044,6 @@ int set_page_dirty(struct page *page);
65193 int set_page_dirty_lock(struct page *page);
65194 int clear_page_dirty_for_io(struct page *page);
65195
65196 -/* Is the vma a continuation of the stack vma above it? */
65197 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
65198 -{
65199 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
65200 -}
65201 -
65202 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
65203 - unsigned long addr)
65204 -{
65205 - return (vma->vm_flags & VM_GROWSDOWN) &&
65206 - (vma->vm_start == addr) &&
65207 - !vma_growsdown(vma->vm_prev, addr);
65208 -}
65209 -
65210 -/* Is the vma a continuation of the stack vma below it? */
65211 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
65212 -{
65213 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
65214 -}
65215 -
65216 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
65217 - unsigned long addr)
65218 -{
65219 - return (vma->vm_flags & VM_GROWSUP) &&
65220 - (vma->vm_end == addr) &&
65221 - !vma_growsup(vma->vm_next, addr);
65222 -}
65223 -
65224 extern pid_t
65225 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
65226
65227 @@ -1166,6 +1143,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
65228 }
65229 #endif
65230
65231 +#ifdef CONFIG_MMU
65232 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
65233 +#else
65234 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
65235 +{
65236 + return __pgprot(0);
65237 +}
65238 +#endif
65239 +
65240 int vma_wants_writenotify(struct vm_area_struct *vma);
65241
65242 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
65243 @@ -1184,8 +1170,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
65244 {
65245 return 0;
65246 }
65247 +
65248 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
65249 + unsigned long address)
65250 +{
65251 + return 0;
65252 +}
65253 #else
65254 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
65255 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
65256 #endif
65257
65258 #ifdef __PAGETABLE_PMD_FOLDED
65259 @@ -1194,8 +1187,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
65260 {
65261 return 0;
65262 }
65263 +
65264 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
65265 + unsigned long address)
65266 +{
65267 + return 0;
65268 +}
65269 #else
65270 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
65271 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
65272 #endif
65273
65274 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
65275 @@ -1213,11 +1213,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
65276 NULL: pud_offset(pgd, address);
65277 }
65278
65279 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
65280 +{
65281 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
65282 + NULL: pud_offset(pgd, address);
65283 +}
65284 +
65285 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
65286 {
65287 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
65288 NULL: pmd_offset(pud, address);
65289 }
65290 +
65291 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
65292 +{
65293 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
65294 + NULL: pmd_offset(pud, address);
65295 +}
65296 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
65297
65298 #if USE_SPLIT_PTLOCKS
65299 @@ -1447,6 +1459,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
65300 unsigned long, unsigned long,
65301 unsigned long, unsigned long);
65302 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
65303 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
65304
65305 /* These take the mm semaphore themselves */
65306 extern unsigned long vm_brk(unsigned long, unsigned long);
65307 @@ -1510,6 +1523,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
65308 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
65309 struct vm_area_struct **pprev);
65310
65311 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
65312 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
65313 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
65314 +
65315 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
65316 NULL if none. Assume start_addr < end_addr. */
65317 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
65318 @@ -1538,15 +1555,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
65319 return vma;
65320 }
65321
65322 -#ifdef CONFIG_MMU
65323 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
65324 -#else
65325 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
65326 -{
65327 - return __pgprot(0);
65328 -}
65329 -#endif
65330 -
65331 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
65332 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
65333 unsigned long pfn, unsigned long size, pgprot_t);
65334 @@ -1652,7 +1660,7 @@ extern int unpoison_memory(unsigned long pfn);
65335 extern int sysctl_memory_failure_early_kill;
65336 extern int sysctl_memory_failure_recovery;
65337 extern void shake_page(struct page *p, int access);
65338 -extern atomic_long_t mce_bad_pages;
65339 +extern atomic_long_unchecked_t mce_bad_pages;
65340 extern int soft_offline_page(struct page *page, int flags);
65341
65342 extern void dump_page(struct page *page);
65343 @@ -1683,5 +1691,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
65344 static inline bool page_is_guard(struct page *page) { return false; }
65345 #endif /* CONFIG_DEBUG_PAGEALLOC */
65346
65347 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
65348 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
65349 +#else
65350 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
65351 +#endif
65352 +
65353 #endif /* __KERNEL__ */
65354 #endif /* _LINUX_MM_H */
65355 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
65356 index 31f8a3a..499f1db 100644
65357 --- a/include/linux/mm_types.h
65358 +++ b/include/linux/mm_types.h
65359 @@ -275,6 +275,8 @@ struct vm_area_struct {
65360 #ifdef CONFIG_NUMA
65361 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
65362 #endif
65363 +
65364 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
65365 };
65366
65367 struct core_thread {
65368 @@ -348,7 +350,7 @@ struct mm_struct {
65369 unsigned long def_flags;
65370 unsigned long nr_ptes; /* Page table pages */
65371 unsigned long start_code, end_code, start_data, end_data;
65372 - unsigned long start_brk, brk, start_stack;
65373 + unsigned long brk_gap, start_brk, brk, start_stack;
65374 unsigned long arg_start, arg_end, env_start, env_end;
65375
65376 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
65377 @@ -399,6 +401,24 @@ struct mm_struct {
65378 struct cpumask cpumask_allocation;
65379 #endif
65380 struct uprobes_state uprobes_state;
65381 +
65382 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65383 + unsigned long pax_flags;
65384 +#endif
65385 +
65386 +#ifdef CONFIG_PAX_DLRESOLVE
65387 + unsigned long call_dl_resolve;
65388 +#endif
65389 +
65390 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
65391 + unsigned long call_syscall;
65392 +#endif
65393 +
65394 +#ifdef CONFIG_PAX_ASLR
65395 + unsigned long delta_mmap; /* randomized offset */
65396 + unsigned long delta_stack; /* randomized offset */
65397 +#endif
65398 +
65399 };
65400
65401 static inline void mm_init_cpumask(struct mm_struct *mm)
65402 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
65403 index c5d5278..f0b68c8 100644
65404 --- a/include/linux/mmiotrace.h
65405 +++ b/include/linux/mmiotrace.h
65406 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
65407 /* Called from ioremap.c */
65408 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
65409 void __iomem *addr);
65410 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
65411 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
65412
65413 /* For anyone to insert markers. Remember trailing newline. */
65414 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
65415 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
65416 {
65417 }
65418
65419 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
65420 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
65421 {
65422 }
65423
65424 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
65425 index a23923b..073fee4 100644
65426 --- a/include/linux/mmzone.h
65427 +++ b/include/linux/mmzone.h
65428 @@ -421,7 +421,7 @@ struct zone {
65429 unsigned long flags; /* zone flags, see below */
65430
65431 /* Zone statistics */
65432 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65433 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65434
65435 /*
65436 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
65437 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
65438 index fed3def..7cc3f93 100644
65439 --- a/include/linux/mod_devicetable.h
65440 +++ b/include/linux/mod_devicetable.h
65441 @@ -12,7 +12,7 @@
65442 typedef unsigned long kernel_ulong_t;
65443 #endif
65444
65445 -#define PCI_ANY_ID (~0)
65446 +#define PCI_ANY_ID ((__u16)~0)
65447
65448 struct pci_device_id {
65449 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
65450 @@ -139,7 +139,7 @@ struct usb_device_id {
65451 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
65452 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
65453
65454 -#define HID_ANY_ID (~0)
65455 +#define HID_ANY_ID (~0U)
65456 #define HID_BUS_ANY 0xffff
65457 #define HID_GROUP_ANY 0x0000
65458
65459 diff --git a/include/linux/module.h b/include/linux/module.h
65460 index 1375ee3..d631af0 100644
65461 --- a/include/linux/module.h
65462 +++ b/include/linux/module.h
65463 @@ -17,9 +17,11 @@
65464 #include <linux/moduleparam.h>
65465 #include <linux/tracepoint.h>
65466 #include <linux/export.h>
65467 +#include <linux/fs.h>
65468
65469 #include <linux/percpu.h>
65470 #include <asm/module.h>
65471 +#include <asm/pgtable.h>
65472
65473 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
65474 #define MODULE_SIG_STRING "~Module signature appended~\n"
65475 @@ -281,19 +283,16 @@ struct module
65476 int (*init)(void);
65477
65478 /* If this is non-NULL, vfree after init() returns */
65479 - void *module_init;
65480 + void *module_init_rx, *module_init_rw;
65481
65482 /* Here is the actual code + data, vfree'd on unload. */
65483 - void *module_core;
65484 + void *module_core_rx, *module_core_rw;
65485
65486 /* Here are the sizes of the init and core sections */
65487 - unsigned int init_size, core_size;
65488 + unsigned int init_size_rw, core_size_rw;
65489
65490 /* The size of the executable code in each section. */
65491 - unsigned int init_text_size, core_text_size;
65492 -
65493 - /* Size of RO sections of the module (text+rodata) */
65494 - unsigned int init_ro_size, core_ro_size;
65495 + unsigned int init_size_rx, core_size_rx;
65496
65497 /* Arch-specific module values */
65498 struct mod_arch_specific arch;
65499 @@ -349,6 +348,10 @@ struct module
65500 #ifdef CONFIG_EVENT_TRACING
65501 struct ftrace_event_call **trace_events;
65502 unsigned int num_trace_events;
65503 + struct file_operations trace_id;
65504 + struct file_operations trace_enable;
65505 + struct file_operations trace_format;
65506 + struct file_operations trace_filter;
65507 #endif
65508 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
65509 unsigned int num_ftrace_callsites;
65510 @@ -396,16 +399,46 @@ bool is_module_address(unsigned long addr);
65511 bool is_module_percpu_address(unsigned long addr);
65512 bool is_module_text_address(unsigned long addr);
65513
65514 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
65515 +{
65516 +
65517 +#ifdef CONFIG_PAX_KERNEXEC
65518 + if (ktla_ktva(addr) >= (unsigned long)start &&
65519 + ktla_ktva(addr) < (unsigned long)start + size)
65520 + return 1;
65521 +#endif
65522 +
65523 + return ((void *)addr >= start && (void *)addr < start + size);
65524 +}
65525 +
65526 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
65527 +{
65528 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
65529 +}
65530 +
65531 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
65532 +{
65533 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
65534 +}
65535 +
65536 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
65537 +{
65538 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
65539 +}
65540 +
65541 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
65542 +{
65543 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
65544 +}
65545 +
65546 static inline int within_module_core(unsigned long addr, struct module *mod)
65547 {
65548 - return (unsigned long)mod->module_core <= addr &&
65549 - addr < (unsigned long)mod->module_core + mod->core_size;
65550 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
65551 }
65552
65553 static inline int within_module_init(unsigned long addr, struct module *mod)
65554 {
65555 - return (unsigned long)mod->module_init <= addr &&
65556 - addr < (unsigned long)mod->module_init + mod->init_size;
65557 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
65558 }
65559
65560 /* Search for module by name: must hold module_mutex. */
65561 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
65562 index 560ca53..5ee8d73 100644
65563 --- a/include/linux/moduleloader.h
65564 +++ b/include/linux/moduleloader.h
65565 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
65566
65567 /* Allocator used for allocating struct module, core sections and init
65568 sections. Returns NULL on failure. */
65569 -void *module_alloc(unsigned long size);
65570 +void *module_alloc(unsigned long size) __size_overflow(1);
65571 +
65572 +#ifdef CONFIG_PAX_KERNEXEC
65573 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
65574 +#else
65575 +#define module_alloc_exec(x) module_alloc(x)
65576 +#endif
65577
65578 /* Free memory returned from module_alloc. */
65579 void module_free(struct module *mod, void *module_region);
65580
65581 +#ifdef CONFIG_PAX_KERNEXEC
65582 +void module_free_exec(struct module *mod, void *module_region);
65583 +#else
65584 +#define module_free_exec(x, y) module_free((x), (y))
65585 +#endif
65586 +
65587 /*
65588 * Apply the given relocation to the (simplified) ELF. Return -error
65589 * or 0.
65590 @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
65591 unsigned int relsec,
65592 struct module *me)
65593 {
65594 +#ifdef CONFIG_MODULES
65595 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
65596 +#endif
65597 return -ENOEXEC;
65598 }
65599 #endif
65600 @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
65601 unsigned int relsec,
65602 struct module *me)
65603 {
65604 +#ifdef CONFIG_MODULES
65605 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
65606 +#endif
65607 return -ENOEXEC;
65608 }
65609 #endif
65610 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
65611 index d6a5806..7c13347 100644
65612 --- a/include/linux/moduleparam.h
65613 +++ b/include/linux/moduleparam.h
65614 @@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
65615 * @len is usually just sizeof(string).
65616 */
65617 #define module_param_string(name, string, len, perm) \
65618 - static const struct kparam_string __param_string_##name \
65619 + static const struct kparam_string __param_string_##name __used \
65620 = { len, string }; \
65621 __module_param_call(MODULE_PARAM_PREFIX, name, \
65622 &param_ops_string, \
65623 @@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
65624 */
65625 #define module_param_array_named(name, array, type, nump, perm) \
65626 param_check_##type(name, &(array)[0]); \
65627 - static const struct kparam_array __param_arr_##name \
65628 + static const struct kparam_array __param_arr_##name __used \
65629 = { .max = ARRAY_SIZE(array), .num = nump, \
65630 .ops = &param_ops_##type, \
65631 .elemsize = sizeof(array[0]), .elem = array }; \
65632 diff --git a/include/linux/namei.h b/include/linux/namei.h
65633 index 4bf19d8..5268cea 100644
65634 --- a/include/linux/namei.h
65635 +++ b/include/linux/namei.h
65636 @@ -18,7 +18,7 @@ struct nameidata {
65637 unsigned seq;
65638 int last_type;
65639 unsigned depth;
65640 - char *saved_names[MAX_NESTED_LINKS + 1];
65641 + const char *saved_names[MAX_NESTED_LINKS + 1];
65642 };
65643
65644 /*
65645 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
65646
65647 extern void nd_jump_link(struct nameidata *nd, struct path *path);
65648
65649 -static inline void nd_set_link(struct nameidata *nd, char *path)
65650 +static inline void nd_set_link(struct nameidata *nd, const char *path)
65651 {
65652 nd->saved_names[nd->depth] = path;
65653 }
65654
65655 -static inline char *nd_get_link(struct nameidata *nd)
65656 +static inline const char *nd_get_link(const struct nameidata *nd)
65657 {
65658 return nd->saved_names[nd->depth];
65659 }
65660 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
65661 index a848ffc..3bbbaee 100644
65662 --- a/include/linux/netdevice.h
65663 +++ b/include/linux/netdevice.h
65664 @@ -999,6 +999,7 @@ struct net_device_ops {
65665 struct net_device *dev,
65666 int idx);
65667 };
65668 +typedef struct net_device_ops __no_const net_device_ops_no_const;
65669
65670 /*
65671 * The DEVICE structure.
65672 @@ -1059,7 +1060,7 @@ struct net_device {
65673 int iflink;
65674
65675 struct net_device_stats stats;
65676 - atomic_long_t rx_dropped; /* dropped packets by core network
65677 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
65678 * Do not use this in drivers.
65679 */
65680
65681 diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
65682 index 7958e84..ed74d7a 100644
65683 --- a/include/linux/netfilter/ipset/ip_set.h
65684 +++ b/include/linux/netfilter/ipset/ip_set.h
65685 @@ -98,7 +98,7 @@ struct ip_set_type_variant {
65686 /* Return true if "b" set is the same as "a"
65687 * according to the create set parameters */
65688 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
65689 -};
65690 +} __do_const;
65691
65692 /* The core set type structure */
65693 struct ip_set_type {
65694 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
65695 index 4966dde..7d8ce06 100644
65696 --- a/include/linux/netfilter/nfnetlink.h
65697 +++ b/include/linux/netfilter/nfnetlink.h
65698 @@ -16,7 +16,7 @@ struct nfnl_callback {
65699 const struct nlattr * const cda[]);
65700 const struct nla_policy *policy; /* netlink attribute policy */
65701 const u_int16_t attr_count; /* number of nlattr's */
65702 -};
65703 +} __do_const;
65704
65705 struct nfnetlink_subsystem {
65706 const char *name;
65707 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
65708 new file mode 100644
65709 index 0000000..33f4af8
65710 --- /dev/null
65711 +++ b/include/linux/netfilter/xt_gradm.h
65712 @@ -0,0 +1,9 @@
65713 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
65714 +#define _LINUX_NETFILTER_XT_GRADM_H 1
65715 +
65716 +struct xt_gradm_mtinfo {
65717 + __u16 flags;
65718 + __u16 invflags;
65719 +};
65720 +
65721 +#endif
65722 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
65723 index d65746e..62e72c2 100644
65724 --- a/include/linux/notifier.h
65725 +++ b/include/linux/notifier.h
65726 @@ -51,7 +51,8 @@ struct notifier_block {
65727 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
65728 struct notifier_block __rcu *next;
65729 int priority;
65730 -};
65731 +} __do_const;
65732 +typedef struct notifier_block __no_const notifier_block_no_const;
65733
65734 struct atomic_notifier_head {
65735 spinlock_t lock;
65736 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
65737 index a4c5624..79d6d88 100644
65738 --- a/include/linux/oprofile.h
65739 +++ b/include/linux/oprofile.h
65740 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
65741 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
65742 char const * name, ulong * val);
65743
65744 -/** Create a file for read-only access to an atomic_t. */
65745 +/** Create a file for read-only access to an atomic_unchecked_t. */
65746 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
65747 - char const * name, atomic_t * val);
65748 + char const * name, atomic_unchecked_t * val);
65749
65750 /** create a directory */
65751 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
65752 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
65753 index 6bfb2faa..1204767 100644
65754 --- a/include/linux/perf_event.h
65755 +++ b/include/linux/perf_event.h
65756 @@ -328,8 +328,8 @@ struct perf_event {
65757
65758 enum perf_event_active_state state;
65759 unsigned int attach_state;
65760 - local64_t count;
65761 - atomic64_t child_count;
65762 + local64_t count; /* PaX: fix it one day */
65763 + atomic64_unchecked_t child_count;
65764
65765 /*
65766 * These are the total time in nanoseconds that the event
65767 @@ -380,8 +380,8 @@ struct perf_event {
65768 * These accumulate total time (in nanoseconds) that children
65769 * events have been enabled and running, respectively.
65770 */
65771 - atomic64_t child_total_time_enabled;
65772 - atomic64_t child_total_time_running;
65773 + atomic64_unchecked_t child_total_time_enabled;
65774 + atomic64_unchecked_t child_total_time_running;
65775
65776 /*
65777 * Protect attach/detach and child_list:
65778 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
65779 index ad1a427..6419649 100644
65780 --- a/include/linux/pipe_fs_i.h
65781 +++ b/include/linux/pipe_fs_i.h
65782 @@ -45,9 +45,9 @@ struct pipe_buffer {
65783 struct pipe_inode_info {
65784 wait_queue_head_t wait;
65785 unsigned int nrbufs, curbuf, buffers;
65786 - unsigned int readers;
65787 - unsigned int writers;
65788 - unsigned int waiting_writers;
65789 + atomic_t readers;
65790 + atomic_t writers;
65791 + atomic_t waiting_writers;
65792 unsigned int r_counter;
65793 unsigned int w_counter;
65794 struct page *tmp_page;
65795 diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
65796 index 5f28cae..3d23723 100644
65797 --- a/include/linux/platform_data/usb-ehci-s5p.h
65798 +++ b/include/linux/platform_data/usb-ehci-s5p.h
65799 @@ -14,7 +14,7 @@
65800 struct s5p_ehci_platdata {
65801 int (*phy_init)(struct platform_device *pdev, int type);
65802 int (*phy_exit)(struct platform_device *pdev, int type);
65803 -};
65804 +} __no_const;
65805
65806 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
65807
65808 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
65809 index f271860..6b3bec5 100644
65810 --- a/include/linux/pm_runtime.h
65811 +++ b/include/linux/pm_runtime.h
65812 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
65813
65814 static inline void pm_runtime_mark_last_busy(struct device *dev)
65815 {
65816 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
65817 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
65818 }
65819
65820 #else /* !CONFIG_PM_RUNTIME */
65821 diff --git a/include/linux/poison.h b/include/linux/poison.h
65822 index 2110a81..13a11bb 100644
65823 --- a/include/linux/poison.h
65824 +++ b/include/linux/poison.h
65825 @@ -19,8 +19,8 @@
65826 * under normal circumstances, used to verify that nobody uses
65827 * non-initialized list entries.
65828 */
65829 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
65830 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
65831 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
65832 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
65833
65834 /********** include/linux/timer.h **********/
65835 /*
65836 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
65837 index 4a496eb..d9c5659 100644
65838 --- a/include/linux/power/smartreflex.h
65839 +++ b/include/linux/power/smartreflex.h
65840 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
65841 int (*notify)(struct omap_sr *sr, u32 status);
65842 u8 notify_flags;
65843 u8 class_type;
65844 -};
65845 +} __do_const;
65846
65847 /**
65848 * struct omap_sr_nvalue_table - Smartreflex n-target value info
65849 diff --git a/include/linux/printk.h b/include/linux/printk.h
65850 index 9afc01e..92c32e8 100644
65851 --- a/include/linux/printk.h
65852 +++ b/include/linux/printk.h
65853 @@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
65854 extern int printk_needs_cpu(int cpu);
65855 extern void printk_tick(void);
65856
65857 +extern int kptr_restrict;
65858 +
65859 #ifdef CONFIG_PRINTK
65860 asmlinkage __printf(5, 0)
65861 int vprintk_emit(int facility, int level,
65862 @@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
65863
65864 extern int printk_delay_msec;
65865 extern int dmesg_restrict;
65866 -extern int kptr_restrict;
65867
65868 void log_buf_kexec_setup(void);
65869 void __init setup_log_buf(int early);
65870 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
65871 index 3fd2e87..75db910 100644
65872 --- a/include/linux/proc_fs.h
65873 +++ b/include/linux/proc_fs.h
65874 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
65875 return proc_create_data(name, mode, parent, proc_fops, NULL);
65876 }
65877
65878 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
65879 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
65880 +{
65881 +#ifdef CONFIG_GRKERNSEC_PROC_USER
65882 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
65883 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65884 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
65885 +#else
65886 + return proc_create_data(name, mode, parent, proc_fops, NULL);
65887 +#endif
65888 +}
65889 +
65890 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
65891 umode_t mode, struct proc_dir_entry *base,
65892 read_proc_t *read_proc, void * data)
65893 diff --git a/include/linux/random.h b/include/linux/random.h
65894 index 6330ed4..419c6c3 100644
65895 --- a/include/linux/random.h
65896 +++ b/include/linux/random.h
65897 @@ -30,12 +30,17 @@ void srandom32(u32 seed);
65898
65899 u32 prandom32(struct rnd_state *);
65900
65901 +static inline unsigned long pax_get_random_long(void)
65902 +{
65903 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
65904 +}
65905 +
65906 /*
65907 * Handle minimum values for seeds
65908 */
65909 static inline u32 __seed(u32 x, u32 m)
65910 {
65911 - return (x < m) ? x + m : x;
65912 + return (x <= m) ? x + m + 1 : x;
65913 }
65914
65915 /**
65916 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
65917 index 23b3630..e1bc12b 100644
65918 --- a/include/linux/reboot.h
65919 +++ b/include/linux/reboot.h
65920 @@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
65921 * Architecture-specific implementations of sys_reboot commands.
65922 */
65923
65924 -extern void machine_restart(char *cmd);
65925 -extern void machine_halt(void);
65926 -extern void machine_power_off(void);
65927 +extern void machine_restart(char *cmd) __noreturn;
65928 +extern void machine_halt(void) __noreturn;
65929 +extern void machine_power_off(void) __noreturn;
65930
65931 extern void machine_shutdown(void);
65932 struct pt_regs;
65933 @@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
65934 */
65935
65936 extern void kernel_restart_prepare(char *cmd);
65937 -extern void kernel_restart(char *cmd);
65938 -extern void kernel_halt(void);
65939 -extern void kernel_power_off(void);
65940 +extern void kernel_restart(char *cmd) __noreturn;
65941 +extern void kernel_halt(void) __noreturn;
65942 +extern void kernel_power_off(void) __noreturn;
65943
65944 extern int C_A_D; /* for sysctl */
65945 void ctrl_alt_del(void);
65946 @@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
65947 * Emergency restart, callable from an interrupt handler.
65948 */
65949
65950 -extern void emergency_restart(void);
65951 +extern void emergency_restart(void) __noreturn;
65952 #include <asm/emergency-restart.h>
65953
65954 #endif /* _LINUX_REBOOT_H */
65955 diff --git a/include/linux/regset.h b/include/linux/regset.h
65956 index 8e0c9fe..fdb64bc 100644
65957 --- a/include/linux/regset.h
65958 +++ b/include/linux/regset.h
65959 @@ -161,7 +161,7 @@ struct user_regset {
65960 unsigned int align;
65961 unsigned int bias;
65962 unsigned int core_note_type;
65963 -};
65964 +} __do_const;
65965
65966 /**
65967 * struct user_regset_view - available regsets
65968 diff --git a/include/linux/relay.h b/include/linux/relay.h
65969 index 91cacc3..b55ff74 100644
65970 --- a/include/linux/relay.h
65971 +++ b/include/linux/relay.h
65972 @@ -160,7 +160,7 @@ struct rchan_callbacks
65973 * The callback should return 0 if successful, negative if not.
65974 */
65975 int (*remove_buf_file)(struct dentry *dentry);
65976 -};
65977 +} __no_const;
65978
65979 /*
65980 * CONFIG_RELAY kernel API, kernel/relay.c
65981 diff --git a/include/linux/rio.h b/include/linux/rio.h
65982 index a3e7842..d973ca6 100644
65983 --- a/include/linux/rio.h
65984 +++ b/include/linux/rio.h
65985 @@ -339,7 +339,7 @@ struct rio_ops {
65986 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
65987 u64 rstart, u32 size, u32 flags);
65988 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
65989 -};
65990 +} __no_const;
65991
65992 #define RIO_RESOURCE_MEM 0x00000100
65993 #define RIO_RESOURCE_DOORBELL 0x00000200
65994 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
65995 index bfe1f47..6a33ee3 100644
65996 --- a/include/linux/rmap.h
65997 +++ b/include/linux/rmap.h
65998 @@ -134,8 +134,8 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
65999 void anon_vma_init(void); /* create anon_vma_cachep */
66000 int anon_vma_prepare(struct vm_area_struct *);
66001 void unlink_anon_vmas(struct vm_area_struct *);
66002 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
66003 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
66004 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
66005 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
66006
66007 static inline void anon_vma_merge(struct vm_area_struct *vma,
66008 struct vm_area_struct *next)
66009 diff --git a/include/linux/sched.h b/include/linux/sched.h
66010 index 3e63925..6c93b17 100644
66011 --- a/include/linux/sched.h
66012 +++ b/include/linux/sched.h
66013 @@ -61,6 +61,7 @@ struct bio_list;
66014 struct fs_struct;
66015 struct perf_event_context;
66016 struct blk_plug;
66017 +struct linux_binprm;
66018
66019 /*
66020 * List of flags we want to share for kernel threads,
66021 @@ -344,10 +345,23 @@ struct user_namespace;
66022 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
66023
66024 extern int sysctl_max_map_count;
66025 +extern unsigned long sysctl_heap_stack_gap;
66026
66027 #include <linux/aio.h>
66028
66029 #ifdef CONFIG_MMU
66030 +
66031 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
66032 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
66033 +#else
66034 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
66035 +{
66036 + return 0;
66037 +}
66038 +#endif
66039 +
66040 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
66041 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
66042 extern void arch_pick_mmap_layout(struct mm_struct *mm);
66043 extern unsigned long
66044 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
66045 @@ -614,6 +628,17 @@ struct signal_struct {
66046 #ifdef CONFIG_TASKSTATS
66047 struct taskstats *stats;
66048 #endif
66049 +
66050 +#ifdef CONFIG_GRKERNSEC
66051 + u32 curr_ip;
66052 + u32 saved_ip;
66053 + u32 gr_saddr;
66054 + u32 gr_daddr;
66055 + u16 gr_sport;
66056 + u16 gr_dport;
66057 + u8 used_accept:1;
66058 +#endif
66059 +
66060 #ifdef CONFIG_AUDIT
66061 unsigned audit_tty;
66062 struct tty_audit_buf *tty_audit_buf;
66063 @@ -691,6 +716,11 @@ struct user_struct {
66064 struct key *session_keyring; /* UID's default session keyring */
66065 #endif
66066
66067 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
66068 + unsigned int banned;
66069 + unsigned long ban_expires;
66070 +#endif
66071 +
66072 /* Hash table maintenance information */
66073 struct hlist_node uidhash_node;
66074 kuid_t uid;
66075 @@ -1312,8 +1342,8 @@ struct task_struct {
66076 struct list_head thread_group;
66077
66078 struct completion *vfork_done; /* for vfork() */
66079 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
66080 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
66081 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
66082 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
66083
66084 cputime_t utime, stime, utimescaled, stimescaled;
66085 cputime_t gtime;
66086 @@ -1329,11 +1359,6 @@ struct task_struct {
66087 struct task_cputime cputime_expires;
66088 struct list_head cpu_timers[3];
66089
66090 -/* process credentials */
66091 - const struct cred __rcu *real_cred; /* objective and real subjective task
66092 - * credentials (COW) */
66093 - const struct cred __rcu *cred; /* effective (overridable) subjective task
66094 - * credentials (COW) */
66095 char comm[TASK_COMM_LEN]; /* executable name excluding path
66096 - access with [gs]et_task_comm (which lock
66097 it with task_lock())
66098 @@ -1350,6 +1375,10 @@ struct task_struct {
66099 #endif
66100 /* CPU-specific state of this task */
66101 struct thread_struct thread;
66102 +/* thread_info moved to task_struct */
66103 +#ifdef CONFIG_X86
66104 + struct thread_info tinfo;
66105 +#endif
66106 /* filesystem information */
66107 struct fs_struct *fs;
66108 /* open file information */
66109 @@ -1423,6 +1452,10 @@ struct task_struct {
66110 gfp_t lockdep_reclaim_gfp;
66111 #endif
66112
66113 +/* process credentials */
66114 + const struct cred __rcu *real_cred; /* objective and real subjective task
66115 + * credentials (COW) */
66116 +
66117 /* journalling filesystem info */
66118 void *journal_info;
66119
66120 @@ -1461,6 +1494,10 @@ struct task_struct {
66121 /* cg_list protected by css_set_lock and tsk->alloc_lock */
66122 struct list_head cg_list;
66123 #endif
66124 +
66125 + const struct cred __rcu *cred; /* effective (overridable) subjective task
66126 + * credentials (COW) */
66127 +
66128 #ifdef CONFIG_FUTEX
66129 struct robust_list_head __user *robust_list;
66130 #ifdef CONFIG_COMPAT
66131 @@ -1548,8 +1585,74 @@ struct task_struct {
66132 #ifdef CONFIG_UPROBES
66133 struct uprobe_task *utask;
66134 #endif
66135 +
66136 +#ifdef CONFIG_GRKERNSEC
66137 + /* grsecurity */
66138 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66139 + u64 exec_id;
66140 +#endif
66141 +#ifdef CONFIG_GRKERNSEC_SETXID
66142 + const struct cred *delayed_cred;
66143 +#endif
66144 + struct dentry *gr_chroot_dentry;
66145 + struct acl_subject_label *acl;
66146 + struct acl_role_label *role;
66147 + struct file *exec_file;
66148 + unsigned long brute_expires;
66149 + u16 acl_role_id;
66150 + /* is this the task that authenticated to the special role */
66151 + u8 acl_sp_role;
66152 + u8 is_writable;
66153 + u8 brute;
66154 + u8 gr_is_chrooted;
66155 +#endif
66156 +
66157 };
66158
66159 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
66160 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
66161 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
66162 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
66163 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
66164 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
66165 +
66166 +#ifdef CONFIG_PAX_SOFTMODE
66167 +extern int pax_softmode;
66168 +#endif
66169 +
66170 +extern int pax_check_flags(unsigned long *);
66171 +
66172 +/* if tsk != current then task_lock must be held on it */
66173 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
66174 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
66175 +{
66176 + if (likely(tsk->mm))
66177 + return tsk->mm->pax_flags;
66178 + else
66179 + return 0UL;
66180 +}
66181 +
66182 +/* if tsk != current then task_lock must be held on it */
66183 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
66184 +{
66185 + if (likely(tsk->mm)) {
66186 + tsk->mm->pax_flags = flags;
66187 + return 0;
66188 + }
66189 + return -EINVAL;
66190 +}
66191 +#endif
66192 +
66193 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
66194 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
66195 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
66196 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
66197 +#endif
66198 +
66199 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
66200 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
66201 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
66202 +
66203 /* Future-safe accessor for struct task_struct's cpus_allowed. */
66204 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
66205
66206 @@ -2092,7 +2195,9 @@ void yield(void);
66207 extern struct exec_domain default_exec_domain;
66208
66209 union thread_union {
66210 +#ifndef CONFIG_X86
66211 struct thread_info thread_info;
66212 +#endif
66213 unsigned long stack[THREAD_SIZE/sizeof(long)];
66214 };
66215
66216 @@ -2125,6 +2230,7 @@ extern struct pid_namespace init_pid_ns;
66217 */
66218
66219 extern struct task_struct *find_task_by_vpid(pid_t nr);
66220 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
66221 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
66222 struct pid_namespace *ns);
66223
66224 @@ -2281,7 +2387,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
66225 extern void exit_itimers(struct signal_struct *);
66226 extern void flush_itimer_signals(void);
66227
66228 -extern void do_group_exit(int);
66229 +extern __noreturn void do_group_exit(int);
66230
66231 extern void daemonize(const char *, ...);
66232 extern int allow_signal(int);
66233 @@ -2485,9 +2591,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
66234
66235 #endif
66236
66237 -static inline int object_is_on_stack(void *obj)
66238 +static inline int object_starts_on_stack(void *obj)
66239 {
66240 - void *stack = task_stack_page(current);
66241 + const void *stack = task_stack_page(current);
66242
66243 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
66244 }
66245 diff --git a/include/linux/security.h b/include/linux/security.h
66246 index 05e88bd..5cda002 100644
66247 --- a/include/linux/security.h
66248 +++ b/include/linux/security.h
66249 @@ -26,6 +26,7 @@
66250 #include <linux/capability.h>
66251 #include <linux/slab.h>
66252 #include <linux/err.h>
66253 +#include <linux/grsecurity.h>
66254
66255 struct linux_binprm;
66256 struct cred;
66257 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
66258 index 68a04a3..866e6a1 100644
66259 --- a/include/linux/seq_file.h
66260 +++ b/include/linux/seq_file.h
66261 @@ -26,6 +26,9 @@ struct seq_file {
66262 struct mutex lock;
66263 const struct seq_operations *op;
66264 int poll_event;
66265 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66266 + u64 exec_id;
66267 +#endif
66268 #ifdef CONFIG_USER_NS
66269 struct user_namespace *user_ns;
66270 #endif
66271 @@ -38,6 +41,7 @@ struct seq_operations {
66272 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
66273 int (*show) (struct seq_file *m, void *v);
66274 };
66275 +typedef struct seq_operations __no_const seq_operations_no_const;
66276
66277 #define SEQ_SKIP 1
66278
66279 diff --git a/include/linux/shm.h b/include/linux/shm.h
66280 index bcf8a6a..4d0af77 100644
66281 --- a/include/linux/shm.h
66282 +++ b/include/linux/shm.h
66283 @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
66284
66285 /* The task created the shm object. NULL if the task is dead. */
66286 struct task_struct *shm_creator;
66287 +#ifdef CONFIG_GRKERNSEC
66288 + time_t shm_createtime;
66289 + pid_t shm_lapid;
66290 +#endif
66291 };
66292
66293 /* shm_mode upper byte flags */
66294 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
66295 index 6a2c34e..a1f320f 100644
66296 --- a/include/linux/skbuff.h
66297 +++ b/include/linux/skbuff.h
66298 @@ -577,7 +577,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
66299 extern struct sk_buff *__alloc_skb(unsigned int size,
66300 gfp_t priority, int flags, int node);
66301 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
66302 -static inline struct sk_buff *alloc_skb(unsigned int size,
66303 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
66304 gfp_t priority)
66305 {
66306 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
66307 @@ -687,7 +687,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
66308 */
66309 static inline int skb_queue_empty(const struct sk_buff_head *list)
66310 {
66311 - return list->next == (struct sk_buff *)list;
66312 + return list->next == (const struct sk_buff *)list;
66313 }
66314
66315 /**
66316 @@ -700,7 +700,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
66317 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
66318 const struct sk_buff *skb)
66319 {
66320 - return skb->next == (struct sk_buff *)list;
66321 + return skb->next == (const struct sk_buff *)list;
66322 }
66323
66324 /**
66325 @@ -713,7 +713,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
66326 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
66327 const struct sk_buff *skb)
66328 {
66329 - return skb->prev == (struct sk_buff *)list;
66330 + return skb->prev == (const struct sk_buff *)list;
66331 }
66332
66333 /**
66334 @@ -1626,7 +1626,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
66335 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
66336 */
66337 #ifndef NET_SKB_PAD
66338 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
66339 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
66340 #endif
66341
66342 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
66343 @@ -2204,7 +2204,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
66344 int noblock, int *err);
66345 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
66346 struct poll_table_struct *wait);
66347 -extern int skb_copy_datagram_iovec(const struct sk_buff *from,
66348 +extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
66349 int offset, struct iovec *to,
66350 int size);
66351 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
66352 diff --git a/include/linux/slab.h b/include/linux/slab.h
66353 index 83d1a14..e23d723 100644
66354 --- a/include/linux/slab.h
66355 +++ b/include/linux/slab.h
66356 @@ -11,12 +11,20 @@
66357
66358 #include <linux/gfp.h>
66359 #include <linux/types.h>
66360 +#include <linux/err.h>
66361
66362 /*
66363 * Flags to pass to kmem_cache_create().
66364 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
66365 */
66366 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
66367 +
66368 +#ifdef CONFIG_PAX_USERCOPY_SLABS
66369 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
66370 +#else
66371 +#define SLAB_USERCOPY 0x00000000UL
66372 +#endif
66373 +
66374 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
66375 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
66376 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
66377 @@ -87,10 +95,13 @@
66378 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
66379 * Both make kfree a no-op.
66380 */
66381 -#define ZERO_SIZE_PTR ((void *)16)
66382 +#define ZERO_SIZE_PTR \
66383 +({ \
66384 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
66385 + (void *)(-MAX_ERRNO-1L); \
66386 +})
66387
66388 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
66389 - (unsigned long)ZERO_SIZE_PTR)
66390 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
66391
66392 /*
66393 * Common fields provided in kmem_cache by all slab allocators
66394 @@ -110,7 +121,7 @@ struct kmem_cache {
66395 unsigned int align; /* Alignment as calculated */
66396 unsigned long flags; /* Active flags on the slab */
66397 const char *name; /* Slab name for sysfs */
66398 - int refcount; /* Use counter */
66399 + atomic_t refcount; /* Use counter */
66400 void (*ctor)(void *); /* Called on object slot creation */
66401 struct list_head list; /* List of all slab caches on the system */
66402 };
66403 @@ -185,6 +196,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
66404 void kfree(const void *);
66405 void kzfree(const void *);
66406 size_t ksize(const void *);
66407 +const char *check_heap_object(const void *ptr, unsigned long n);
66408 +bool is_usercopy_object(const void *ptr);
66409
66410 /*
66411 * Allocator specific definitions. These are mainly used to establish optimized
66412 @@ -264,8 +277,18 @@ size_t ksize(const void *);
66413 * for general use, and so are not documented here. For a full list of
66414 * potential flags, always refer to linux/gfp.h.
66415 */
66416 +
66417 +extern void kmalloc_array_error(void)
66418 +#if defined(CONFIG_GCOV_KERNEL) && defined(CONFIG_PAX_SIZE_OVERFLOW)
66419 +__compiletime_warning("kmalloc_array called with swapped arguments?");
66420 +#else
66421 +__compiletime_error("kmalloc_array called with swapped arguments?");
66422 +#endif
66423 +
66424 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
66425 {
66426 + if (__builtin_constant_p(n) && !__builtin_constant_p(size))
66427 + kmalloc_array_error();
66428 if (size != 0 && n > SIZE_MAX / size)
66429 return NULL;
66430 return __kmalloc(n * size, flags);
66431 @@ -323,7 +346,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
66432 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
66433 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
66434 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
66435 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
66436 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
66437 #define kmalloc_track_caller(size, flags) \
66438 __kmalloc_track_caller(size, flags, _RET_IP_)
66439 #else
66440 @@ -343,7 +366,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
66441 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
66442 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
66443 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
66444 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
66445 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
66446 #define kmalloc_node_track_caller(size, flags, node) \
66447 __kmalloc_node_track_caller(size, flags, node, \
66448 _RET_IP_)
66449 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
66450 index cc290f0..0ba60931 100644
66451 --- a/include/linux/slab_def.h
66452 +++ b/include/linux/slab_def.h
66453 @@ -52,7 +52,7 @@ struct kmem_cache {
66454 /* 4) cache creation/removal */
66455 const char *name;
66456 struct list_head list;
66457 - int refcount;
66458 + atomic_t refcount;
66459 int object_size;
66460 int align;
66461
66462 @@ -68,10 +68,10 @@ struct kmem_cache {
66463 unsigned long node_allocs;
66464 unsigned long node_frees;
66465 unsigned long node_overflow;
66466 - atomic_t allochit;
66467 - atomic_t allocmiss;
66468 - atomic_t freehit;
66469 - atomic_t freemiss;
66470 + atomic_unchecked_t allochit;
66471 + atomic_unchecked_t allocmiss;
66472 + atomic_unchecked_t freehit;
66473 + atomic_unchecked_t freemiss;
66474
66475 /*
66476 * If debugging is enabled, then the allocator can add additional
66477 @@ -104,11 +104,16 @@ struct cache_sizes {
66478 #ifdef CONFIG_ZONE_DMA
66479 struct kmem_cache *cs_dmacachep;
66480 #endif
66481 +
66482 +#ifdef CONFIG_PAX_USERCOPY_SLABS
66483 + struct kmem_cache *cs_usercopycachep;
66484 +#endif
66485 +
66486 };
66487 extern struct cache_sizes malloc_sizes[];
66488
66489 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
66490 -void *__kmalloc(size_t size, gfp_t flags);
66491 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
66492
66493 #ifdef CONFIG_TRACING
66494 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
66495 @@ -145,6 +150,13 @@ found:
66496 cachep = malloc_sizes[i].cs_dmacachep;
66497 else
66498 #endif
66499 +
66500 +#ifdef CONFIG_PAX_USERCOPY_SLABS
66501 + if (flags & GFP_USERCOPY)
66502 + cachep = malloc_sizes[i].cs_usercopycachep;
66503 + else
66504 +#endif
66505 +
66506 cachep = malloc_sizes[i].cs_cachep;
66507
66508 ret = kmem_cache_alloc_trace(cachep, flags, size);
66509 @@ -155,7 +167,7 @@ found:
66510 }
66511
66512 #ifdef CONFIG_NUMA
66513 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
66514 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
66515 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
66516
66517 #ifdef CONFIG_TRACING
66518 @@ -198,6 +210,13 @@ found:
66519 cachep = malloc_sizes[i].cs_dmacachep;
66520 else
66521 #endif
66522 +
66523 +#ifdef CONFIG_PAX_USERCOPY_SLABS
66524 + if (flags & GFP_USERCOPY)
66525 + cachep = malloc_sizes[i].cs_usercopycachep;
66526 + else
66527 +#endif
66528 +
66529 cachep = malloc_sizes[i].cs_cachep;
66530
66531 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
66532 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
66533 index f28e14a..7831211 100644
66534 --- a/include/linux/slob_def.h
66535 +++ b/include/linux/slob_def.h
66536 @@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
66537 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
66538 }
66539
66540 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
66541 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
66542
66543 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
66544 {
66545 @@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
66546 return __kmalloc_node(size, flags, NUMA_NO_NODE);
66547 }
66548
66549 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
66550 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
66551 {
66552 return kmalloc(size, flags);
66553 }
66554 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
66555 index df448ad..b99e7f6 100644
66556 --- a/include/linux/slub_def.h
66557 +++ b/include/linux/slub_def.h
66558 @@ -91,7 +91,7 @@ struct kmem_cache {
66559 struct kmem_cache_order_objects max;
66560 struct kmem_cache_order_objects min;
66561 gfp_t allocflags; /* gfp flags to use on each alloc */
66562 - int refcount; /* Refcount for slab cache destroy */
66563 + atomic_t refcount; /* Refcount for slab cache destroy */
66564 void (*ctor)(void *);
66565 int inuse; /* Offset to metadata */
66566 int align; /* Alignment */
66567 @@ -152,7 +152,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
66568 * Sorry that the following has to be that ugly but some versions of GCC
66569 * have trouble with constant propagation and loops.
66570 */
66571 -static __always_inline int kmalloc_index(size_t size)
66572 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
66573 {
66574 if (!size)
66575 return 0;
66576 @@ -217,7 +217,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
66577 }
66578
66579 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
66580 -void *__kmalloc(size_t size, gfp_t flags);
66581 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
66582
66583 static __always_inline void *
66584 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
66585 @@ -258,7 +258,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
66586 }
66587 #endif
66588
66589 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
66590 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
66591 {
66592 unsigned int order = get_order(size);
66593 return kmalloc_order_trace(size, flags, order);
66594 @@ -283,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
66595 }
66596
66597 #ifdef CONFIG_NUMA
66598 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
66599 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
66600 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
66601
66602 #ifdef CONFIG_TRACING
66603 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
66604 index 680f9a3..f13aeb0 100644
66605 --- a/include/linux/sonet.h
66606 +++ b/include/linux/sonet.h
66607 @@ -7,7 +7,7 @@
66608 #include <uapi/linux/sonet.h>
66609
66610 struct k_sonet_stats {
66611 -#define __HANDLE_ITEM(i) atomic_t i
66612 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
66613 __SONET_ITEMS
66614 #undef __HANDLE_ITEM
66615 };
66616 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
66617 index 34206b8..f019e06 100644
66618 --- a/include/linux/sunrpc/clnt.h
66619 +++ b/include/linux/sunrpc/clnt.h
66620 @@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
66621 {
66622 switch (sap->sa_family) {
66623 case AF_INET:
66624 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
66625 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
66626 case AF_INET6:
66627 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
66628 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
66629 }
66630 return 0;
66631 }
66632 @@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
66633 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
66634 const struct sockaddr *src)
66635 {
66636 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
66637 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
66638 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
66639
66640 dsin->sin_family = ssin->sin_family;
66641 @@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
66642 if (sa->sa_family != AF_INET6)
66643 return 0;
66644
66645 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
66646 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
66647 }
66648
66649 #endif /* __KERNEL__ */
66650 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
66651 index 0b8e3e6..33e0a01 100644
66652 --- a/include/linux/sunrpc/svc_rdma.h
66653 +++ b/include/linux/sunrpc/svc_rdma.h
66654 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
66655 extern unsigned int svcrdma_max_requests;
66656 extern unsigned int svcrdma_max_req_size;
66657
66658 -extern atomic_t rdma_stat_recv;
66659 -extern atomic_t rdma_stat_read;
66660 -extern atomic_t rdma_stat_write;
66661 -extern atomic_t rdma_stat_sq_starve;
66662 -extern atomic_t rdma_stat_rq_starve;
66663 -extern atomic_t rdma_stat_rq_poll;
66664 -extern atomic_t rdma_stat_rq_prod;
66665 -extern atomic_t rdma_stat_sq_poll;
66666 -extern atomic_t rdma_stat_sq_prod;
66667 +extern atomic_unchecked_t rdma_stat_recv;
66668 +extern atomic_unchecked_t rdma_stat_read;
66669 +extern atomic_unchecked_t rdma_stat_write;
66670 +extern atomic_unchecked_t rdma_stat_sq_starve;
66671 +extern atomic_unchecked_t rdma_stat_rq_starve;
66672 +extern atomic_unchecked_t rdma_stat_rq_poll;
66673 +extern atomic_unchecked_t rdma_stat_rq_prod;
66674 +extern atomic_unchecked_t rdma_stat_sq_poll;
66675 +extern atomic_unchecked_t rdma_stat_sq_prod;
66676
66677 #define RPCRDMA_VERSION 1
66678
66679 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
66680 index cd844a6..3ca3592 100644
66681 --- a/include/linux/sysctl.h
66682 +++ b/include/linux/sysctl.h
66683 @@ -41,6 +41,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
66684
66685 extern int proc_dostring(struct ctl_table *, int,
66686 void __user *, size_t *, loff_t *);
66687 +extern int proc_dostring_modpriv(struct ctl_table *, int,
66688 + void __user *, size_t *, loff_t *);
66689 extern int proc_dointvec(struct ctl_table *, int,
66690 void __user *, size_t *, loff_t *);
66691 extern int proc_dointvec_minmax(struct ctl_table *, int,
66692 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
66693 index 7faf933..eb6f5e3 100644
66694 --- a/include/linux/sysrq.h
66695 +++ b/include/linux/sysrq.h
66696 @@ -36,7 +36,7 @@ struct sysrq_key_op {
66697 char *help_msg;
66698 char *action_msg;
66699 int enable_mask;
66700 -};
66701 +} __do_const;
66702
66703 #ifdef CONFIG_MAGIC_SYSRQ
66704
66705 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
66706 index ccc1899..b1aaceb 100644
66707 --- a/include/linux/thread_info.h
66708 +++ b/include/linux/thread_info.h
66709 @@ -146,6 +146,15 @@ static inline bool test_and_clear_restore_sigmask(void)
66710 #error "no set_restore_sigmask() provided and default one won't work"
66711 #endif
66712
66713 +extern void __check_object_size(const void *ptr, unsigned long n, bool to);
66714 +static inline void check_object_size(const void *ptr, unsigned long n, bool to)
66715 +{
66716 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
66717 + if (!__builtin_constant_p(n))
66718 +#endif
66719 + __check_object_size(ptr, n, to);
66720 +}
66721 +
66722 #endif /* __KERNEL__ */
66723
66724 #endif /* _LINUX_THREAD_INFO_H */
66725 diff --git a/include/linux/tty.h b/include/linux/tty.h
66726 index f0b4eb4..1c4854e 100644
66727 --- a/include/linux/tty.h
66728 +++ b/include/linux/tty.h
66729 @@ -192,7 +192,7 @@ struct tty_port {
66730 const struct tty_port_operations *ops; /* Port operations */
66731 spinlock_t lock; /* Lock protecting tty field */
66732 int blocked_open; /* Waiting to open */
66733 - int count; /* Usage count */
66734 + atomic_t count; /* Usage count */
66735 wait_queue_head_t open_wait; /* Open waiters */
66736 wait_queue_head_t close_wait; /* Close waiters */
66737 wait_queue_head_t delta_msr_wait; /* Modem status change */
66738 @@ -513,7 +513,7 @@ extern int tty_port_open(struct tty_port *port,
66739 struct tty_struct *tty, struct file *filp);
66740 static inline int tty_port_users(struct tty_port *port)
66741 {
66742 - return port->count + port->blocked_open;
66743 + return atomic_read(&port->count) + port->blocked_open;
66744 }
66745
66746 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
66747 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
66748 index dd976cf..e272742 100644
66749 --- a/include/linux/tty_driver.h
66750 +++ b/include/linux/tty_driver.h
66751 @@ -284,7 +284,7 @@ struct tty_operations {
66752 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
66753 #endif
66754 const struct file_operations *proc_fops;
66755 -};
66756 +} __do_const;
66757
66758 struct tty_driver {
66759 int magic; /* magic number for this structure */
66760 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
66761 index fb79dd8d..07d4773 100644
66762 --- a/include/linux/tty_ldisc.h
66763 +++ b/include/linux/tty_ldisc.h
66764 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
66765
66766 struct module *owner;
66767
66768 - int refcount;
66769 + atomic_t refcount;
66770 };
66771
66772 struct tty_ldisc {
66773 diff --git a/include/linux/types.h b/include/linux/types.h
66774 index 1cc0e4b..0d50edf 100644
66775 --- a/include/linux/types.h
66776 +++ b/include/linux/types.h
66777 @@ -175,10 +175,26 @@ typedef struct {
66778 int counter;
66779 } atomic_t;
66780
66781 +#ifdef CONFIG_PAX_REFCOUNT
66782 +typedef struct {
66783 + int counter;
66784 +} atomic_unchecked_t;
66785 +#else
66786 +typedef atomic_t atomic_unchecked_t;
66787 +#endif
66788 +
66789 #ifdef CONFIG_64BIT
66790 typedef struct {
66791 long counter;
66792 } atomic64_t;
66793 +
66794 +#ifdef CONFIG_PAX_REFCOUNT
66795 +typedef struct {
66796 + long counter;
66797 +} atomic64_unchecked_t;
66798 +#else
66799 +typedef atomic64_t atomic64_unchecked_t;
66800 +#endif
66801 #endif
66802
66803 struct list_head {
66804 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
66805 index 5ca0951..ab496a5 100644
66806 --- a/include/linux/uaccess.h
66807 +++ b/include/linux/uaccess.h
66808 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
66809 long ret; \
66810 mm_segment_t old_fs = get_fs(); \
66811 \
66812 - set_fs(KERNEL_DS); \
66813 pagefault_disable(); \
66814 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
66815 - pagefault_enable(); \
66816 + set_fs(KERNEL_DS); \
66817 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
66818 set_fs(old_fs); \
66819 + pagefault_enable(); \
66820 ret; \
66821 })
66822
66823 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
66824 index 99c1b4d..bb94261 100644
66825 --- a/include/linux/unaligned/access_ok.h
66826 +++ b/include/linux/unaligned/access_ok.h
66827 @@ -6,32 +6,32 @@
66828
66829 static inline u16 get_unaligned_le16(const void *p)
66830 {
66831 - return le16_to_cpup((__le16 *)p);
66832 + return le16_to_cpup((const __le16 *)p);
66833 }
66834
66835 static inline u32 get_unaligned_le32(const void *p)
66836 {
66837 - return le32_to_cpup((__le32 *)p);
66838 + return le32_to_cpup((const __le32 *)p);
66839 }
66840
66841 static inline u64 get_unaligned_le64(const void *p)
66842 {
66843 - return le64_to_cpup((__le64 *)p);
66844 + return le64_to_cpup((const __le64 *)p);
66845 }
66846
66847 static inline u16 get_unaligned_be16(const void *p)
66848 {
66849 - return be16_to_cpup((__be16 *)p);
66850 + return be16_to_cpup((const __be16 *)p);
66851 }
66852
66853 static inline u32 get_unaligned_be32(const void *p)
66854 {
66855 - return be32_to_cpup((__be32 *)p);
66856 + return be32_to_cpup((const __be32 *)p);
66857 }
66858
66859 static inline u64 get_unaligned_be64(const void *p)
66860 {
66861 - return be64_to_cpup((__be64 *)p);
66862 + return be64_to_cpup((const __be64 *)p);
66863 }
66864
66865 static inline void put_unaligned_le16(u16 val, void *p)
66866 diff --git a/include/linux/usb.h b/include/linux/usb.h
66867 index 10278d1..e21ec3c 100644
66868 --- a/include/linux/usb.h
66869 +++ b/include/linux/usb.h
66870 @@ -551,7 +551,7 @@ struct usb_device {
66871 int maxchild;
66872
66873 u32 quirks;
66874 - atomic_t urbnum;
66875 + atomic_unchecked_t urbnum;
66876
66877 unsigned long active_duration;
66878
66879 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
66880 index c5d36c6..108f4f9 100644
66881 --- a/include/linux/usb/renesas_usbhs.h
66882 +++ b/include/linux/usb/renesas_usbhs.h
66883 @@ -39,7 +39,7 @@ enum {
66884 */
66885 struct renesas_usbhs_driver_callback {
66886 int (*notify_hotplug)(struct platform_device *pdev);
66887 -};
66888 +} __no_const;
66889
66890 /*
66891 * callback functions for platform
66892 diff --git a/include/linux/usb/usbnet.h b/include/linux/usb/usbnet.h
66893 index ddbbb7d..9134611 100644
66894 --- a/include/linux/usb/usbnet.h
66895 +++ b/include/linux/usb/usbnet.h
66896 @@ -33,6 +33,7 @@ struct usbnet {
66897 wait_queue_head_t *wait;
66898 struct mutex phy_mutex;
66899 unsigned char suspend_count;
66900 + unsigned char pkt_cnt, pkt_err;
66901
66902 /* i/o info: pipes etc */
66903 unsigned in, out;
66904 @@ -69,6 +70,8 @@ struct usbnet {
66905 # define EVENT_DEV_ASLEEP 6
66906 # define EVENT_DEV_OPEN 7
66907 # define EVENT_DEVICE_REPORT_IDLE 8
66908 +# define EVENT_NO_RUNTIME_PM 9
66909 +# define EVENT_RX_KILL 10
66910 };
66911
66912 static inline struct usb_driver *driver_of(struct usb_interface *intf)
66913 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
66914 index 6f8fbcf..8259001 100644
66915 --- a/include/linux/vermagic.h
66916 +++ b/include/linux/vermagic.h
66917 @@ -25,9 +25,35 @@
66918 #define MODULE_ARCH_VERMAGIC ""
66919 #endif
66920
66921 +#ifdef CONFIG_PAX_REFCOUNT
66922 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
66923 +#else
66924 +#define MODULE_PAX_REFCOUNT ""
66925 +#endif
66926 +
66927 +#ifdef CONSTIFY_PLUGIN
66928 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
66929 +#else
66930 +#define MODULE_CONSTIFY_PLUGIN ""
66931 +#endif
66932 +
66933 +#ifdef STACKLEAK_PLUGIN
66934 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
66935 +#else
66936 +#define MODULE_STACKLEAK_PLUGIN ""
66937 +#endif
66938 +
66939 +#ifdef CONFIG_GRKERNSEC
66940 +#define MODULE_GRSEC "GRSEC "
66941 +#else
66942 +#define MODULE_GRSEC ""
66943 +#endif
66944 +
66945 #define VERMAGIC_STRING \
66946 UTS_RELEASE " " \
66947 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
66948 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
66949 - MODULE_ARCH_VERMAGIC
66950 + MODULE_ARCH_VERMAGIC \
66951 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
66952 + MODULE_GRSEC
66953
66954 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
66955 index 6071e91..ca6a489 100644
66956 --- a/include/linux/vmalloc.h
66957 +++ b/include/linux/vmalloc.h
66958 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
66959 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
66960 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
66961 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
66962 +
66963 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
66964 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
66965 +#endif
66966 +
66967 /* bits [20..32] reserved for arch specific ioremap internals */
66968
66969 /*
66970 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
66971 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
66972 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
66973 unsigned long start, unsigned long end, gfp_t gfp_mask,
66974 - pgprot_t prot, int node, const void *caller);
66975 + pgprot_t prot, int node, const void *caller) __size_overflow(1);
66976 extern void vfree(const void *addr);
66977
66978 extern void *vmap(struct page **pages, unsigned int count,
66979 @@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
66980 extern void free_vm_area(struct vm_struct *area);
66981
66982 /* for /dev/kmem */
66983 -extern long vread(char *buf, char *addr, unsigned long count);
66984 -extern long vwrite(char *buf, char *addr, unsigned long count);
66985 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
66986 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
66987
66988 /*
66989 * Internals. Dont't use..
66990 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
66991 index 92a86b2..1d9eb3c 100644
66992 --- a/include/linux/vmstat.h
66993 +++ b/include/linux/vmstat.h
66994 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
66995 /*
66996 * Zone based page accounting with per cpu differentials.
66997 */
66998 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66999 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
67000
67001 static inline void zone_page_state_add(long x, struct zone *zone,
67002 enum zone_stat_item item)
67003 {
67004 - atomic_long_add(x, &zone->vm_stat[item]);
67005 - atomic_long_add(x, &vm_stat[item]);
67006 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
67007 + atomic_long_add_unchecked(x, &vm_stat[item]);
67008 }
67009
67010 static inline unsigned long global_page_state(enum zone_stat_item item)
67011 {
67012 - long x = atomic_long_read(&vm_stat[item]);
67013 + long x = atomic_long_read_unchecked(&vm_stat[item]);
67014 #ifdef CONFIG_SMP
67015 if (x < 0)
67016 x = 0;
67017 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
67018 static inline unsigned long zone_page_state(struct zone *zone,
67019 enum zone_stat_item item)
67020 {
67021 - long x = atomic_long_read(&zone->vm_stat[item]);
67022 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
67023 #ifdef CONFIG_SMP
67024 if (x < 0)
67025 x = 0;
67026 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
67027 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
67028 enum zone_stat_item item)
67029 {
67030 - long x = atomic_long_read(&zone->vm_stat[item]);
67031 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
67032
67033 #ifdef CONFIG_SMP
67034 int cpu;
67035 @@ -218,8 +218,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
67036
67037 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
67038 {
67039 - atomic_long_inc(&zone->vm_stat[item]);
67040 - atomic_long_inc(&vm_stat[item]);
67041 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
67042 + atomic_long_inc_unchecked(&vm_stat[item]);
67043 }
67044
67045 static inline void __inc_zone_page_state(struct page *page,
67046 @@ -230,8 +230,8 @@ static inline void __inc_zone_page_state(struct page *page,
67047
67048 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
67049 {
67050 - atomic_long_dec(&zone->vm_stat[item]);
67051 - atomic_long_dec(&vm_stat[item]);
67052 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
67053 + atomic_long_dec_unchecked(&vm_stat[item]);
67054 }
67055
67056 static inline void __dec_zone_page_state(struct page *page,
67057 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
67058 index 95d1c91..6798cca 100644
67059 --- a/include/media/v4l2-dev.h
67060 +++ b/include/media/v4l2-dev.h
67061 @@ -76,7 +76,7 @@ struct v4l2_file_operations {
67062 int (*mmap) (struct file *, struct vm_area_struct *);
67063 int (*open) (struct file *);
67064 int (*release) (struct file *);
67065 -};
67066 +} __do_const;
67067
67068 /*
67069 * Newer version of video_device, handled by videodev2.c
67070 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
67071 index e48b571..7e40de4 100644
67072 --- a/include/media/v4l2-ioctl.h
67073 +++ b/include/media/v4l2-ioctl.h
67074 @@ -282,7 +282,6 @@ struct v4l2_ioctl_ops {
67075 bool valid_prio, int cmd, void *arg);
67076 };
67077
67078 -
67079 /* v4l debugging and diagnostics */
67080
67081 /* Debug bitmask flags to be used on V4L2 */
67082 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
67083 index 9e5425b..8136ffc 100644
67084 --- a/include/net/caif/cfctrl.h
67085 +++ b/include/net/caif/cfctrl.h
67086 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
67087 void (*radioset_rsp)(void);
67088 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
67089 struct cflayer *client_layer);
67090 -};
67091 +} __no_const;
67092
67093 /* Link Setup Parameters for CAIF-Links. */
67094 struct cfctrl_link_param {
67095 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
67096 struct cfctrl {
67097 struct cfsrvl serv;
67098 struct cfctrl_rsp res;
67099 - atomic_t req_seq_no;
67100 - atomic_t rsp_seq_no;
67101 + atomic_unchecked_t req_seq_no;
67102 + atomic_unchecked_t rsp_seq_no;
67103 struct list_head list;
67104 /* Protects from simultaneous access to first_req list */
67105 spinlock_t info_list_lock;
67106 diff --git a/include/net/flow.h b/include/net/flow.h
67107 index 628e11b..4c475df 100644
67108 --- a/include/net/flow.h
67109 +++ b/include/net/flow.h
67110 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
67111
67112 extern void flow_cache_flush(void);
67113 extern void flow_cache_flush_deferred(void);
67114 -extern atomic_t flow_cache_genid;
67115 +extern atomic_unchecked_t flow_cache_genid;
67116
67117 #endif
67118 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
67119 index e5062c9..48a9a4b 100644
67120 --- a/include/net/gro_cells.h
67121 +++ b/include/net/gro_cells.h
67122 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
67123 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
67124
67125 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
67126 - atomic_long_inc(&dev->rx_dropped);
67127 + atomic_long_inc_unchecked(&dev->rx_dropped);
67128 kfree_skb(skb);
67129 return;
67130 }
67131 @@ -73,8 +73,8 @@ static inline int gro_cells_init(struct gro_cells *gcells, struct net_device *de
67132 int i;
67133
67134 gcells->gro_cells_mask = roundup_pow_of_two(netif_get_num_default_rss_queues()) - 1;
67135 - gcells->cells = kcalloc(sizeof(struct gro_cell),
67136 - gcells->gro_cells_mask + 1,
67137 + gcells->cells = kcalloc(gcells->gro_cells_mask + 1,
67138 + sizeof(struct gro_cell),
67139 GFP_KERNEL);
67140 if (!gcells->cells)
67141 return -ENOMEM;
67142 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
67143 index 1832927..ce39aea 100644
67144 --- a/include/net/inet_connection_sock.h
67145 +++ b/include/net/inet_connection_sock.h
67146 @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
67147 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
67148 int (*bind_conflict)(const struct sock *sk,
67149 const struct inet_bind_bucket *tb, bool relax);
67150 -};
67151 +} __do_const;
67152
67153 /** inet_connection_sock - INET connection oriented sock
67154 *
67155 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
67156 index 53f464d..ba76aaa 100644
67157 --- a/include/net/inetpeer.h
67158 +++ b/include/net/inetpeer.h
67159 @@ -47,8 +47,8 @@ struct inet_peer {
67160 */
67161 union {
67162 struct {
67163 - atomic_t rid; /* Frag reception counter */
67164 - atomic_t ip_id_count; /* IP ID for the next packet */
67165 + atomic_unchecked_t rid; /* Frag reception counter */
67166 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
67167 };
67168 struct rcu_head rcu;
67169 struct inet_peer *gc_next;
67170 @@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
67171 more++;
67172 inet_peer_refcheck(p);
67173 do {
67174 - old = atomic_read(&p->ip_id_count);
67175 + old = atomic_read_unchecked(&p->ip_id_count);
67176 new = old + more;
67177 if (!new)
67178 new = 1;
67179 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
67180 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
67181 return new;
67182 }
67183
67184 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
67185 index 9497be1..5a4fafe 100644
67186 --- a/include/net/ip_fib.h
67187 +++ b/include/net/ip_fib.h
67188 @@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
67189
67190 #define FIB_RES_SADDR(net, res) \
67191 ((FIB_RES_NH(res).nh_saddr_genid == \
67192 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
67193 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
67194 FIB_RES_NH(res).nh_saddr : \
67195 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
67196 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
67197 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
67198 index ee75ccd..2cc2b95 100644
67199 --- a/include/net/ip_vs.h
67200 +++ b/include/net/ip_vs.h
67201 @@ -510,7 +510,7 @@ struct ip_vs_conn {
67202 struct ip_vs_conn *control; /* Master control connection */
67203 atomic_t n_control; /* Number of controlled ones */
67204 struct ip_vs_dest *dest; /* real server */
67205 - atomic_t in_pkts; /* incoming packet counter */
67206 + atomic_unchecked_t in_pkts; /* incoming packet counter */
67207
67208 /* packet transmitter for different forwarding methods. If it
67209 mangles the packet, it must return NF_DROP or better NF_STOLEN,
67210 @@ -648,7 +648,7 @@ struct ip_vs_dest {
67211 __be16 port; /* port number of the server */
67212 union nf_inet_addr addr; /* IP address of the server */
67213 volatile unsigned int flags; /* dest status flags */
67214 - atomic_t conn_flags; /* flags to copy to conn */
67215 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
67216 atomic_t weight; /* server weight */
67217
67218 atomic_t refcnt; /* reference counter */
67219 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
67220 index 80ffde3..968b0f4 100644
67221 --- a/include/net/irda/ircomm_tty.h
67222 +++ b/include/net/irda/ircomm_tty.h
67223 @@ -35,6 +35,7 @@
67224 #include <linux/termios.h>
67225 #include <linux/timer.h>
67226 #include <linux/tty.h> /* struct tty_struct */
67227 +#include <asm/local.h>
67228
67229 #include <net/irda/irias_object.h>
67230 #include <net/irda/ircomm_core.h>
67231 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
67232 index cc7c197..9f2da2a 100644
67233 --- a/include/net/iucv/af_iucv.h
67234 +++ b/include/net/iucv/af_iucv.h
67235 @@ -141,7 +141,7 @@ struct iucv_sock {
67236 struct iucv_sock_list {
67237 struct hlist_head head;
67238 rwlock_t lock;
67239 - atomic_t autobind_name;
67240 + atomic_unchecked_t autobind_name;
67241 };
67242
67243 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
67244 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
67245 index 0dab173..1b76af0 100644
67246 --- a/include/net/neighbour.h
67247 +++ b/include/net/neighbour.h
67248 @@ -123,7 +123,7 @@ struct neigh_ops {
67249 void (*error_report)(struct neighbour *, struct sk_buff *);
67250 int (*output)(struct neighbour *, struct sk_buff *);
67251 int (*connected_output)(struct neighbour *, struct sk_buff *);
67252 -};
67253 +} __do_const;
67254
67255 struct pneigh_entry {
67256 struct pneigh_entry *next;
67257 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
67258 index 95e6466..251016d 100644
67259 --- a/include/net/net_namespace.h
67260 +++ b/include/net/net_namespace.h
67261 @@ -110,7 +110,7 @@ struct net {
67262 #endif
67263 struct netns_ipvs *ipvs;
67264 struct sock *diag_nlsk;
67265 - atomic_t rt_genid;
67266 + atomic_unchecked_t rt_genid;
67267 };
67268
67269 /*
67270 @@ -320,12 +320,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
67271
67272 static inline int rt_genid(struct net *net)
67273 {
67274 - return atomic_read(&net->rt_genid);
67275 + return atomic_read_unchecked(&net->rt_genid);
67276 }
67277
67278 static inline void rt_genid_bump(struct net *net)
67279 {
67280 - atomic_inc(&net->rt_genid);
67281 + atomic_inc_unchecked(&net->rt_genid);
67282 }
67283
67284 #endif /* __NET_NET_NAMESPACE_H */
67285 diff --git a/include/net/netdma.h b/include/net/netdma.h
67286 index 8ba8ce2..99b7fff 100644
67287 --- a/include/net/netdma.h
67288 +++ b/include/net/netdma.h
67289 @@ -24,7 +24,7 @@
67290 #include <linux/dmaengine.h>
67291 #include <linux/skbuff.h>
67292
67293 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
67294 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
67295 struct sk_buff *skb, int offset, struct iovec *to,
67296 size_t len, struct dma_pinned_list *pinned_list);
67297
67298 diff --git a/include/net/netfilter/nf_queue.h b/include/net/netfilter/nf_queue.h
67299 index 252fd10..aa1421f 100644
67300 --- a/include/net/netfilter/nf_queue.h
67301 +++ b/include/net/netfilter/nf_queue.h
67302 @@ -22,7 +22,7 @@ struct nf_queue_handler {
67303 int (*outfn)(struct nf_queue_entry *entry,
67304 unsigned int queuenum);
67305 char *name;
67306 -};
67307 +} __do_const;
67308
67309 extern int nf_register_queue_handler(u_int8_t pf,
67310 const struct nf_queue_handler *qh);
67311 diff --git a/include/net/netlink.h b/include/net/netlink.h
67312 index 9690b0f..87aded7 100644
67313 --- a/include/net/netlink.h
67314 +++ b/include/net/netlink.h
67315 @@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
67316 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
67317 {
67318 if (mark)
67319 - skb_trim(skb, (unsigned char *) mark - skb->data);
67320 + skb_trim(skb, (const unsigned char *) mark - skb->data);
67321 }
67322
67323 /**
67324 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
67325 index 2ae2b83..dbdc85e 100644
67326 --- a/include/net/netns/ipv4.h
67327 +++ b/include/net/netns/ipv4.h
67328 @@ -64,7 +64,7 @@ struct netns_ipv4 {
67329 kgid_t sysctl_ping_group_range[2];
67330 long sysctl_tcp_mem[3];
67331
67332 - atomic_t dev_addr_genid;
67333 + atomic_unchecked_t dev_addr_genid;
67334
67335 #ifdef CONFIG_IP_MROUTE
67336 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
67337 diff --git a/include/net/protocol.h b/include/net/protocol.h
67338 index 929528c..c84d4f6 100644
67339 --- a/include/net/protocol.h
67340 +++ b/include/net/protocol.h
67341 @@ -48,7 +48,7 @@ struct net_protocol {
67342 int (*gro_complete)(struct sk_buff *skb);
67343 unsigned int no_policy:1,
67344 netns_ok:1;
67345 -};
67346 +} __do_const;
67347
67348 #if IS_ENABLED(CONFIG_IPV6)
67349 struct inet6_protocol {
67350 @@ -69,7 +69,7 @@ struct inet6_protocol {
67351 int (*gro_complete)(struct sk_buff *skb);
67352
67353 unsigned int flags; /* INET6_PROTO_xxx */
67354 -};
67355 +} __do_const;
67356
67357 #define INET6_PROTO_NOPOLICY 0x1
67358 #define INET6_PROTO_FINAL 0x2
67359 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
67360 index 9c6414f..fbd0524 100644
67361 --- a/include/net/sctp/sctp.h
67362 +++ b/include/net/sctp/sctp.h
67363 @@ -318,9 +318,9 @@ do { \
67364
67365 #else /* SCTP_DEBUG */
67366
67367 -#define SCTP_DEBUG_PRINTK(whatever...)
67368 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
67369 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
67370 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
67371 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
67372 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
67373 #define SCTP_ENABLE_DEBUG
67374 #define SCTP_DISABLE_DEBUG
67375 #define SCTP_ASSERT(expr, str, func)
67376 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
67377 index 64158aa..b65533c 100644
67378 --- a/include/net/sctp/structs.h
67379 +++ b/include/net/sctp/structs.h
67380 @@ -496,7 +496,7 @@ struct sctp_af {
67381 int sockaddr_len;
67382 sa_family_t sa_family;
67383 struct list_head list;
67384 -};
67385 +} __do_const;
67386
67387 struct sctp_af *sctp_get_af_specific(sa_family_t);
67388 int sctp_register_af(struct sctp_af *);
67389 @@ -516,7 +516,7 @@ struct sctp_pf {
67390 struct sctp_association *asoc);
67391 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
67392 struct sctp_af *af;
67393 -};
67394 +} __do_const;
67395
67396
67397 /* Structure to track chunk fragments that have been acked, but peer
67398 diff --git a/include/net/sock.h b/include/net/sock.h
67399 index c945fba..e162e56 100644
67400 --- a/include/net/sock.h
67401 +++ b/include/net/sock.h
67402 @@ -304,7 +304,7 @@ struct sock {
67403 #ifdef CONFIG_RPS
67404 __u32 sk_rxhash;
67405 #endif
67406 - atomic_t sk_drops;
67407 + atomic_unchecked_t sk_drops;
67408 int sk_rcvbuf;
67409
67410 struct sk_filter __rcu *sk_filter;
67411 @@ -1763,7 +1763,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
67412 }
67413
67414 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
67415 - char __user *from, char *to,
67416 + char __user *from, unsigned char *to,
67417 int copy, int offset)
67418 {
67419 if (skb->ip_summed == CHECKSUM_NONE) {
67420 @@ -2022,7 +2022,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
67421 }
67422 }
67423
67424 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
67425 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
67426
67427 /**
67428 * sk_page_frag - return an appropriate page_frag
67429 diff --git a/include/net/tcp.h b/include/net/tcp.h
67430 index 4af45e3..af97861 100644
67431 --- a/include/net/tcp.h
67432 +++ b/include/net/tcp.h
67433 @@ -531,7 +531,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
67434 extern void tcp_xmit_retransmit_queue(struct sock *);
67435 extern void tcp_simple_retransmit(struct sock *);
67436 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
67437 -extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
67438 +extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
67439
67440 extern void tcp_send_probe0(struct sock *);
67441 extern void tcp_send_partial(struct sock *);
67442 @@ -702,8 +702,8 @@ struct tcp_skb_cb {
67443 struct inet6_skb_parm h6;
67444 #endif
67445 } header; /* For incoming frames */
67446 - __u32 seq; /* Starting sequence number */
67447 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
67448 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
67449 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
67450 __u32 when; /* used to compute rtt's */
67451 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
67452
67453 @@ -717,7 +717,7 @@ struct tcp_skb_cb {
67454
67455 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
67456 /* 1 byte hole */
67457 - __u32 ack_seq; /* Sequence number ACK'd */
67458 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
67459 };
67460
67461 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
67462 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
67463 index 63445ed..74ef61d 100644
67464 --- a/include/net/xfrm.h
67465 +++ b/include/net/xfrm.h
67466 @@ -423,7 +423,7 @@ struct xfrm_mode {
67467 struct module *owner;
67468 unsigned int encap;
67469 int flags;
67470 -};
67471 +} __do_const;
67472
67473 /* Flags for xfrm_mode. */
67474 enum {
67475 @@ -514,7 +514,7 @@ struct xfrm_policy {
67476 struct timer_list timer;
67477
67478 struct flow_cache_object flo;
67479 - atomic_t genid;
67480 + atomic_unchecked_t genid;
67481 u32 priority;
67482 u32 index;
67483 struct xfrm_mark mark;
67484 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
67485 index 1a046b1..ee0bef0 100644
67486 --- a/include/rdma/iw_cm.h
67487 +++ b/include/rdma/iw_cm.h
67488 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
67489 int backlog);
67490
67491 int (*destroy_listen)(struct iw_cm_id *cm_id);
67492 -};
67493 +} __no_const;
67494
67495 /**
67496 * iw_create_cm_id - Create an IW CM identifier.
67497 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
67498 index 399162b..b337f1a 100644
67499 --- a/include/scsi/libfc.h
67500 +++ b/include/scsi/libfc.h
67501 @@ -762,6 +762,7 @@ struct libfc_function_template {
67502 */
67503 void (*disc_stop_final) (struct fc_lport *);
67504 };
67505 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
67506
67507 /**
67508 * struct fc_disc - Discovery context
67509 @@ -866,7 +867,7 @@ struct fc_lport {
67510 struct fc_vport *vport;
67511
67512 /* Operational Information */
67513 - struct libfc_function_template tt;
67514 + libfc_function_template_no_const tt;
67515 u8 link_up;
67516 u8 qfull;
67517 enum fc_lport_state state;
67518 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
67519 index 55367b0..d97bd2a 100644
67520 --- a/include/scsi/scsi_device.h
67521 +++ b/include/scsi/scsi_device.h
67522 @@ -169,9 +169,9 @@ struct scsi_device {
67523 unsigned int max_device_blocked; /* what device_blocked counts down from */
67524 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
67525
67526 - atomic_t iorequest_cnt;
67527 - atomic_t iodone_cnt;
67528 - atomic_t ioerr_cnt;
67529 + atomic_unchecked_t iorequest_cnt;
67530 + atomic_unchecked_t iodone_cnt;
67531 + atomic_unchecked_t ioerr_cnt;
67532
67533 struct device sdev_gendev,
67534 sdev_dev;
67535 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
67536 index b797e8f..8e2c3aa 100644
67537 --- a/include/scsi/scsi_transport_fc.h
67538 +++ b/include/scsi/scsi_transport_fc.h
67539 @@ -751,7 +751,8 @@ struct fc_function_template {
67540 unsigned long show_host_system_hostname:1;
67541
67542 unsigned long disable_target_scan:1;
67543 -};
67544 +} __do_const;
67545 +typedef struct fc_function_template __no_const fc_function_template_no_const;
67546
67547
67548 /**
67549 diff --git a/include/sound/soc.h b/include/sound/soc.h
67550 index 91244a0..89ca1a7 100644
67551 --- a/include/sound/soc.h
67552 +++ b/include/sound/soc.h
67553 @@ -769,7 +769,7 @@ struct snd_soc_codec_driver {
67554 /* probe ordering - for components with runtime dependencies */
67555 int probe_order;
67556 int remove_order;
67557 -};
67558 +} __do_const;
67559
67560 /* SoC platform interface */
67561 struct snd_soc_platform_driver {
67562 @@ -815,7 +815,7 @@ struct snd_soc_platform_driver {
67563 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
67564 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
67565 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
67566 -};
67567 +} __do_const;
67568
67569 struct snd_soc_platform {
67570 const char *name;
67571 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
67572 index fca8bbe..c0242ea 100644
67573 --- a/include/target/target_core_base.h
67574 +++ b/include/target/target_core_base.h
67575 @@ -760,7 +760,7 @@ struct se_device {
67576 spinlock_t stats_lock;
67577 /* Active commands on this virtual SE device */
67578 atomic_t simple_cmds;
67579 - atomic_t dev_ordered_id;
67580 + atomic_unchecked_t dev_ordered_id;
67581 atomic_t dev_ordered_sync;
67582 atomic_t dev_qf_count;
67583 struct se_obj dev_obj;
67584 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
67585 new file mode 100644
67586 index 0000000..fb634b7
67587 --- /dev/null
67588 +++ b/include/trace/events/fs.h
67589 @@ -0,0 +1,53 @@
67590 +#undef TRACE_SYSTEM
67591 +#define TRACE_SYSTEM fs
67592 +
67593 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
67594 +#define _TRACE_FS_H
67595 +
67596 +#include <linux/fs.h>
67597 +#include <linux/tracepoint.h>
67598 +
67599 +TRACE_EVENT(do_sys_open,
67600 +
67601 + TP_PROTO(const char *filename, int flags, int mode),
67602 +
67603 + TP_ARGS(filename, flags, mode),
67604 +
67605 + TP_STRUCT__entry(
67606 + __string( filename, filename )
67607 + __field( int, flags )
67608 + __field( int, mode )
67609 + ),
67610 +
67611 + TP_fast_assign(
67612 + __assign_str(filename, filename);
67613 + __entry->flags = flags;
67614 + __entry->mode = mode;
67615 + ),
67616 +
67617 + TP_printk("\"%s\" %x %o",
67618 + __get_str(filename), __entry->flags, __entry->mode)
67619 +);
67620 +
67621 +TRACE_EVENT(open_exec,
67622 +
67623 + TP_PROTO(const char *filename),
67624 +
67625 + TP_ARGS(filename),
67626 +
67627 + TP_STRUCT__entry(
67628 + __string( filename, filename )
67629 + ),
67630 +
67631 + TP_fast_assign(
67632 + __assign_str(filename, filename);
67633 + ),
67634 +
67635 + TP_printk("\"%s\"",
67636 + __get_str(filename))
67637 +);
67638 +
67639 +#endif /* _TRACE_FS_H */
67640 +
67641 +/* This part must be outside protection */
67642 +#include <trace/define_trace.h>
67643 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
67644 index 1c09820..7f5ec79 100644
67645 --- a/include/trace/events/irq.h
67646 +++ b/include/trace/events/irq.h
67647 @@ -36,7 +36,7 @@ struct softirq_action;
67648 */
67649 TRACE_EVENT(irq_handler_entry,
67650
67651 - TP_PROTO(int irq, struct irqaction *action),
67652 + TP_PROTO(int irq, const struct irqaction *action),
67653
67654 TP_ARGS(irq, action),
67655
67656 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
67657 */
67658 TRACE_EVENT(irq_handler_exit,
67659
67660 - TP_PROTO(int irq, struct irqaction *action, int ret),
67661 + TP_PROTO(int irq, const struct irqaction *action, int ret),
67662
67663 TP_ARGS(irq, action, ret),
67664
67665 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
67666 index 7caf44c..23c6f27 100644
67667 --- a/include/uapi/linux/a.out.h
67668 +++ b/include/uapi/linux/a.out.h
67669 @@ -39,6 +39,14 @@ enum machine_type {
67670 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
67671 };
67672
67673 +/* Constants for the N_FLAGS field */
67674 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
67675 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
67676 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
67677 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
67678 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
67679 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
67680 +
67681 #if !defined (N_MAGIC)
67682 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
67683 #endif
67684 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
67685 index d876736..b36014e 100644
67686 --- a/include/uapi/linux/byteorder/little_endian.h
67687 +++ b/include/uapi/linux/byteorder/little_endian.h
67688 @@ -42,51 +42,51 @@
67689
67690 static inline __le64 __cpu_to_le64p(const __u64 *p)
67691 {
67692 - return (__force __le64)*p;
67693 + return (__force const __le64)*p;
67694 }
67695 static inline __u64 __le64_to_cpup(const __le64 *p)
67696 {
67697 - return (__force __u64)*p;
67698 + return (__force const __u64)*p;
67699 }
67700 static inline __le32 __cpu_to_le32p(const __u32 *p)
67701 {
67702 - return (__force __le32)*p;
67703 + return (__force const __le32)*p;
67704 }
67705 static inline __u32 __le32_to_cpup(const __le32 *p)
67706 {
67707 - return (__force __u32)*p;
67708 + return (__force const __u32)*p;
67709 }
67710 static inline __le16 __cpu_to_le16p(const __u16 *p)
67711 {
67712 - return (__force __le16)*p;
67713 + return (__force const __le16)*p;
67714 }
67715 static inline __u16 __le16_to_cpup(const __le16 *p)
67716 {
67717 - return (__force __u16)*p;
67718 + return (__force const __u16)*p;
67719 }
67720 static inline __be64 __cpu_to_be64p(const __u64 *p)
67721 {
67722 - return (__force __be64)__swab64p(p);
67723 + return (__force const __be64)__swab64p(p);
67724 }
67725 static inline __u64 __be64_to_cpup(const __be64 *p)
67726 {
67727 - return __swab64p((__u64 *)p);
67728 + return __swab64p((const __u64 *)p);
67729 }
67730 static inline __be32 __cpu_to_be32p(const __u32 *p)
67731 {
67732 - return (__force __be32)__swab32p(p);
67733 + return (__force const __be32)__swab32p(p);
67734 }
67735 static inline __u32 __be32_to_cpup(const __be32 *p)
67736 {
67737 - return __swab32p((__u32 *)p);
67738 + return __swab32p((const __u32 *)p);
67739 }
67740 static inline __be16 __cpu_to_be16p(const __u16 *p)
67741 {
67742 - return (__force __be16)__swab16p(p);
67743 + return (__force const __be16)__swab16p(p);
67744 }
67745 static inline __u16 __be16_to_cpup(const __be16 *p)
67746 {
67747 - return __swab16p((__u16 *)p);
67748 + return __swab16p((const __u16 *)p);
67749 }
67750 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
67751 #define __le64_to_cpus(x) do { (void)(x); } while (0)
67752 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
67753 index 126a817..d522bd1 100644
67754 --- a/include/uapi/linux/elf.h
67755 +++ b/include/uapi/linux/elf.h
67756 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
67757 #define PT_GNU_EH_FRAME 0x6474e550
67758
67759 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
67760 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
67761 +
67762 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
67763 +
67764 +/* Constants for the e_flags field */
67765 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
67766 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
67767 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
67768 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
67769 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
67770 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
67771
67772 /*
67773 * Extended Numbering
67774 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
67775 #define DT_DEBUG 21
67776 #define DT_TEXTREL 22
67777 #define DT_JMPREL 23
67778 +#define DT_FLAGS 30
67779 + #define DF_TEXTREL 0x00000004
67780 #define DT_ENCODING 32
67781 #define OLD_DT_LOOS 0x60000000
67782 #define DT_LOOS 0x6000000d
67783 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
67784 #define PF_W 0x2
67785 #define PF_X 0x1
67786
67787 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
67788 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
67789 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
67790 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
67791 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
67792 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
67793 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
67794 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
67795 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
67796 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
67797 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
67798 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
67799 +
67800 typedef struct elf32_phdr{
67801 Elf32_Word p_type;
67802 Elf32_Off p_offset;
67803 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
67804 #define EI_OSABI 7
67805 #define EI_PAD 8
67806
67807 +#define EI_PAX 14
67808 +
67809 #define ELFMAG0 0x7f /* EI_MAG */
67810 #define ELFMAG1 'E'
67811 #define ELFMAG2 'L'
67812 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
67813 index aa169c4..6a2771d 100644
67814 --- a/include/uapi/linux/personality.h
67815 +++ b/include/uapi/linux/personality.h
67816 @@ -30,6 +30,7 @@ enum {
67817 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
67818 ADDR_NO_RANDOMIZE | \
67819 ADDR_COMPAT_LAYOUT | \
67820 + ADDR_LIMIT_3GB | \
67821 MMAP_PAGE_ZERO)
67822
67823 /*
67824 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
67825 index 7530e74..e714828 100644
67826 --- a/include/uapi/linux/screen_info.h
67827 +++ b/include/uapi/linux/screen_info.h
67828 @@ -43,7 +43,8 @@ struct screen_info {
67829 __u16 pages; /* 0x32 */
67830 __u16 vesa_attributes; /* 0x34 */
67831 __u32 capabilities; /* 0x36 */
67832 - __u8 _reserved[6]; /* 0x3a */
67833 + __u16 vesapm_size; /* 0x3a */
67834 + __u8 _reserved[4]; /* 0x3c */
67835 } __attribute__((packed));
67836
67837 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
67838 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
67839 index 6d67213..8dab561 100644
67840 --- a/include/uapi/linux/sysctl.h
67841 +++ b/include/uapi/linux/sysctl.h
67842 @@ -155,7 +155,11 @@ enum
67843 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
67844 };
67845
67846 -
67847 +#ifdef CONFIG_PAX_SOFTMODE
67848 +enum {
67849 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
67850 +};
67851 +#endif
67852
67853 /* CTL_VM names: */
67854 enum
67855 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
67856 index 26607bd..588b65f 100644
67857 --- a/include/uapi/linux/xattr.h
67858 +++ b/include/uapi/linux/xattr.h
67859 @@ -60,5 +60,9 @@
67860 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
67861 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
67862
67863 +/* User namespace */
67864 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
67865 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
67866 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
67867
67868 #endif /* _UAPI_LINUX_XATTR_H */
67869 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
67870 index f9466fa..f4e2b81 100644
67871 --- a/include/video/udlfb.h
67872 +++ b/include/video/udlfb.h
67873 @@ -53,10 +53,10 @@ struct dlfb_data {
67874 u32 pseudo_palette[256];
67875 int blank_mode; /*one of FB_BLANK_ */
67876 /* blit-only rendering path metrics, exposed through sysfs */
67877 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
67878 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
67879 - atomic_t bytes_sent; /* to usb, after compression including overhead */
67880 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
67881 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
67882 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
67883 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
67884 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
67885 };
67886
67887 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
67888 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
67889 index 0993a22..32ba2fe 100644
67890 --- a/include/video/uvesafb.h
67891 +++ b/include/video/uvesafb.h
67892 @@ -177,6 +177,7 @@ struct uvesafb_par {
67893 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
67894 u8 pmi_setpal; /* PMI for palette changes */
67895 u16 *pmi_base; /* protected mode interface location */
67896 + u8 *pmi_code; /* protected mode code location */
67897 void *pmi_start;
67898 void *pmi_pal;
67899 u8 *vbe_state_orig; /*
67900 diff --git a/init/Kconfig b/init/Kconfig
67901 index 6fdd6e3..5b01610 100644
67902 --- a/init/Kconfig
67903 +++ b/init/Kconfig
67904 @@ -925,6 +925,7 @@ endif # CGROUPS
67905
67906 config CHECKPOINT_RESTORE
67907 bool "Checkpoint/restore support" if EXPERT
67908 + depends on !GRKERNSEC
67909 default n
67910 help
67911 Enables additional kernel features in a sake of checkpoint/restore.
67912 @@ -1016,6 +1017,8 @@ config UIDGID_CONVERTED
67913 depends on OCFS2_FS = n
67914 depends on XFS_FS = n
67915
67916 + depends on GRKERNSEC = n
67917 +
67918 config UIDGID_STRICT_TYPE_CHECKS
67919 bool "Require conversions between uid/gids and their internal representation"
67920 depends on UIDGID_CONVERTED
67921 @@ -1405,7 +1408,7 @@ config SLUB_DEBUG
67922
67923 config COMPAT_BRK
67924 bool "Disable heap randomization"
67925 - default y
67926 + default n
67927 help
67928 Randomizing heap placement makes heap exploits harder, but it
67929 also breaks ancient binaries (including anything libc5 based).
67930 @@ -1648,7 +1651,7 @@ config INIT_ALL_POSSIBLE
67931 config STOP_MACHINE
67932 bool
67933 default y
67934 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
67935 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
67936 help
67937 Need stop_machine() primitive.
67938
67939 diff --git a/init/Makefile b/init/Makefile
67940 index 7bc47ee..6da2dc7 100644
67941 --- a/init/Makefile
67942 +++ b/init/Makefile
67943 @@ -2,6 +2,9 @@
67944 # Makefile for the linux kernel.
67945 #
67946
67947 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
67948 +asflags-y := $(GCC_PLUGINS_AFLAGS)
67949 +
67950 obj-y := main.o version.o mounts.o
67951 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
67952 obj-y += noinitramfs.o
67953 diff --git a/init/do_mounts.c b/init/do_mounts.c
67954 index f8a6642..4e5ee1b 100644
67955 --- a/init/do_mounts.c
67956 +++ b/init/do_mounts.c
67957 @@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
67958 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
67959 {
67960 struct super_block *s;
67961 - int err = sys_mount(name, "/root", fs, flags, data);
67962 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
67963 if (err)
67964 return err;
67965
67966 - sys_chdir("/root");
67967 + sys_chdir((const char __force_user *)"/root");
67968 s = current->fs->pwd.dentry->d_sb;
67969 ROOT_DEV = s->s_dev;
67970 printk(KERN_INFO
67971 @@ -461,18 +461,18 @@ void __init change_floppy(char *fmt, ...)
67972 va_start(args, fmt);
67973 vsprintf(buf, fmt, args);
67974 va_end(args);
67975 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
67976 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
67977 if (fd >= 0) {
67978 sys_ioctl(fd, FDEJECT, 0);
67979 sys_close(fd);
67980 }
67981 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
67982 - fd = sys_open("/dev/console", O_RDWR, 0);
67983 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
67984 if (fd >= 0) {
67985 sys_ioctl(fd, TCGETS, (long)&termios);
67986 termios.c_lflag &= ~ICANON;
67987 sys_ioctl(fd, TCSETSF, (long)&termios);
67988 - sys_read(fd, &c, 1);
67989 + sys_read(fd, (char __user *)&c, 1);
67990 termios.c_lflag |= ICANON;
67991 sys_ioctl(fd, TCSETSF, (long)&termios);
67992 sys_close(fd);
67993 @@ -566,6 +566,6 @@ void __init prepare_namespace(void)
67994 mount_root();
67995 out:
67996 devtmpfs_mount("dev");
67997 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
67998 - sys_chroot(".");
67999 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
68000 + sys_chroot((const char __force_user *)".");
68001 }
68002 diff --git a/init/do_mounts.h b/init/do_mounts.h
68003 index f5b978a..69dbfe8 100644
68004 --- a/init/do_mounts.h
68005 +++ b/init/do_mounts.h
68006 @@ -15,15 +15,15 @@ extern int root_mountflags;
68007
68008 static inline int create_dev(char *name, dev_t dev)
68009 {
68010 - sys_unlink(name);
68011 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
68012 + sys_unlink((char __force_user *)name);
68013 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
68014 }
68015
68016 #if BITS_PER_LONG == 32
68017 static inline u32 bstat(char *name)
68018 {
68019 struct stat64 stat;
68020 - if (sys_stat64(name, &stat) != 0)
68021 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
68022 return 0;
68023 if (!S_ISBLK(stat.st_mode))
68024 return 0;
68025 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
68026 static inline u32 bstat(char *name)
68027 {
68028 struct stat stat;
68029 - if (sys_newstat(name, &stat) != 0)
68030 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
68031 return 0;
68032 if (!S_ISBLK(stat.st_mode))
68033 return 0;
68034 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
68035 index f9acf71..1e19144 100644
68036 --- a/init/do_mounts_initrd.c
68037 +++ b/init/do_mounts_initrd.c
68038 @@ -58,8 +58,8 @@ static void __init handle_initrd(void)
68039 create_dev("/dev/root.old", Root_RAM0);
68040 /* mount initrd on rootfs' /root */
68041 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
68042 - sys_mkdir("/old", 0700);
68043 - sys_chdir("/old");
68044 + sys_mkdir((const char __force_user *)"/old", 0700);
68045 + sys_chdir((const char __force_user *)"/old");
68046
68047 /*
68048 * In case that a resume from disk is carried out by linuxrc or one of
68049 @@ -73,31 +73,31 @@ static void __init handle_initrd(void)
68050 current->flags &= ~PF_FREEZER_SKIP;
68051
68052 /* move initrd to rootfs' /old */
68053 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
68054 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
68055 /* switch root and cwd back to / of rootfs */
68056 - sys_chroot("..");
68057 + sys_chroot((const char __force_user *)"..");
68058
68059 if (new_decode_dev(real_root_dev) == Root_RAM0) {
68060 - sys_chdir("/old");
68061 + sys_chdir((const char __force_user *)"/old");
68062 return;
68063 }
68064
68065 - sys_chdir("/");
68066 + sys_chdir((const char __force_user *)"/");
68067 ROOT_DEV = new_decode_dev(real_root_dev);
68068 mount_root();
68069
68070 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
68071 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
68072 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
68073 if (!error)
68074 printk("okay\n");
68075 else {
68076 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
68077 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
68078 if (error == -ENOENT)
68079 printk("/initrd does not exist. Ignored.\n");
68080 else
68081 printk("failed\n");
68082 printk(KERN_NOTICE "Unmounting old root\n");
68083 - sys_umount("/old", MNT_DETACH);
68084 + sys_umount((char __force_user *)"/old", MNT_DETACH);
68085 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
68086 if (fd < 0) {
68087 error = fd;
68088 @@ -120,11 +120,11 @@ int __init initrd_load(void)
68089 * mounted in the normal path.
68090 */
68091 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
68092 - sys_unlink("/initrd.image");
68093 + sys_unlink((const char __force_user *)"/initrd.image");
68094 handle_initrd();
68095 return 1;
68096 }
68097 }
68098 - sys_unlink("/initrd.image");
68099 + sys_unlink((const char __force_user *)"/initrd.image");
68100 return 0;
68101 }
68102 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
68103 index 8cb6db5..d729f50 100644
68104 --- a/init/do_mounts_md.c
68105 +++ b/init/do_mounts_md.c
68106 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
68107 partitioned ? "_d" : "", minor,
68108 md_setup_args[ent].device_names);
68109
68110 - fd = sys_open(name, 0, 0);
68111 + fd = sys_open((char __force_user *)name, 0, 0);
68112 if (fd < 0) {
68113 printk(KERN_ERR "md: open failed - cannot start "
68114 "array %s\n", name);
68115 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
68116 * array without it
68117 */
68118 sys_close(fd);
68119 - fd = sys_open(name, 0, 0);
68120 + fd = sys_open((char __force_user *)name, 0, 0);
68121 sys_ioctl(fd, BLKRRPART, 0);
68122 }
68123 sys_close(fd);
68124 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
68125
68126 wait_for_device_probe();
68127
68128 - fd = sys_open("/dev/md0", 0, 0);
68129 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
68130 if (fd >= 0) {
68131 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
68132 sys_close(fd);
68133 diff --git a/init/init_task.c b/init/init_task.c
68134 index 8b2f399..f0797c9 100644
68135 --- a/init/init_task.c
68136 +++ b/init/init_task.c
68137 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
68138 * Initial thread structure. Alignment of this is handled by a special
68139 * linker map entry.
68140 */
68141 +#ifdef CONFIG_X86
68142 +union thread_union init_thread_union __init_task_data;
68143 +#else
68144 union thread_union init_thread_union __init_task_data =
68145 { INIT_THREAD_INFO(init_task) };
68146 +#endif
68147 diff --git a/init/initramfs.c b/init/initramfs.c
68148 index 84c6bf1..8899338 100644
68149 --- a/init/initramfs.c
68150 +++ b/init/initramfs.c
68151 @@ -84,7 +84,7 @@ static void __init free_hash(void)
68152 }
68153 }
68154
68155 -static long __init do_utime(char *filename, time_t mtime)
68156 +static long __init do_utime(char __force_user *filename, time_t mtime)
68157 {
68158 struct timespec t[2];
68159
68160 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
68161 struct dir_entry *de, *tmp;
68162 list_for_each_entry_safe(de, tmp, &dir_list, list) {
68163 list_del(&de->list);
68164 - do_utime(de->name, de->mtime);
68165 + do_utime((char __force_user *)de->name, de->mtime);
68166 kfree(de->name);
68167 kfree(de);
68168 }
68169 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
68170 if (nlink >= 2) {
68171 char *old = find_link(major, minor, ino, mode, collected);
68172 if (old)
68173 - return (sys_link(old, collected) < 0) ? -1 : 1;
68174 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
68175 }
68176 return 0;
68177 }
68178 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
68179 {
68180 struct stat st;
68181
68182 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
68183 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
68184 if (S_ISDIR(st.st_mode))
68185 - sys_rmdir(path);
68186 + sys_rmdir((char __force_user *)path);
68187 else
68188 - sys_unlink(path);
68189 + sys_unlink((char __force_user *)path);
68190 }
68191 }
68192
68193 @@ -315,7 +315,7 @@ static int __init do_name(void)
68194 int openflags = O_WRONLY|O_CREAT;
68195 if (ml != 1)
68196 openflags |= O_TRUNC;
68197 - wfd = sys_open(collected, openflags, mode);
68198 + wfd = sys_open((char __force_user *)collected, openflags, mode);
68199
68200 if (wfd >= 0) {
68201 sys_fchown(wfd, uid, gid);
68202 @@ -327,17 +327,17 @@ static int __init do_name(void)
68203 }
68204 }
68205 } else if (S_ISDIR(mode)) {
68206 - sys_mkdir(collected, mode);
68207 - sys_chown(collected, uid, gid);
68208 - sys_chmod(collected, mode);
68209 + sys_mkdir((char __force_user *)collected, mode);
68210 + sys_chown((char __force_user *)collected, uid, gid);
68211 + sys_chmod((char __force_user *)collected, mode);
68212 dir_add(collected, mtime);
68213 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
68214 S_ISFIFO(mode) || S_ISSOCK(mode)) {
68215 if (maybe_link() == 0) {
68216 - sys_mknod(collected, mode, rdev);
68217 - sys_chown(collected, uid, gid);
68218 - sys_chmod(collected, mode);
68219 - do_utime(collected, mtime);
68220 + sys_mknod((char __force_user *)collected, mode, rdev);
68221 + sys_chown((char __force_user *)collected, uid, gid);
68222 + sys_chmod((char __force_user *)collected, mode);
68223 + do_utime((char __force_user *)collected, mtime);
68224 }
68225 }
68226 return 0;
68227 @@ -346,15 +346,15 @@ static int __init do_name(void)
68228 static int __init do_copy(void)
68229 {
68230 if (count >= body_len) {
68231 - sys_write(wfd, victim, body_len);
68232 + sys_write(wfd, (char __force_user *)victim, body_len);
68233 sys_close(wfd);
68234 - do_utime(vcollected, mtime);
68235 + do_utime((char __force_user *)vcollected, mtime);
68236 kfree(vcollected);
68237 eat(body_len);
68238 state = SkipIt;
68239 return 0;
68240 } else {
68241 - sys_write(wfd, victim, count);
68242 + sys_write(wfd, (char __force_user *)victim, count);
68243 body_len -= count;
68244 eat(count);
68245 return 1;
68246 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
68247 {
68248 collected[N_ALIGN(name_len) + body_len] = '\0';
68249 clean_path(collected, 0);
68250 - sys_symlink(collected + N_ALIGN(name_len), collected);
68251 - sys_lchown(collected, uid, gid);
68252 - do_utime(collected, mtime);
68253 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
68254 + sys_lchown((char __force_user *)collected, uid, gid);
68255 + do_utime((char __force_user *)collected, mtime);
68256 state = SkipIt;
68257 next_state = Reset;
68258 return 0;
68259 diff --git a/init/main.c b/init/main.c
68260 index 857166f..9df1d8e 100644
68261 --- a/init/main.c
68262 +++ b/init/main.c
68263 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
68264 extern void tc_init(void);
68265 #endif
68266
68267 +extern void grsecurity_init(void);
68268 +
68269 /*
68270 * Debug helper: via this flag we know that we are in 'early bootup code'
68271 * where only the boot processor is running with IRQ disabled. This means
68272 @@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
68273
68274 __setup("reset_devices", set_reset_devices);
68275
68276 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
68277 +int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
68278 +static int __init setup_grsec_proc_gid(char *str)
68279 +{
68280 + grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
68281 + return 1;
68282 +}
68283 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
68284 +#endif
68285 +
68286 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
68287 +extern char pax_enter_kernel_user[];
68288 +extern char pax_exit_kernel_user[];
68289 +extern pgdval_t clone_pgd_mask;
68290 +#endif
68291 +
68292 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
68293 +static int __init setup_pax_nouderef(char *str)
68294 +{
68295 +#ifdef CONFIG_X86_32
68296 + unsigned int cpu;
68297 + struct desc_struct *gdt;
68298 +
68299 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
68300 + gdt = get_cpu_gdt_table(cpu);
68301 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
68302 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
68303 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
68304 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
68305 + }
68306 + loadsegment(ds, __KERNEL_DS);
68307 + loadsegment(es, __KERNEL_DS);
68308 + loadsegment(ss, __KERNEL_DS);
68309 +#else
68310 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
68311 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
68312 + clone_pgd_mask = ~(pgdval_t)0UL;
68313 +#endif
68314 +
68315 + return 0;
68316 +}
68317 +early_param("pax_nouderef", setup_pax_nouderef);
68318 +#endif
68319 +
68320 +#ifdef CONFIG_PAX_SOFTMODE
68321 +int pax_softmode;
68322 +
68323 +static int __init setup_pax_softmode(char *str)
68324 +{
68325 + get_option(&str, &pax_softmode);
68326 + return 1;
68327 +}
68328 +__setup("pax_softmode=", setup_pax_softmode);
68329 +#endif
68330 +
68331 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
68332 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
68333 static const char *panic_later, *panic_param;
68334 @@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
68335 {
68336 int count = preempt_count();
68337 int ret;
68338 + const char *msg1 = "", *msg2 = "";
68339
68340 if (initcall_debug)
68341 ret = do_one_initcall_debug(fn);
68342 @@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
68343 sprintf(msgbuf, "error code %d ", ret);
68344
68345 if (preempt_count() != count) {
68346 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
68347 + msg1 = " preemption imbalance";
68348 preempt_count() = count;
68349 }
68350 if (irqs_disabled()) {
68351 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
68352 + msg2 = " disabled interrupts";
68353 local_irq_enable();
68354 }
68355 - if (msgbuf[0]) {
68356 - printk("initcall %pF returned with %s\n", fn, msgbuf);
68357 + if (msgbuf[0] || *msg1 || *msg2) {
68358 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
68359 }
68360
68361 return ret;
68362 @@ -743,6 +801,10 @@ static char *initcall_level_names[] __initdata = {
68363 "late",
68364 };
68365
68366 +#ifdef CONFIG_PAX_LATENT_ENTROPY
68367 +u64 latent_entropy;
68368 +#endif
68369 +
68370 static void __init do_initcall_level(int level)
68371 {
68372 extern const struct kernel_param __start___param[], __stop___param[];
68373 @@ -755,8 +817,14 @@ static void __init do_initcall_level(int level)
68374 level, level,
68375 &repair_env_string);
68376
68377 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
68378 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
68379 do_one_initcall(*fn);
68380 +
68381 +#ifdef CONFIG_PAX_LATENT_ENTROPY
68382 + add_device_randomness(&latent_entropy, sizeof(latent_entropy));
68383 +#endif
68384 +
68385 + }
68386 }
68387
68388 static void __init do_initcalls(void)
68389 @@ -790,8 +858,14 @@ static void __init do_pre_smp_initcalls(void)
68390 {
68391 initcall_t *fn;
68392
68393 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
68394 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
68395 do_one_initcall(*fn);
68396 +
68397 +#ifdef CONFIG_PAX_LATENT_ENTROPY
68398 + add_device_randomness(&latent_entropy, sizeof(latent_entropy));
68399 +#endif
68400 +
68401 + }
68402 }
68403
68404 static int run_init_process(const char *init_filename)
68405 @@ -876,7 +950,7 @@ static noinline void __init kernel_init_freeable(void)
68406 do_basic_setup();
68407
68408 /* Open the /dev/console on the rootfs, this should never fail */
68409 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
68410 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
68411 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
68412
68413 (void) sys_dup(0);
68414 @@ -889,11 +963,13 @@ static noinline void __init kernel_init_freeable(void)
68415 if (!ramdisk_execute_command)
68416 ramdisk_execute_command = "/init";
68417
68418 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
68419 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
68420 ramdisk_execute_command = NULL;
68421 prepare_namespace();
68422 }
68423
68424 + grsecurity_init();
68425 +
68426 /*
68427 * Ok, we have completed the initial bootup, and
68428 * we're essentially up and running. Get rid of the
68429 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
68430 index 71a3ca1..cc330ee 100644
68431 --- a/ipc/mqueue.c
68432 +++ b/ipc/mqueue.c
68433 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
68434 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
68435 info->attr.mq_msgsize);
68436
68437 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
68438 spin_lock(&mq_lock);
68439 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
68440 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
68441 diff --git a/ipc/msg.c b/ipc/msg.c
68442 index a71af5a..a90a110 100644
68443 --- a/ipc/msg.c
68444 +++ b/ipc/msg.c
68445 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
68446 return security_msg_queue_associate(msq, msgflg);
68447 }
68448
68449 +static struct ipc_ops msg_ops = {
68450 + .getnew = newque,
68451 + .associate = msg_security,
68452 + .more_checks = NULL
68453 +};
68454 +
68455 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
68456 {
68457 struct ipc_namespace *ns;
68458 - struct ipc_ops msg_ops;
68459 struct ipc_params msg_params;
68460
68461 ns = current->nsproxy->ipc_ns;
68462
68463 - msg_ops.getnew = newque;
68464 - msg_ops.associate = msg_security;
68465 - msg_ops.more_checks = NULL;
68466 -
68467 msg_params.key = key;
68468 msg_params.flg = msgflg;
68469
68470 diff --git a/ipc/sem.c b/ipc/sem.c
68471 index 58d31f1..cce7a55 100644
68472 --- a/ipc/sem.c
68473 +++ b/ipc/sem.c
68474 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
68475 return 0;
68476 }
68477
68478 +static struct ipc_ops sem_ops = {
68479 + .getnew = newary,
68480 + .associate = sem_security,
68481 + .more_checks = sem_more_checks
68482 +};
68483 +
68484 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
68485 {
68486 struct ipc_namespace *ns;
68487 - struct ipc_ops sem_ops;
68488 struct ipc_params sem_params;
68489
68490 ns = current->nsproxy->ipc_ns;
68491 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
68492 if (nsems < 0 || nsems > ns->sc_semmsl)
68493 return -EINVAL;
68494
68495 - sem_ops.getnew = newary;
68496 - sem_ops.associate = sem_security;
68497 - sem_ops.more_checks = sem_more_checks;
68498 -
68499 sem_params.key = key;
68500 sem_params.flg = semflg;
68501 sem_params.u.nsems = nsems;
68502 diff --git a/ipc/shm.c b/ipc/shm.c
68503 index dff40c9..9450e27 100644
68504 --- a/ipc/shm.c
68505 +++ b/ipc/shm.c
68506 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
68507 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
68508 #endif
68509
68510 +#ifdef CONFIG_GRKERNSEC
68511 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68512 + const time_t shm_createtime, const uid_t cuid,
68513 + const int shmid);
68514 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68515 + const time_t shm_createtime);
68516 +#endif
68517 +
68518 void shm_init_ns(struct ipc_namespace *ns)
68519 {
68520 ns->shm_ctlmax = SHMMAX;
68521 @@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
68522 shp->shm_lprid = 0;
68523 shp->shm_atim = shp->shm_dtim = 0;
68524 shp->shm_ctim = get_seconds();
68525 +#ifdef CONFIG_GRKERNSEC
68526 + {
68527 + struct timespec timeval;
68528 + do_posix_clock_monotonic_gettime(&timeval);
68529 +
68530 + shp->shm_createtime = timeval.tv_sec;
68531 + }
68532 +#endif
68533 shp->shm_segsz = size;
68534 shp->shm_nattch = 0;
68535 shp->shm_file = file;
68536 @@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
68537 return 0;
68538 }
68539
68540 +static struct ipc_ops shm_ops = {
68541 + .getnew = newseg,
68542 + .associate = shm_security,
68543 + .more_checks = shm_more_checks
68544 +};
68545 +
68546 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
68547 {
68548 struct ipc_namespace *ns;
68549 - struct ipc_ops shm_ops;
68550 struct ipc_params shm_params;
68551
68552 ns = current->nsproxy->ipc_ns;
68553
68554 - shm_ops.getnew = newseg;
68555 - shm_ops.associate = shm_security;
68556 - shm_ops.more_checks = shm_more_checks;
68557 -
68558 shm_params.key = key;
68559 shm_params.flg = shmflg;
68560 shm_params.u.size = size;
68561 @@ -1003,6 +1020,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
68562 f_mode = FMODE_READ | FMODE_WRITE;
68563 }
68564 if (shmflg & SHM_EXEC) {
68565 +
68566 +#ifdef CONFIG_PAX_MPROTECT
68567 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
68568 + goto out;
68569 +#endif
68570 +
68571 prot |= PROT_EXEC;
68572 acc_mode |= S_IXUGO;
68573 }
68574 @@ -1026,9 +1049,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
68575 if (err)
68576 goto out_unlock;
68577
68578 +#ifdef CONFIG_GRKERNSEC
68579 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
68580 + shp->shm_perm.cuid, shmid) ||
68581 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
68582 + err = -EACCES;
68583 + goto out_unlock;
68584 + }
68585 +#endif
68586 +
68587 path = shp->shm_file->f_path;
68588 path_get(&path);
68589 shp->shm_nattch++;
68590 +#ifdef CONFIG_GRKERNSEC
68591 + shp->shm_lapid = current->pid;
68592 +#endif
68593 size = i_size_read(path.dentry->d_inode);
68594 shm_unlock(shp);
68595
68596 diff --git a/kernel/acct.c b/kernel/acct.c
68597 index 051e071..15e0920 100644
68598 --- a/kernel/acct.c
68599 +++ b/kernel/acct.c
68600 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
68601 */
68602 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
68603 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
68604 - file->f_op->write(file, (char *)&ac,
68605 + file->f_op->write(file, (char __force_user *)&ac,
68606 sizeof(acct_t), &file->f_pos);
68607 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
68608 set_fs(fs);
68609 diff --git a/kernel/audit.c b/kernel/audit.c
68610 index 40414e9..c920b72 100644
68611 --- a/kernel/audit.c
68612 +++ b/kernel/audit.c
68613 @@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
68614 3) suppressed due to audit_rate_limit
68615 4) suppressed due to audit_backlog_limit
68616 */
68617 -static atomic_t audit_lost = ATOMIC_INIT(0);
68618 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
68619
68620 /* The netlink socket. */
68621 static struct sock *audit_sock;
68622 @@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
68623 unsigned long now;
68624 int print;
68625
68626 - atomic_inc(&audit_lost);
68627 + atomic_inc_unchecked(&audit_lost);
68628
68629 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
68630
68631 @@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
68632 printk(KERN_WARNING
68633 "audit: audit_lost=%d audit_rate_limit=%d "
68634 "audit_backlog_limit=%d\n",
68635 - atomic_read(&audit_lost),
68636 + atomic_read_unchecked(&audit_lost),
68637 audit_rate_limit,
68638 audit_backlog_limit);
68639 audit_panic(message);
68640 @@ -677,7 +677,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
68641 status_set.pid = audit_pid;
68642 status_set.rate_limit = audit_rate_limit;
68643 status_set.backlog_limit = audit_backlog_limit;
68644 - status_set.lost = atomic_read(&audit_lost);
68645 + status_set.lost = atomic_read_unchecked(&audit_lost);
68646 status_set.backlog = skb_queue_len(&audit_skb_queue);
68647 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
68648 &status_set, sizeof(status_set));
68649 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
68650 index 157e989..b28b365 100644
68651 --- a/kernel/auditsc.c
68652 +++ b/kernel/auditsc.c
68653 @@ -2352,7 +2352,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
68654 }
68655
68656 /* global counter which is incremented every time something logs in */
68657 -static atomic_t session_id = ATOMIC_INIT(0);
68658 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
68659
68660 /**
68661 * audit_set_loginuid - set current task's audit_context loginuid
68662 @@ -2376,7 +2376,7 @@ int audit_set_loginuid(kuid_t loginuid)
68663 return -EPERM;
68664 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
68665
68666 - sessionid = atomic_inc_return(&session_id);
68667 + sessionid = atomic_inc_return_unchecked(&session_id);
68668 if (context && context->in_syscall) {
68669 struct audit_buffer *ab;
68670
68671 diff --git a/kernel/capability.c b/kernel/capability.c
68672 index 493d972..ea17248 100644
68673 --- a/kernel/capability.c
68674 +++ b/kernel/capability.c
68675 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
68676 * before modification is attempted and the application
68677 * fails.
68678 */
68679 + if (tocopy > ARRAY_SIZE(kdata))
68680 + return -EFAULT;
68681 +
68682 if (copy_to_user(dataptr, kdata, tocopy
68683 * sizeof(struct __user_cap_data_struct))) {
68684 return -EFAULT;
68685 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
68686 int ret;
68687
68688 rcu_read_lock();
68689 - ret = security_capable(__task_cred(t), ns, cap);
68690 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
68691 + gr_task_is_capable(t, __task_cred(t), cap);
68692 rcu_read_unlock();
68693
68694 - return (ret == 0);
68695 + return ret;
68696 }
68697
68698 /**
68699 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
68700 int ret;
68701
68702 rcu_read_lock();
68703 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
68704 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
68705 rcu_read_unlock();
68706
68707 - return (ret == 0);
68708 + return ret;
68709 }
68710
68711 /**
68712 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
68713 BUG();
68714 }
68715
68716 - if (security_capable(current_cred(), ns, cap) == 0) {
68717 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
68718 current->flags |= PF_SUPERPRIV;
68719 return true;
68720 }
68721 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
68722 }
68723 EXPORT_SYMBOL(ns_capable);
68724
68725 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
68726 +{
68727 + if (unlikely(!cap_valid(cap))) {
68728 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
68729 + BUG();
68730 + }
68731 +
68732 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
68733 + current->flags |= PF_SUPERPRIV;
68734 + return true;
68735 + }
68736 + return false;
68737 +}
68738 +EXPORT_SYMBOL(ns_capable_nolog);
68739 +
68740 /**
68741 * capable - Determine if the current task has a superior capability in effect
68742 * @cap: The capability to be tested for
68743 @@ -408,6 +427,12 @@ bool capable(int cap)
68744 }
68745 EXPORT_SYMBOL(capable);
68746
68747 +bool capable_nolog(int cap)
68748 +{
68749 + return ns_capable_nolog(&init_user_ns, cap);
68750 +}
68751 +EXPORT_SYMBOL(capable_nolog);
68752 +
68753 /**
68754 * nsown_capable - Check superior capability to one's own user_ns
68755 * @cap: The capability in question
68756 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
68757
68758 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
68759 }
68760 +
68761 +bool inode_capable_nolog(const struct inode *inode, int cap)
68762 +{
68763 + struct user_namespace *ns = current_user_ns();
68764 +
68765 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
68766 +}
68767 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
68768 index ad99830..992d8a7 100644
68769 --- a/kernel/cgroup.c
68770 +++ b/kernel/cgroup.c
68771 @@ -5514,7 +5514,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
68772 struct css_set *cg = link->cg;
68773 struct task_struct *task;
68774 int count = 0;
68775 - seq_printf(seq, "css_set %p\n", cg);
68776 + seq_printf(seq, "css_set %pK\n", cg);
68777 list_for_each_entry(task, &cg->tasks, cg_list) {
68778 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
68779 seq_puts(seq, " ...\n");
68780 diff --git a/kernel/compat.c b/kernel/compat.c
68781 index c28a306..b4d0cf3 100644
68782 --- a/kernel/compat.c
68783 +++ b/kernel/compat.c
68784 @@ -13,6 +13,7 @@
68785
68786 #include <linux/linkage.h>
68787 #include <linux/compat.h>
68788 +#include <linux/module.h>
68789 #include <linux/errno.h>
68790 #include <linux/time.h>
68791 #include <linux/signal.h>
68792 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
68793 mm_segment_t oldfs;
68794 long ret;
68795
68796 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
68797 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
68798 oldfs = get_fs();
68799 set_fs(KERNEL_DS);
68800 ret = hrtimer_nanosleep_restart(restart);
68801 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
68802 oldfs = get_fs();
68803 set_fs(KERNEL_DS);
68804 ret = hrtimer_nanosleep(&tu,
68805 - rmtp ? (struct timespec __user *)&rmt : NULL,
68806 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
68807 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
68808 set_fs(oldfs);
68809
68810 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
68811 mm_segment_t old_fs = get_fs();
68812
68813 set_fs(KERNEL_DS);
68814 - ret = sys_sigpending((old_sigset_t __user *) &s);
68815 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
68816 set_fs(old_fs);
68817 if (ret == 0)
68818 ret = put_user(s, set);
68819 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
68820 mm_segment_t old_fs = get_fs();
68821
68822 set_fs(KERNEL_DS);
68823 - ret = sys_old_getrlimit(resource, &r);
68824 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
68825 set_fs(old_fs);
68826
68827 if (!ret) {
68828 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
68829 mm_segment_t old_fs = get_fs();
68830
68831 set_fs(KERNEL_DS);
68832 - ret = sys_getrusage(who, (struct rusage __user *) &r);
68833 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
68834 set_fs(old_fs);
68835
68836 if (ret)
68837 @@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
68838 set_fs (KERNEL_DS);
68839 ret = sys_wait4(pid,
68840 (stat_addr ?
68841 - (unsigned int __user *) &status : NULL),
68842 - options, (struct rusage __user *) &r);
68843 + (unsigned int __force_user *) &status : NULL),
68844 + options, (struct rusage __force_user *) &r);
68845 set_fs (old_fs);
68846
68847 if (ret > 0) {
68848 @@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
68849 memset(&info, 0, sizeof(info));
68850
68851 set_fs(KERNEL_DS);
68852 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
68853 - uru ? (struct rusage __user *)&ru : NULL);
68854 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
68855 + uru ? (struct rusage __force_user *)&ru : NULL);
68856 set_fs(old_fs);
68857
68858 if ((ret < 0) || (info.si_signo == 0))
68859 @@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
68860 oldfs = get_fs();
68861 set_fs(KERNEL_DS);
68862 err = sys_timer_settime(timer_id, flags,
68863 - (struct itimerspec __user *) &newts,
68864 - (struct itimerspec __user *) &oldts);
68865 + (struct itimerspec __force_user *) &newts,
68866 + (struct itimerspec __force_user *) &oldts);
68867 set_fs(oldfs);
68868 if (!err && old && put_compat_itimerspec(old, &oldts))
68869 return -EFAULT;
68870 @@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
68871 oldfs = get_fs();
68872 set_fs(KERNEL_DS);
68873 err = sys_timer_gettime(timer_id,
68874 - (struct itimerspec __user *) &ts);
68875 + (struct itimerspec __force_user *) &ts);
68876 set_fs(oldfs);
68877 if (!err && put_compat_itimerspec(setting, &ts))
68878 return -EFAULT;
68879 @@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
68880 oldfs = get_fs();
68881 set_fs(KERNEL_DS);
68882 err = sys_clock_settime(which_clock,
68883 - (struct timespec __user *) &ts);
68884 + (struct timespec __force_user *) &ts);
68885 set_fs(oldfs);
68886 return err;
68887 }
68888 @@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
68889 oldfs = get_fs();
68890 set_fs(KERNEL_DS);
68891 err = sys_clock_gettime(which_clock,
68892 - (struct timespec __user *) &ts);
68893 + (struct timespec __force_user *) &ts);
68894 set_fs(oldfs);
68895 if (!err && put_compat_timespec(&ts, tp))
68896 return -EFAULT;
68897 @@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
68898
68899 oldfs = get_fs();
68900 set_fs(KERNEL_DS);
68901 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
68902 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
68903 set_fs(oldfs);
68904
68905 err = compat_put_timex(utp, &txc);
68906 @@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
68907 oldfs = get_fs();
68908 set_fs(KERNEL_DS);
68909 err = sys_clock_getres(which_clock,
68910 - (struct timespec __user *) &ts);
68911 + (struct timespec __force_user *) &ts);
68912 set_fs(oldfs);
68913 if (!err && tp && put_compat_timespec(&ts, tp))
68914 return -EFAULT;
68915 @@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
68916 long err;
68917 mm_segment_t oldfs;
68918 struct timespec tu;
68919 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
68920 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
68921
68922 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
68923 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
68924 oldfs = get_fs();
68925 set_fs(KERNEL_DS);
68926 err = clock_nanosleep_restart(restart);
68927 @@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
68928 oldfs = get_fs();
68929 set_fs(KERNEL_DS);
68930 err = sys_clock_nanosleep(which_clock, flags,
68931 - (struct timespec __user *) &in,
68932 - (struct timespec __user *) &out);
68933 + (struct timespec __force_user *) &in,
68934 + (struct timespec __force_user *) &out);
68935 set_fs(oldfs);
68936
68937 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
68938 diff --git a/kernel/configs.c b/kernel/configs.c
68939 index 42e8fa0..9e7406b 100644
68940 --- a/kernel/configs.c
68941 +++ b/kernel/configs.c
68942 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
68943 struct proc_dir_entry *entry;
68944
68945 /* create the current config file */
68946 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
68947 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
68948 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
68949 + &ikconfig_file_ops);
68950 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68951 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
68952 + &ikconfig_file_ops);
68953 +#endif
68954 +#else
68955 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
68956 &ikconfig_file_ops);
68957 +#endif
68958 +
68959 if (!entry)
68960 return -ENOMEM;
68961
68962 diff --git a/kernel/cred.c b/kernel/cred.c
68963 index 48cea3d..3476734 100644
68964 --- a/kernel/cred.c
68965 +++ b/kernel/cred.c
68966 @@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
68967 validate_creds(cred);
68968 alter_cred_subscribers(cred, -1);
68969 put_cred(cred);
68970 +
68971 +#ifdef CONFIG_GRKERNSEC_SETXID
68972 + cred = (struct cred *) tsk->delayed_cred;
68973 + if (cred != NULL) {
68974 + tsk->delayed_cred = NULL;
68975 + validate_creds(cred);
68976 + alter_cred_subscribers(cred, -1);
68977 + put_cred(cred);
68978 + }
68979 +#endif
68980 }
68981
68982 /**
68983 @@ -469,7 +479,7 @@ error_put:
68984 * Always returns 0 thus allowing this function to be tail-called at the end
68985 * of, say, sys_setgid().
68986 */
68987 -int commit_creds(struct cred *new)
68988 +static int __commit_creds(struct cred *new)
68989 {
68990 struct task_struct *task = current;
68991 const struct cred *old = task->real_cred;
68992 @@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
68993
68994 get_cred(new); /* we will require a ref for the subj creds too */
68995
68996 + gr_set_role_label(task, new->uid, new->gid);
68997 +
68998 /* dumpability changes */
68999 if (!uid_eq(old->euid, new->euid) ||
69000 !gid_eq(old->egid, new->egid) ||
69001 @@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
69002 put_cred(old);
69003 return 0;
69004 }
69005 +#ifdef CONFIG_GRKERNSEC_SETXID
69006 +extern int set_user(struct cred *new);
69007 +
69008 +void gr_delayed_cred_worker(void)
69009 +{
69010 + const struct cred *new = current->delayed_cred;
69011 + struct cred *ncred;
69012 +
69013 + current->delayed_cred = NULL;
69014 +
69015 + if (current_uid() && new != NULL) {
69016 + // from doing get_cred on it when queueing this
69017 + put_cred(new);
69018 + return;
69019 + } else if (new == NULL)
69020 + return;
69021 +
69022 + ncred = prepare_creds();
69023 + if (!ncred)
69024 + goto die;
69025 + // uids
69026 + ncred->uid = new->uid;
69027 + ncred->euid = new->euid;
69028 + ncred->suid = new->suid;
69029 + ncred->fsuid = new->fsuid;
69030 + // gids
69031 + ncred->gid = new->gid;
69032 + ncred->egid = new->egid;
69033 + ncred->sgid = new->sgid;
69034 + ncred->fsgid = new->fsgid;
69035 + // groups
69036 + if (set_groups(ncred, new->group_info) < 0) {
69037 + abort_creds(ncred);
69038 + goto die;
69039 + }
69040 + // caps
69041 + ncred->securebits = new->securebits;
69042 + ncred->cap_inheritable = new->cap_inheritable;
69043 + ncred->cap_permitted = new->cap_permitted;
69044 + ncred->cap_effective = new->cap_effective;
69045 + ncred->cap_bset = new->cap_bset;
69046 +
69047 + if (set_user(ncred)) {
69048 + abort_creds(ncred);
69049 + goto die;
69050 + }
69051 +
69052 + // from doing get_cred on it when queueing this
69053 + put_cred(new);
69054 +
69055 + __commit_creds(ncred);
69056 + return;
69057 +die:
69058 + // from doing get_cred on it when queueing this
69059 + put_cred(new);
69060 + do_group_exit(SIGKILL);
69061 +}
69062 +#endif
69063 +
69064 +int commit_creds(struct cred *new)
69065 +{
69066 +#ifdef CONFIG_GRKERNSEC_SETXID
69067 + int ret;
69068 + int schedule_it = 0;
69069 + struct task_struct *t;
69070 +
69071 + /* we won't get called with tasklist_lock held for writing
69072 + and interrupts disabled as the cred struct in that case is
69073 + init_cred
69074 + */
69075 + if (grsec_enable_setxid && !current_is_single_threaded() &&
69076 + !current_uid() && new->uid) {
69077 + schedule_it = 1;
69078 + }
69079 + ret = __commit_creds(new);
69080 + if (schedule_it) {
69081 + rcu_read_lock();
69082 + read_lock(&tasklist_lock);
69083 + for (t = next_thread(current); t != current;
69084 + t = next_thread(t)) {
69085 + if (t->delayed_cred == NULL) {
69086 + t->delayed_cred = get_cred(new);
69087 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
69088 + set_tsk_need_resched(t);
69089 + }
69090 + }
69091 + read_unlock(&tasklist_lock);
69092 + rcu_read_unlock();
69093 + }
69094 + return ret;
69095 +#else
69096 + return __commit_creds(new);
69097 +#endif
69098 +}
69099 +
69100 EXPORT_SYMBOL(commit_creds);
69101
69102 /**
69103 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
69104 index 9a61738..c5c8f3a 100644
69105 --- a/kernel/debug/debug_core.c
69106 +++ b/kernel/debug/debug_core.c
69107 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
69108 */
69109 static atomic_t masters_in_kgdb;
69110 static atomic_t slaves_in_kgdb;
69111 -static atomic_t kgdb_break_tasklet_var;
69112 +static atomic_unchecked_t kgdb_break_tasklet_var;
69113 atomic_t kgdb_setting_breakpoint;
69114
69115 struct task_struct *kgdb_usethread;
69116 @@ -132,7 +132,7 @@ int kgdb_single_step;
69117 static pid_t kgdb_sstep_pid;
69118
69119 /* to keep track of the CPU which is doing the single stepping*/
69120 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
69121 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
69122
69123 /*
69124 * If you are debugging a problem where roundup (the collection of
69125 @@ -540,7 +540,7 @@ return_normal:
69126 * kernel will only try for the value of sstep_tries before
69127 * giving up and continuing on.
69128 */
69129 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
69130 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
69131 (kgdb_info[cpu].task &&
69132 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
69133 atomic_set(&kgdb_active, -1);
69134 @@ -634,8 +634,8 @@ cpu_master_loop:
69135 }
69136
69137 kgdb_restore:
69138 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
69139 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
69140 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
69141 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
69142 if (kgdb_info[sstep_cpu].task)
69143 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
69144 else
69145 @@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
69146 static void kgdb_tasklet_bpt(unsigned long ing)
69147 {
69148 kgdb_breakpoint();
69149 - atomic_set(&kgdb_break_tasklet_var, 0);
69150 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
69151 }
69152
69153 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
69154
69155 void kgdb_schedule_breakpoint(void)
69156 {
69157 - if (atomic_read(&kgdb_break_tasklet_var) ||
69158 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
69159 atomic_read(&kgdb_active) != -1 ||
69160 atomic_read(&kgdb_setting_breakpoint))
69161 return;
69162 - atomic_inc(&kgdb_break_tasklet_var);
69163 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
69164 tasklet_schedule(&kgdb_tasklet_breakpoint);
69165 }
69166 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
69167 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
69168 index 8875254..7cf4928 100644
69169 --- a/kernel/debug/kdb/kdb_main.c
69170 +++ b/kernel/debug/kdb/kdb_main.c
69171 @@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
69172 continue;
69173
69174 kdb_printf("%-20s%8u 0x%p ", mod->name,
69175 - mod->core_size, (void *)mod);
69176 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
69177 #ifdef CONFIG_MODULE_UNLOAD
69178 kdb_printf("%4ld ", module_refcount(mod));
69179 #endif
69180 @@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
69181 kdb_printf(" (Loading)");
69182 else
69183 kdb_printf(" (Live)");
69184 - kdb_printf(" 0x%p", mod->module_core);
69185 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
69186
69187 #ifdef CONFIG_MODULE_UNLOAD
69188 {
69189 diff --git a/kernel/events/core.c b/kernel/events/core.c
69190 index dbccf83..8c66482 100644
69191 --- a/kernel/events/core.c
69192 +++ b/kernel/events/core.c
69193 @@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
69194 return 0;
69195 }
69196
69197 -static atomic64_t perf_event_id;
69198 +static atomic64_unchecked_t perf_event_id;
69199
69200 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
69201 enum event_type_t event_type);
69202 @@ -2668,7 +2668,7 @@ static void __perf_event_read(void *info)
69203
69204 static inline u64 perf_event_count(struct perf_event *event)
69205 {
69206 - return local64_read(&event->count) + atomic64_read(&event->child_count);
69207 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
69208 }
69209
69210 static u64 perf_event_read(struct perf_event *event)
69211 @@ -2998,9 +2998,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
69212 mutex_lock(&event->child_mutex);
69213 total += perf_event_read(event);
69214 *enabled += event->total_time_enabled +
69215 - atomic64_read(&event->child_total_time_enabled);
69216 + atomic64_read_unchecked(&event->child_total_time_enabled);
69217 *running += event->total_time_running +
69218 - atomic64_read(&event->child_total_time_running);
69219 + atomic64_read_unchecked(&event->child_total_time_running);
69220
69221 list_for_each_entry(child, &event->child_list, child_list) {
69222 total += perf_event_read(child);
69223 @@ -3403,10 +3403,10 @@ void perf_event_update_userpage(struct perf_event *event)
69224 userpg->offset -= local64_read(&event->hw.prev_count);
69225
69226 userpg->time_enabled = enabled +
69227 - atomic64_read(&event->child_total_time_enabled);
69228 + atomic64_read_unchecked(&event->child_total_time_enabled);
69229
69230 userpg->time_running = running +
69231 - atomic64_read(&event->child_total_time_running);
69232 + atomic64_read_unchecked(&event->child_total_time_running);
69233
69234 arch_perf_update_userpage(userpg, now);
69235
69236 @@ -3965,11 +3965,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
69237 values[n++] = perf_event_count(event);
69238 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
69239 values[n++] = enabled +
69240 - atomic64_read(&event->child_total_time_enabled);
69241 + atomic64_read_unchecked(&event->child_total_time_enabled);
69242 }
69243 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
69244 values[n++] = running +
69245 - atomic64_read(&event->child_total_time_running);
69246 + atomic64_read_unchecked(&event->child_total_time_running);
69247 }
69248 if (read_format & PERF_FORMAT_ID)
69249 values[n++] = primary_event_id(event);
69250 @@ -4712,12 +4712,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
69251 * need to add enough zero bytes after the string to handle
69252 * the 64bit alignment we do later.
69253 */
69254 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
69255 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
69256 if (!buf) {
69257 name = strncpy(tmp, "//enomem", sizeof(tmp));
69258 goto got_name;
69259 }
69260 - name = d_path(&file->f_path, buf, PATH_MAX);
69261 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
69262 if (IS_ERR(name)) {
69263 name = strncpy(tmp, "//toolong", sizeof(tmp));
69264 goto got_name;
69265 @@ -6156,7 +6156,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
69266 event->parent = parent_event;
69267
69268 event->ns = get_pid_ns(current->nsproxy->pid_ns);
69269 - event->id = atomic64_inc_return(&perf_event_id);
69270 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
69271
69272 event->state = PERF_EVENT_STATE_INACTIVE;
69273
69274 @@ -6774,10 +6774,10 @@ static void sync_child_event(struct perf_event *child_event,
69275 /*
69276 * Add back the child's count to the parent's count:
69277 */
69278 - atomic64_add(child_val, &parent_event->child_count);
69279 - atomic64_add(child_event->total_time_enabled,
69280 + atomic64_add_unchecked(child_val, &parent_event->child_count);
69281 + atomic64_add_unchecked(child_event->total_time_enabled,
69282 &parent_event->child_total_time_enabled);
69283 - atomic64_add(child_event->total_time_running,
69284 + atomic64_add_unchecked(child_event->total_time_running,
69285 &parent_event->child_total_time_running);
69286
69287 /*
69288 diff --git a/kernel/exit.c b/kernel/exit.c
69289 index 346616c..f103b28 100644
69290 --- a/kernel/exit.c
69291 +++ b/kernel/exit.c
69292 @@ -182,6 +182,10 @@ void release_task(struct task_struct * p)
69293 struct task_struct *leader;
69294 int zap_leader;
69295 repeat:
69296 +#ifdef CONFIG_NET
69297 + gr_del_task_from_ip_table(p);
69298 +#endif
69299 +
69300 /* don't need to get the RCU readlock here - the process is dead and
69301 * can't be modifying its own credentials. But shut RCU-lockdep up */
69302 rcu_read_lock();
69303 @@ -394,7 +398,7 @@ int allow_signal(int sig)
69304 * know it'll be handled, so that they don't get converted to
69305 * SIGKILL or just silently dropped.
69306 */
69307 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
69308 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
69309 recalc_sigpending();
69310 spin_unlock_irq(&current->sighand->siglock);
69311 return 0;
69312 @@ -430,6 +434,9 @@ void daemonize(const char *name, ...)
69313 vsnprintf(current->comm, sizeof(current->comm), name, args);
69314 va_end(args);
69315
69316 + gr_put_exec_file(current);
69317 + gr_set_kernel_label(current);
69318 +
69319 /*
69320 * If we were started as result of loading a module, close all of the
69321 * user space pages. We don't need them, and if we didn't close them
69322 @@ -812,6 +819,8 @@ void do_exit(long code)
69323 struct task_struct *tsk = current;
69324 int group_dead;
69325
69326 + set_fs(USER_DS);
69327 +
69328 profile_task_exit(tsk);
69329
69330 WARN_ON(blk_needs_flush_plug(tsk));
69331 @@ -828,7 +837,6 @@ void do_exit(long code)
69332 * mm_release()->clear_child_tid() from writing to a user-controlled
69333 * kernel address.
69334 */
69335 - set_fs(USER_DS);
69336
69337 ptrace_event(PTRACE_EVENT_EXIT, code);
69338
69339 @@ -887,6 +895,9 @@ void do_exit(long code)
69340 tsk->exit_code = code;
69341 taskstats_exit(tsk, group_dead);
69342
69343 + gr_acl_handle_psacct(tsk, code);
69344 + gr_acl_handle_exit();
69345 +
69346 exit_mm(tsk);
69347
69348 if (group_dead)
69349 @@ -1007,7 +1018,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
69350 * Take down every thread in the group. This is called by fatal signals
69351 * as well as by sys_exit_group (below).
69352 */
69353 -void
69354 +__noreturn void
69355 do_group_exit(int exit_code)
69356 {
69357 struct signal_struct *sig = current->signal;
69358 diff --git a/kernel/fork.c b/kernel/fork.c
69359 index acc4cb6..b524cb5 100644
69360 --- a/kernel/fork.c
69361 +++ b/kernel/fork.c
69362 @@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
69363 *stackend = STACK_END_MAGIC; /* for overflow detection */
69364
69365 #ifdef CONFIG_CC_STACKPROTECTOR
69366 - tsk->stack_canary = get_random_int();
69367 + tsk->stack_canary = pax_get_random_long();
69368 #endif
69369
69370 /*
69371 @@ -344,13 +344,81 @@ free_tsk:
69372 }
69373
69374 #ifdef CONFIG_MMU
69375 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
69376 +{
69377 + struct vm_area_struct *tmp;
69378 + unsigned long charge;
69379 + struct mempolicy *pol;
69380 + struct file *file;
69381 +
69382 + charge = 0;
69383 + if (mpnt->vm_flags & VM_ACCOUNT) {
69384 + unsigned long len = vma_pages(mpnt);
69385 +
69386 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
69387 + goto fail_nomem;
69388 + charge = len;
69389 + }
69390 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
69391 + if (!tmp)
69392 + goto fail_nomem;
69393 + *tmp = *mpnt;
69394 + tmp->vm_mm = mm;
69395 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
69396 + pol = mpol_dup(vma_policy(mpnt));
69397 + if (IS_ERR(pol))
69398 + goto fail_nomem_policy;
69399 + vma_set_policy(tmp, pol);
69400 + if (anon_vma_fork(tmp, mpnt))
69401 + goto fail_nomem_anon_vma_fork;
69402 + tmp->vm_flags &= ~VM_LOCKED;
69403 + tmp->vm_next = tmp->vm_prev = NULL;
69404 + tmp->vm_mirror = NULL;
69405 + file = tmp->vm_file;
69406 + if (file) {
69407 + struct inode *inode = file->f_path.dentry->d_inode;
69408 + struct address_space *mapping = file->f_mapping;
69409 +
69410 + get_file(file);
69411 + if (tmp->vm_flags & VM_DENYWRITE)
69412 + atomic_dec(&inode->i_writecount);
69413 + mutex_lock(&mapping->i_mmap_mutex);
69414 + if (tmp->vm_flags & VM_SHARED)
69415 + mapping->i_mmap_writable++;
69416 + flush_dcache_mmap_lock(mapping);
69417 + /* insert tmp into the share list, just after mpnt */
69418 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
69419 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
69420 + else
69421 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
69422 + flush_dcache_mmap_unlock(mapping);
69423 + mutex_unlock(&mapping->i_mmap_mutex);
69424 + }
69425 +
69426 + /*
69427 + * Clear hugetlb-related page reserves for children. This only
69428 + * affects MAP_PRIVATE mappings. Faults generated by the child
69429 + * are not guaranteed to succeed, even if read-only
69430 + */
69431 + if (is_vm_hugetlb_page(tmp))
69432 + reset_vma_resv_huge_pages(tmp);
69433 +
69434 + return tmp;
69435 +
69436 +fail_nomem_anon_vma_fork:
69437 + mpol_put(pol);
69438 +fail_nomem_policy:
69439 + kmem_cache_free(vm_area_cachep, tmp);
69440 +fail_nomem:
69441 + vm_unacct_memory(charge);
69442 + return NULL;
69443 +}
69444 +
69445 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69446 {
69447 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
69448 struct rb_node **rb_link, *rb_parent;
69449 int retval;
69450 - unsigned long charge;
69451 - struct mempolicy *pol;
69452
69453 down_write(&oldmm->mmap_sem);
69454 flush_cache_dup_mm(oldmm);
69455 @@ -363,8 +431,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69456 mm->locked_vm = 0;
69457 mm->mmap = NULL;
69458 mm->mmap_cache = NULL;
69459 - mm->free_area_cache = oldmm->mmap_base;
69460 - mm->cached_hole_size = ~0UL;
69461 + mm->free_area_cache = oldmm->free_area_cache;
69462 + mm->cached_hole_size = oldmm->cached_hole_size;
69463 mm->map_count = 0;
69464 cpumask_clear(mm_cpumask(mm));
69465 mm->mm_rb = RB_ROOT;
69466 @@ -380,57 +448,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69467
69468 prev = NULL;
69469 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
69470 - struct file *file;
69471 -
69472 if (mpnt->vm_flags & VM_DONTCOPY) {
69473 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
69474 -vma_pages(mpnt));
69475 continue;
69476 }
69477 - charge = 0;
69478 - if (mpnt->vm_flags & VM_ACCOUNT) {
69479 - unsigned long len = vma_pages(mpnt);
69480 -
69481 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
69482 - goto fail_nomem;
69483 - charge = len;
69484 - }
69485 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
69486 - if (!tmp)
69487 - goto fail_nomem;
69488 - *tmp = *mpnt;
69489 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
69490 - pol = mpol_dup(vma_policy(mpnt));
69491 - retval = PTR_ERR(pol);
69492 - if (IS_ERR(pol))
69493 - goto fail_nomem_policy;
69494 - vma_set_policy(tmp, pol);
69495 - tmp->vm_mm = mm;
69496 - if (anon_vma_fork(tmp, mpnt))
69497 - goto fail_nomem_anon_vma_fork;
69498 - tmp->vm_flags &= ~VM_LOCKED;
69499 - tmp->vm_next = tmp->vm_prev = NULL;
69500 - file = tmp->vm_file;
69501 - if (file) {
69502 - struct inode *inode = file->f_path.dentry->d_inode;
69503 - struct address_space *mapping = file->f_mapping;
69504 -
69505 - get_file(file);
69506 - if (tmp->vm_flags & VM_DENYWRITE)
69507 - atomic_dec(&inode->i_writecount);
69508 - mutex_lock(&mapping->i_mmap_mutex);
69509 - if (tmp->vm_flags & VM_SHARED)
69510 - mapping->i_mmap_writable++;
69511 - flush_dcache_mmap_lock(mapping);
69512 - /* insert tmp into the share list, just after mpnt */
69513 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
69514 - vma_nonlinear_insert(tmp,
69515 - &mapping->i_mmap_nonlinear);
69516 - else
69517 - vma_interval_tree_insert_after(tmp, mpnt,
69518 - &mapping->i_mmap);
69519 - flush_dcache_mmap_unlock(mapping);
69520 - mutex_unlock(&mapping->i_mmap_mutex);
69521 + tmp = dup_vma(mm, oldmm, mpnt);
69522 + if (!tmp) {
69523 + retval = -ENOMEM;
69524 + goto out;
69525 }
69526
69527 /*
69528 @@ -462,6 +488,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69529 if (retval)
69530 goto out;
69531 }
69532 +
69533 +#ifdef CONFIG_PAX_SEGMEXEC
69534 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
69535 + struct vm_area_struct *mpnt_m;
69536 +
69537 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
69538 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
69539 +
69540 + if (!mpnt->vm_mirror)
69541 + continue;
69542 +
69543 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
69544 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
69545 + mpnt->vm_mirror = mpnt_m;
69546 + } else {
69547 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
69548 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
69549 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
69550 + mpnt->vm_mirror->vm_mirror = mpnt;
69551 + }
69552 + }
69553 + BUG_ON(mpnt_m);
69554 + }
69555 +#endif
69556 +
69557 /* a new mm has just been created */
69558 arch_dup_mmap(oldmm, mm);
69559 retval = 0;
69560 @@ -470,14 +521,6 @@ out:
69561 flush_tlb_mm(oldmm);
69562 up_write(&oldmm->mmap_sem);
69563 return retval;
69564 -fail_nomem_anon_vma_fork:
69565 - mpol_put(pol);
69566 -fail_nomem_policy:
69567 - kmem_cache_free(vm_area_cachep, tmp);
69568 -fail_nomem:
69569 - retval = -ENOMEM;
69570 - vm_unacct_memory(charge);
69571 - goto out;
69572 }
69573
69574 static inline int mm_alloc_pgd(struct mm_struct *mm)
69575 @@ -692,8 +735,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
69576 return ERR_PTR(err);
69577
69578 mm = get_task_mm(task);
69579 - if (mm && mm != current->mm &&
69580 - !ptrace_may_access(task, mode)) {
69581 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
69582 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
69583 mmput(mm);
69584 mm = ERR_PTR(-EACCES);
69585 }
69586 @@ -912,13 +955,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
69587 spin_unlock(&fs->lock);
69588 return -EAGAIN;
69589 }
69590 - fs->users++;
69591 + atomic_inc(&fs->users);
69592 spin_unlock(&fs->lock);
69593 return 0;
69594 }
69595 tsk->fs = copy_fs_struct(fs);
69596 if (!tsk->fs)
69597 return -ENOMEM;
69598 + /* Carry through gr_chroot_dentry and is_chrooted instead
69599 + of recomputing it here. Already copied when the task struct
69600 + is duplicated. This allows pivot_root to not be treated as
69601 + a chroot
69602 + */
69603 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
69604 +
69605 return 0;
69606 }
69607
69608 @@ -1183,6 +1233,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
69609 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
69610 #endif
69611 retval = -EAGAIN;
69612 +
69613 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
69614 +
69615 if (atomic_read(&p->real_cred->user->processes) >=
69616 task_rlimit(p, RLIMIT_NPROC)) {
69617 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
69618 @@ -1422,6 +1475,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
69619 goto bad_fork_free_pid;
69620 }
69621
69622 + /* synchronizes with gr_set_acls()
69623 + we need to call this past the point of no return for fork()
69624 + */
69625 + gr_copy_label(p);
69626 +
69627 if (clone_flags & CLONE_THREAD) {
69628 current->signal->nr_threads++;
69629 atomic_inc(&current->signal->live);
69630 @@ -1505,6 +1563,8 @@ bad_fork_cleanup_count:
69631 bad_fork_free:
69632 free_task(p);
69633 fork_out:
69634 + gr_log_forkfail(retval);
69635 +
69636 return ERR_PTR(retval);
69637 }
69638
69639 @@ -1605,6 +1665,8 @@ long do_fork(unsigned long clone_flags,
69640 if (clone_flags & CLONE_PARENT_SETTID)
69641 put_user(nr, parent_tidptr);
69642
69643 + gr_handle_brute_check();
69644 +
69645 if (clone_flags & CLONE_VFORK) {
69646 p->vfork_done = &vfork;
69647 init_completion(&vfork);
69648 @@ -1714,7 +1776,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
69649 return 0;
69650
69651 /* don't need lock here; in the worst case we'll do useless copy */
69652 - if (fs->users == 1)
69653 + if (atomic_read(&fs->users) == 1)
69654 return 0;
69655
69656 *new_fsp = copy_fs_struct(fs);
69657 @@ -1803,7 +1865,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
69658 fs = current->fs;
69659 spin_lock(&fs->lock);
69660 current->fs = new_fs;
69661 - if (--fs->users)
69662 + gr_set_chroot_entries(current, &current->fs->root);
69663 + if (atomic_dec_return(&fs->users))
69664 new_fs = NULL;
69665 else
69666 new_fs = fs;
69667 diff --git a/kernel/futex.c b/kernel/futex.c
69668 index 19eb089..b8c65ea 100644
69669 --- a/kernel/futex.c
69670 +++ b/kernel/futex.c
69671 @@ -54,6 +54,7 @@
69672 #include <linux/mount.h>
69673 #include <linux/pagemap.h>
69674 #include <linux/syscalls.h>
69675 +#include <linux/ptrace.h>
69676 #include <linux/signal.h>
69677 #include <linux/export.h>
69678 #include <linux/magic.h>
69679 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
69680 struct page *page, *page_head;
69681 int err, ro = 0;
69682
69683 +#ifdef CONFIG_PAX_SEGMEXEC
69684 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
69685 + return -EFAULT;
69686 +#endif
69687 +
69688 /*
69689 * The futex address must be "naturally" aligned.
69690 */
69691 @@ -2733,6 +2739,7 @@ static int __init futex_init(void)
69692 {
69693 u32 curval;
69694 int i;
69695 + mm_segment_t oldfs;
69696
69697 /*
69698 * This will fail and we want it. Some arch implementations do
69699 @@ -2744,8 +2751,11 @@ static int __init futex_init(void)
69700 * implementation, the non-functional ones will return
69701 * -ENOSYS.
69702 */
69703 + oldfs = get_fs();
69704 + set_fs(USER_DS);
69705 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
69706 futex_cmpxchg_enabled = 1;
69707 + set_fs(oldfs);
69708
69709 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
69710 plist_head_init(&futex_queues[i].chain);
69711 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
69712 index 9b22d03..6295b62 100644
69713 --- a/kernel/gcov/base.c
69714 +++ b/kernel/gcov/base.c
69715 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
69716 }
69717
69718 #ifdef CONFIG_MODULES
69719 -static inline int within(void *addr, void *start, unsigned long size)
69720 -{
69721 - return ((addr >= start) && (addr < start + size));
69722 -}
69723 -
69724 /* Update list and generate events when modules are unloaded. */
69725 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
69726 void *data)
69727 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
69728 prev = NULL;
69729 /* Remove entries located in module from linked list. */
69730 for (info = gcov_info_head; info; info = info->next) {
69731 - if (within(info, mod->module_core, mod->core_size)) {
69732 + if (within_module_core_rw((unsigned long)info, mod)) {
69733 if (prev)
69734 prev->next = info->next;
69735 else
69736 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
69737 index 6db7a5e..25b6648 100644
69738 --- a/kernel/hrtimer.c
69739 +++ b/kernel/hrtimer.c
69740 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
69741 local_irq_restore(flags);
69742 }
69743
69744 -static void run_hrtimer_softirq(struct softirq_action *h)
69745 +static void run_hrtimer_softirq(void)
69746 {
69747 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
69748
69749 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
69750 index 60f48fa..7f3a770 100644
69751 --- a/kernel/jump_label.c
69752 +++ b/kernel/jump_label.c
69753 @@ -13,6 +13,7 @@
69754 #include <linux/sort.h>
69755 #include <linux/err.h>
69756 #include <linux/static_key.h>
69757 +#include <linux/mm.h>
69758
69759 #ifdef HAVE_JUMP_LABEL
69760
69761 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
69762
69763 size = (((unsigned long)stop - (unsigned long)start)
69764 / sizeof(struct jump_entry));
69765 + pax_open_kernel();
69766 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
69767 + pax_close_kernel();
69768 }
69769
69770 static void jump_label_update(struct static_key *key, int enable);
69771 @@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
69772 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
69773 struct jump_entry *iter;
69774
69775 + pax_open_kernel();
69776 for (iter = iter_start; iter < iter_stop; iter++) {
69777 if (within_module_init(iter->code, mod))
69778 iter->code = 0;
69779 }
69780 + pax_close_kernel();
69781 }
69782
69783 static int
69784 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
69785 index 2169fee..45c017a 100644
69786 --- a/kernel/kallsyms.c
69787 +++ b/kernel/kallsyms.c
69788 @@ -11,6 +11,9 @@
69789 * Changed the compression method from stem compression to "table lookup"
69790 * compression (see scripts/kallsyms.c for a more complete description)
69791 */
69792 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69793 +#define __INCLUDED_BY_HIDESYM 1
69794 +#endif
69795 #include <linux/kallsyms.h>
69796 #include <linux/module.h>
69797 #include <linux/init.h>
69798 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
69799
69800 static inline int is_kernel_inittext(unsigned long addr)
69801 {
69802 + if (system_state != SYSTEM_BOOTING)
69803 + return 0;
69804 +
69805 if (addr >= (unsigned long)_sinittext
69806 && addr <= (unsigned long)_einittext)
69807 return 1;
69808 return 0;
69809 }
69810
69811 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
69812 +#ifdef CONFIG_MODULES
69813 +static inline int is_module_text(unsigned long addr)
69814 +{
69815 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
69816 + return 1;
69817 +
69818 + addr = ktla_ktva(addr);
69819 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
69820 +}
69821 +#else
69822 +static inline int is_module_text(unsigned long addr)
69823 +{
69824 + return 0;
69825 +}
69826 +#endif
69827 +#endif
69828 +
69829 static inline int is_kernel_text(unsigned long addr)
69830 {
69831 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
69832 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
69833
69834 static inline int is_kernel(unsigned long addr)
69835 {
69836 +
69837 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
69838 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
69839 + return 1;
69840 +
69841 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
69842 +#else
69843 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
69844 +#endif
69845 +
69846 return 1;
69847 return in_gate_area_no_mm(addr);
69848 }
69849
69850 static int is_ksym_addr(unsigned long addr)
69851 {
69852 +
69853 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
69854 + if (is_module_text(addr))
69855 + return 0;
69856 +#endif
69857 +
69858 if (all_var)
69859 return is_kernel(addr);
69860
69861 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
69862
69863 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
69864 {
69865 - iter->name[0] = '\0';
69866 iter->nameoff = get_symbol_offset(new_pos);
69867 iter->pos = new_pos;
69868 }
69869 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
69870 {
69871 struct kallsym_iter *iter = m->private;
69872
69873 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69874 + if (current_uid())
69875 + return 0;
69876 +#endif
69877 +
69878 /* Some debugging symbols have no name. Ignore them. */
69879 if (!iter->name[0])
69880 return 0;
69881 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
69882 */
69883 type = iter->exported ? toupper(iter->type) :
69884 tolower(iter->type);
69885 +
69886 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
69887 type, iter->name, iter->module_name);
69888 } else
69889 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
69890 struct kallsym_iter *iter;
69891 int ret;
69892
69893 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
69894 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
69895 if (!iter)
69896 return -ENOMEM;
69897 reset_iter(iter, 0);
69898 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
69899 index 30b7b22..c726387 100644
69900 --- a/kernel/kcmp.c
69901 +++ b/kernel/kcmp.c
69902 @@ -98,6 +98,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
69903 struct task_struct *task1, *task2;
69904 int ret;
69905
69906 +#ifdef CONFIG_GRKERNSEC
69907 + return -ENOSYS;
69908 +#endif
69909 +
69910 rcu_read_lock();
69911
69912 /*
69913 diff --git a/kernel/kexec.c b/kernel/kexec.c
69914 index 5e4bd78..00c5b91 100644
69915 --- a/kernel/kexec.c
69916 +++ b/kernel/kexec.c
69917 @@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
69918 unsigned long flags)
69919 {
69920 struct compat_kexec_segment in;
69921 - struct kexec_segment out, __user *ksegments;
69922 + struct kexec_segment out;
69923 + struct kexec_segment __user *ksegments;
69924 unsigned long i, result;
69925
69926 /* Don't allow clients that don't understand the native
69927 diff --git a/kernel/kmod.c b/kernel/kmod.c
69928 index 1c317e3..4a92a55 100644
69929 --- a/kernel/kmod.c
69930 +++ b/kernel/kmod.c
69931 @@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
69932 kfree(info->argv);
69933 }
69934
69935 -static int call_modprobe(char *module_name, int wait)
69936 +static int call_modprobe(char *module_name, char *module_param, int wait)
69937 {
69938 static char *envp[] = {
69939 "HOME=/",
69940 @@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
69941 NULL
69942 };
69943
69944 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
69945 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
69946 if (!argv)
69947 goto out;
69948
69949 @@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
69950 argv[1] = "-q";
69951 argv[2] = "--";
69952 argv[3] = module_name; /* check free_modprobe_argv() */
69953 - argv[4] = NULL;
69954 + argv[4] = module_param;
69955 + argv[5] = NULL;
69956
69957 return call_usermodehelper_fns(modprobe_path, argv, envp,
69958 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
69959 @@ -120,9 +121,8 @@ out:
69960 * If module auto-loading support is disabled then this function
69961 * becomes a no-operation.
69962 */
69963 -int __request_module(bool wait, const char *fmt, ...)
69964 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
69965 {
69966 - va_list args;
69967 char module_name[MODULE_NAME_LEN];
69968 unsigned int max_modprobes;
69969 int ret;
69970 @@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
69971 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
69972 static int kmod_loop_msg;
69973
69974 - va_start(args, fmt);
69975 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
69976 - va_end(args);
69977 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
69978 if (ret >= MODULE_NAME_LEN)
69979 return -ENAMETOOLONG;
69980
69981 @@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
69982 if (ret)
69983 return ret;
69984
69985 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
69986 + if (!current_uid()) {
69987 + /* hack to workaround consolekit/udisks stupidity */
69988 + read_lock(&tasklist_lock);
69989 + if (!strcmp(current->comm, "mount") &&
69990 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
69991 + read_unlock(&tasklist_lock);
69992 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
69993 + return -EPERM;
69994 + }
69995 + read_unlock(&tasklist_lock);
69996 + }
69997 +#endif
69998 +
69999 /* If modprobe needs a service that is in a module, we get a recursive
70000 * loop. Limit the number of running kmod threads to max_threads/2 or
70001 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
70002 @@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
70003
70004 trace_module_request(module_name, wait, _RET_IP_);
70005
70006 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
70007 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
70008
70009 atomic_dec(&kmod_concurrent);
70010 return ret;
70011 }
70012 +
70013 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
70014 +{
70015 + va_list args;
70016 + int ret;
70017 +
70018 + va_start(args, fmt);
70019 + ret = ____request_module(wait, module_param, fmt, args);
70020 + va_end(args);
70021 +
70022 + return ret;
70023 +}
70024 +
70025 +int __request_module(bool wait, const char *fmt, ...)
70026 +{
70027 + va_list args;
70028 + int ret;
70029 +
70030 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
70031 + if (current_uid()) {
70032 + char module_param[MODULE_NAME_LEN];
70033 +
70034 + memset(module_param, 0, sizeof(module_param));
70035 +
70036 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
70037 +
70038 + va_start(args, fmt);
70039 + ret = ____request_module(wait, module_param, fmt, args);
70040 + va_end(args);
70041 +
70042 + return ret;
70043 + }
70044 +#endif
70045 +
70046 + va_start(args, fmt);
70047 + ret = ____request_module(wait, NULL, fmt, args);
70048 + va_end(args);
70049 +
70050 + return ret;
70051 +}
70052 +
70053 EXPORT_SYMBOL(__request_module);
70054 #endif /* CONFIG_MODULES */
70055
70056 @@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
70057 *
70058 * Thus the __user pointer cast is valid here.
70059 */
70060 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
70061 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
70062
70063 /*
70064 * If ret is 0, either ____call_usermodehelper failed and the
70065 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
70066 index 098f396..fe85ff1 100644
70067 --- a/kernel/kprobes.c
70068 +++ b/kernel/kprobes.c
70069 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
70070 * kernel image and loaded module images reside. This is required
70071 * so x86_64 can correctly handle the %rip-relative fixups.
70072 */
70073 - kip->insns = module_alloc(PAGE_SIZE);
70074 + kip->insns = module_alloc_exec(PAGE_SIZE);
70075 if (!kip->insns) {
70076 kfree(kip);
70077 return NULL;
70078 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
70079 */
70080 if (!list_is_singular(&kip->list)) {
70081 list_del(&kip->list);
70082 - module_free(NULL, kip->insns);
70083 + module_free_exec(NULL, kip->insns);
70084 kfree(kip);
70085 }
70086 return 1;
70087 @@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
70088 {
70089 int i, err = 0;
70090 unsigned long offset = 0, size = 0;
70091 - char *modname, namebuf[128];
70092 + char *modname, namebuf[KSYM_NAME_LEN];
70093 const char *symbol_name;
70094 void *addr;
70095 struct kprobe_blackpoint *kb;
70096 @@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
70097 kprobe_type = "k";
70098
70099 if (sym)
70100 - seq_printf(pi, "%p %s %s+0x%x %s ",
70101 + seq_printf(pi, "%pK %s %s+0x%x %s ",
70102 p->addr, kprobe_type, sym, offset,
70103 (modname ? modname : " "));
70104 else
70105 - seq_printf(pi, "%p %s %p ",
70106 + seq_printf(pi, "%pK %s %pK ",
70107 p->addr, kprobe_type, p->addr);
70108
70109 if (!pp)
70110 @@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
70111 const char *sym = NULL;
70112 unsigned int i = *(loff_t *) v;
70113 unsigned long offset = 0;
70114 - char *modname, namebuf[128];
70115 + char *modname, namebuf[KSYM_NAME_LEN];
70116
70117 head = &kprobe_table[i];
70118 preempt_disable();
70119 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
70120 index 4e316e1..5501eef 100644
70121 --- a/kernel/ksysfs.c
70122 +++ b/kernel/ksysfs.c
70123 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
70124 {
70125 if (count+1 > UEVENT_HELPER_PATH_LEN)
70126 return -ENOENT;
70127 + if (!capable(CAP_SYS_ADMIN))
70128 + return -EPERM;
70129 memcpy(uevent_helper, buf, count);
70130 uevent_helper[count] = '\0';
70131 if (count && uevent_helper[count-1] == '\n')
70132 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
70133 index 7981e5b..7f2105c 100644
70134 --- a/kernel/lockdep.c
70135 +++ b/kernel/lockdep.c
70136 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
70137 end = (unsigned long) &_end,
70138 addr = (unsigned long) obj;
70139
70140 +#ifdef CONFIG_PAX_KERNEXEC
70141 + start = ktla_ktva(start);
70142 +#endif
70143 +
70144 /*
70145 * static variable?
70146 */
70147 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
70148 if (!static_obj(lock->key)) {
70149 debug_locks_off();
70150 printk("INFO: trying to register non-static key.\n");
70151 + printk("lock:%pS key:%pS.\n", lock, lock->key);
70152 printk("the code is fine but needs lockdep annotation.\n");
70153 printk("turning off the locking correctness validator.\n");
70154 dump_stack();
70155 @@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
70156 if (!class)
70157 return 0;
70158 }
70159 - atomic_inc((atomic_t *)&class->ops);
70160 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
70161 if (very_verbose(class)) {
70162 printk("\nacquire class [%p] %s", class->key, class->name);
70163 if (class->name_version > 1)
70164 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
70165 index 91c32a0..7b88d63 100644
70166 --- a/kernel/lockdep_proc.c
70167 +++ b/kernel/lockdep_proc.c
70168 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
70169
70170 static void print_name(struct seq_file *m, struct lock_class *class)
70171 {
70172 - char str[128];
70173 + char str[KSYM_NAME_LEN];
70174 const char *name = class->name;
70175
70176 if (!name) {
70177 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
70178 return 0;
70179 }
70180
70181 - seq_printf(m, "%p", class->key);
70182 + seq_printf(m, "%pK", class->key);
70183 #ifdef CONFIG_DEBUG_LOCKDEP
70184 seq_printf(m, " OPS:%8ld", class->ops);
70185 #endif
70186 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
70187
70188 list_for_each_entry(entry, &class->locks_after, entry) {
70189 if (entry->distance == 1) {
70190 - seq_printf(m, " -> [%p] ", entry->class->key);
70191 + seq_printf(m, " -> [%pK] ", entry->class->key);
70192 print_name(m, entry->class);
70193 seq_puts(m, "\n");
70194 }
70195 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
70196 if (!class->key)
70197 continue;
70198
70199 - seq_printf(m, "[%p] ", class->key);
70200 + seq_printf(m, "[%pK] ", class->key);
70201 print_name(m, class);
70202 seq_puts(m, "\n");
70203 }
70204 @@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
70205 if (!i)
70206 seq_line(m, '-', 40-namelen, namelen);
70207
70208 - snprintf(ip, sizeof(ip), "[<%p>]",
70209 + snprintf(ip, sizeof(ip), "[<%pK>]",
70210 (void *)class->contention_point[i]);
70211 seq_printf(m, "%40s %14lu %29s %pS\n",
70212 name, stats->contention_point[i],
70213 @@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
70214 if (!i)
70215 seq_line(m, '-', 40-namelen, namelen);
70216
70217 - snprintf(ip, sizeof(ip), "[<%p>]",
70218 + snprintf(ip, sizeof(ip), "[<%pK>]",
70219 (void *)class->contending_point[i]);
70220 seq_printf(m, "%40s %14lu %29s %pS\n",
70221 name, stats->contending_point[i],
70222 diff --git a/kernel/module.c b/kernel/module.c
70223 index 3e544f4..34c3008 100644
70224 --- a/kernel/module.c
70225 +++ b/kernel/module.c
70226 @@ -59,6 +59,7 @@
70227 #include <linux/pfn.h>
70228 #include <linux/bsearch.h>
70229 #include <linux/fips.h>
70230 +#include <linux/grsecurity.h>
70231 #include "module-internal.h"
70232
70233 #define CREATE_TRACE_POINTS
70234 @@ -153,7 +154,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
70235
70236 /* Bounds of module allocation, for speeding __module_address.
70237 * Protected by module_mutex. */
70238 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
70239 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
70240 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
70241
70242 int register_module_notifier(struct notifier_block * nb)
70243 {
70244 @@ -319,7 +321,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
70245 return true;
70246
70247 list_for_each_entry_rcu(mod, &modules, list) {
70248 - struct symsearch arr[] = {
70249 + struct symsearch modarr[] = {
70250 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
70251 NOT_GPL_ONLY, false },
70252 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
70253 @@ -344,7 +346,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
70254 if (mod->state == MODULE_STATE_UNFORMED)
70255 continue;
70256
70257 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
70258 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
70259 return true;
70260 }
70261 return false;
70262 @@ -484,7 +486,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
70263 static int percpu_modalloc(struct module *mod,
70264 unsigned long size, unsigned long align)
70265 {
70266 - if (align > PAGE_SIZE) {
70267 + if (align-1 >= PAGE_SIZE) {
70268 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
70269 mod->name, align, PAGE_SIZE);
70270 align = PAGE_SIZE;
70271 @@ -1088,7 +1090,7 @@ struct module_attribute module_uevent =
70272 static ssize_t show_coresize(struct module_attribute *mattr,
70273 struct module_kobject *mk, char *buffer)
70274 {
70275 - return sprintf(buffer, "%u\n", mk->mod->core_size);
70276 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
70277 }
70278
70279 static struct module_attribute modinfo_coresize =
70280 @@ -1097,7 +1099,7 @@ static struct module_attribute modinfo_coresize =
70281 static ssize_t show_initsize(struct module_attribute *mattr,
70282 struct module_kobject *mk, char *buffer)
70283 {
70284 - return sprintf(buffer, "%u\n", mk->mod->init_size);
70285 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
70286 }
70287
70288 static struct module_attribute modinfo_initsize =
70289 @@ -1311,7 +1313,7 @@ resolve_symbol_wait(struct module *mod,
70290 */
70291 #ifdef CONFIG_SYSFS
70292
70293 -#ifdef CONFIG_KALLSYMS
70294 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
70295 static inline bool sect_empty(const Elf_Shdr *sect)
70296 {
70297 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
70298 @@ -1777,21 +1779,21 @@ static void set_section_ro_nx(void *base,
70299
70300 static void unset_module_core_ro_nx(struct module *mod)
70301 {
70302 - set_page_attributes(mod->module_core + mod->core_text_size,
70303 - mod->module_core + mod->core_size,
70304 + set_page_attributes(mod->module_core_rw,
70305 + mod->module_core_rw + mod->core_size_rw,
70306 set_memory_x);
70307 - set_page_attributes(mod->module_core,
70308 - mod->module_core + mod->core_ro_size,
70309 + set_page_attributes(mod->module_core_rx,
70310 + mod->module_core_rx + mod->core_size_rx,
70311 set_memory_rw);
70312 }
70313
70314 static void unset_module_init_ro_nx(struct module *mod)
70315 {
70316 - set_page_attributes(mod->module_init + mod->init_text_size,
70317 - mod->module_init + mod->init_size,
70318 + set_page_attributes(mod->module_init_rw,
70319 + mod->module_init_rw + mod->init_size_rw,
70320 set_memory_x);
70321 - set_page_attributes(mod->module_init,
70322 - mod->module_init + mod->init_ro_size,
70323 + set_page_attributes(mod->module_init_rx,
70324 + mod->module_init_rx + mod->init_size_rx,
70325 set_memory_rw);
70326 }
70327
70328 @@ -1804,14 +1806,14 @@ void set_all_modules_text_rw(void)
70329 list_for_each_entry_rcu(mod, &modules, list) {
70330 if (mod->state == MODULE_STATE_UNFORMED)
70331 continue;
70332 - if ((mod->module_core) && (mod->core_text_size)) {
70333 - set_page_attributes(mod->module_core,
70334 - mod->module_core + mod->core_text_size,
70335 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
70336 + set_page_attributes(mod->module_core_rx,
70337 + mod->module_core_rx + mod->core_size_rx,
70338 set_memory_rw);
70339 }
70340 - if ((mod->module_init) && (mod->init_text_size)) {
70341 - set_page_attributes(mod->module_init,
70342 - mod->module_init + mod->init_text_size,
70343 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
70344 + set_page_attributes(mod->module_init_rx,
70345 + mod->module_init_rx + mod->init_size_rx,
70346 set_memory_rw);
70347 }
70348 }
70349 @@ -1827,14 +1829,14 @@ void set_all_modules_text_ro(void)
70350 list_for_each_entry_rcu(mod, &modules, list) {
70351 if (mod->state == MODULE_STATE_UNFORMED)
70352 continue;
70353 - if ((mod->module_core) && (mod->core_text_size)) {
70354 - set_page_attributes(mod->module_core,
70355 - mod->module_core + mod->core_text_size,
70356 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
70357 + set_page_attributes(mod->module_core_rx,
70358 + mod->module_core_rx + mod->core_size_rx,
70359 set_memory_ro);
70360 }
70361 - if ((mod->module_init) && (mod->init_text_size)) {
70362 - set_page_attributes(mod->module_init,
70363 - mod->module_init + mod->init_text_size,
70364 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
70365 + set_page_attributes(mod->module_init_rx,
70366 + mod->module_init_rx + mod->init_size_rx,
70367 set_memory_ro);
70368 }
70369 }
70370 @@ -1880,16 +1882,19 @@ static void free_module(struct module *mod)
70371
70372 /* This may be NULL, but that's OK */
70373 unset_module_init_ro_nx(mod);
70374 - module_free(mod, mod->module_init);
70375 + module_free(mod, mod->module_init_rw);
70376 + module_free_exec(mod, mod->module_init_rx);
70377 kfree(mod->args);
70378 percpu_modfree(mod);
70379
70380 /* Free lock-classes: */
70381 - lockdep_free_key_range(mod->module_core, mod->core_size);
70382 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
70383 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
70384
70385 /* Finally, free the core (containing the module structure) */
70386 unset_module_core_ro_nx(mod);
70387 - module_free(mod, mod->module_core);
70388 + module_free_exec(mod, mod->module_core_rx);
70389 + module_free(mod, mod->module_core_rw);
70390
70391 #ifdef CONFIG_MPU
70392 update_protections(current->mm);
70393 @@ -1959,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
70394 int ret = 0;
70395 const struct kernel_symbol *ksym;
70396
70397 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
70398 + int is_fs_load = 0;
70399 + int register_filesystem_found = 0;
70400 + char *p;
70401 +
70402 + p = strstr(mod->args, "grsec_modharden_fs");
70403 + if (p) {
70404 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
70405 + /* copy \0 as well */
70406 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
70407 + is_fs_load = 1;
70408 + }
70409 +#endif
70410 +
70411 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
70412 const char *name = info->strtab + sym[i].st_name;
70413
70414 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
70415 + /* it's a real shame this will never get ripped and copied
70416 + upstream! ;(
70417 + */
70418 + if (is_fs_load && !strcmp(name, "register_filesystem"))
70419 + register_filesystem_found = 1;
70420 +#endif
70421 +
70422 switch (sym[i].st_shndx) {
70423 case SHN_COMMON:
70424 /* We compiled with -fno-common. These are not
70425 @@ -1982,7 +2009,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
70426 ksym = resolve_symbol_wait(mod, info, name);
70427 /* Ok if resolved. */
70428 if (ksym && !IS_ERR(ksym)) {
70429 + pax_open_kernel();
70430 sym[i].st_value = ksym->value;
70431 + pax_close_kernel();
70432 break;
70433 }
70434
70435 @@ -2001,11 +2030,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
70436 secbase = (unsigned long)mod_percpu(mod);
70437 else
70438 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
70439 + pax_open_kernel();
70440 sym[i].st_value += secbase;
70441 + pax_close_kernel();
70442 break;
70443 }
70444 }
70445
70446 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
70447 + if (is_fs_load && !register_filesystem_found) {
70448 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
70449 + ret = -EPERM;
70450 + }
70451 +#endif
70452 +
70453 return ret;
70454 }
70455
70456 @@ -2089,22 +2127,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
70457 || s->sh_entsize != ~0UL
70458 || strstarts(sname, ".init"))
70459 continue;
70460 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
70461 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
70462 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
70463 + else
70464 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
70465 pr_debug("\t%s\n", sname);
70466 }
70467 - switch (m) {
70468 - case 0: /* executable */
70469 - mod->core_size = debug_align(mod->core_size);
70470 - mod->core_text_size = mod->core_size;
70471 - break;
70472 - case 1: /* RO: text and ro-data */
70473 - mod->core_size = debug_align(mod->core_size);
70474 - mod->core_ro_size = mod->core_size;
70475 - break;
70476 - case 3: /* whole core */
70477 - mod->core_size = debug_align(mod->core_size);
70478 - break;
70479 - }
70480 }
70481
70482 pr_debug("Init section allocation order:\n");
70483 @@ -2118,23 +2146,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
70484 || s->sh_entsize != ~0UL
70485 || !strstarts(sname, ".init"))
70486 continue;
70487 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
70488 - | INIT_OFFSET_MASK);
70489 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
70490 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
70491 + else
70492 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
70493 + s->sh_entsize |= INIT_OFFSET_MASK;
70494 pr_debug("\t%s\n", sname);
70495 }
70496 - switch (m) {
70497 - case 0: /* executable */
70498 - mod->init_size = debug_align(mod->init_size);
70499 - mod->init_text_size = mod->init_size;
70500 - break;
70501 - case 1: /* RO: text and ro-data */
70502 - mod->init_size = debug_align(mod->init_size);
70503 - mod->init_ro_size = mod->init_size;
70504 - break;
70505 - case 3: /* whole init */
70506 - mod->init_size = debug_align(mod->init_size);
70507 - break;
70508 - }
70509 }
70510 }
70511
70512 @@ -2306,7 +2324,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
70513
70514 /* Put symbol section at end of init part of module. */
70515 symsect->sh_flags |= SHF_ALLOC;
70516 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
70517 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
70518 info->index.sym) | INIT_OFFSET_MASK;
70519 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
70520
70521 @@ -2326,13 +2344,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
70522 }
70523
70524 /* Append room for core symbols at end of core part. */
70525 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
70526 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
70527 - mod->core_size += strtab_size;
70528 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
70529 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
70530 + mod->core_size_rx += strtab_size;
70531
70532 /* Put string table section at end of init part of module. */
70533 strsect->sh_flags |= SHF_ALLOC;
70534 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
70535 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
70536 info->index.str) | INIT_OFFSET_MASK;
70537 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
70538 }
70539 @@ -2350,12 +2368,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
70540 /* Make sure we get permanent strtab: don't use info->strtab. */
70541 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
70542
70543 + pax_open_kernel();
70544 +
70545 /* Set types up while we still have access to sections. */
70546 for (i = 0; i < mod->num_symtab; i++)
70547 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
70548
70549 - mod->core_symtab = dst = mod->module_core + info->symoffs;
70550 - mod->core_strtab = s = mod->module_core + info->stroffs;
70551 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
70552 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
70553 src = mod->symtab;
70554 *s++ = 0;
70555 for (ndst = i = 0; i < mod->num_symtab; i++) {
70556 @@ -2368,6 +2388,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
70557 }
70558 }
70559 mod->core_num_syms = ndst;
70560 +
70561 + pax_close_kernel();
70562 }
70563 #else
70564 static inline void layout_symtab(struct module *mod, struct load_info *info)
70565 @@ -2401,17 +2423,33 @@ void * __weak module_alloc(unsigned long size)
70566 return size == 0 ? NULL : vmalloc_exec(size);
70567 }
70568
70569 -static void *module_alloc_update_bounds(unsigned long size)
70570 +static void *module_alloc_update_bounds_rw(unsigned long size)
70571 {
70572 void *ret = module_alloc(size);
70573
70574 if (ret) {
70575 mutex_lock(&module_mutex);
70576 /* Update module bounds. */
70577 - if ((unsigned long)ret < module_addr_min)
70578 - module_addr_min = (unsigned long)ret;
70579 - if ((unsigned long)ret + size > module_addr_max)
70580 - module_addr_max = (unsigned long)ret + size;
70581 + if ((unsigned long)ret < module_addr_min_rw)
70582 + module_addr_min_rw = (unsigned long)ret;
70583 + if ((unsigned long)ret + size > module_addr_max_rw)
70584 + module_addr_max_rw = (unsigned long)ret + size;
70585 + mutex_unlock(&module_mutex);
70586 + }
70587 + return ret;
70588 +}
70589 +
70590 +static void *module_alloc_update_bounds_rx(unsigned long size)
70591 +{
70592 + void *ret = module_alloc_exec(size);
70593 +
70594 + if (ret) {
70595 + mutex_lock(&module_mutex);
70596 + /* Update module bounds. */
70597 + if ((unsigned long)ret < module_addr_min_rx)
70598 + module_addr_min_rx = (unsigned long)ret;
70599 + if ((unsigned long)ret + size > module_addr_max_rx)
70600 + module_addr_max_rx = (unsigned long)ret + size;
70601 mutex_unlock(&module_mutex);
70602 }
70603 return ret;
70604 @@ -2630,8 +2668,14 @@ static struct module *setup_load_info(struct load_info *info)
70605 static int check_modinfo(struct module *mod, struct load_info *info)
70606 {
70607 const char *modmagic = get_modinfo(info, "vermagic");
70608 + const char *license = get_modinfo(info, "license");
70609 int err;
70610
70611 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
70612 + if (!license || !license_is_gpl_compatible(license))
70613 + return -ENOEXEC;
70614 +#endif
70615 +
70616 /* This is allowed: modprobe --force will invalidate it. */
70617 if (!modmagic) {
70618 err = try_to_force_load(mod, "bad vermagic");
70619 @@ -2654,7 +2698,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
70620 }
70621
70622 /* Set up license info based on the info section */
70623 - set_license(mod, get_modinfo(info, "license"));
70624 + set_license(mod, license);
70625
70626 return 0;
70627 }
70628 @@ -2748,7 +2792,7 @@ static int move_module(struct module *mod, struct load_info *info)
70629 void *ptr;
70630
70631 /* Do the allocs. */
70632 - ptr = module_alloc_update_bounds(mod->core_size);
70633 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
70634 /*
70635 * The pointer to this block is stored in the module structure
70636 * which is inside the block. Just mark it as not being a
70637 @@ -2758,10 +2802,10 @@ static int move_module(struct module *mod, struct load_info *info)
70638 if (!ptr)
70639 return -ENOMEM;
70640
70641 - memset(ptr, 0, mod->core_size);
70642 - mod->module_core = ptr;
70643 + memset(ptr, 0, mod->core_size_rw);
70644 + mod->module_core_rw = ptr;
70645
70646 - ptr = module_alloc_update_bounds(mod->init_size);
70647 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
70648 /*
70649 * The pointer to this block is stored in the module structure
70650 * which is inside the block. This block doesn't need to be
70651 @@ -2769,12 +2813,39 @@ static int move_module(struct module *mod, struct load_info *info)
70652 * after the module is initialized.
70653 */
70654 kmemleak_ignore(ptr);
70655 - if (!ptr && mod->init_size) {
70656 - module_free(mod, mod->module_core);
70657 + if (!ptr && mod->init_size_rw) {
70658 + module_free(mod, mod->module_core_rw);
70659 return -ENOMEM;
70660 }
70661 - memset(ptr, 0, mod->init_size);
70662 - mod->module_init = ptr;
70663 + memset(ptr, 0, mod->init_size_rw);
70664 + mod->module_init_rw = ptr;
70665 +
70666 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
70667 + kmemleak_not_leak(ptr);
70668 + if (!ptr) {
70669 + module_free(mod, mod->module_init_rw);
70670 + module_free(mod, mod->module_core_rw);
70671 + return -ENOMEM;
70672 + }
70673 +
70674 + pax_open_kernel();
70675 + memset(ptr, 0, mod->core_size_rx);
70676 + pax_close_kernel();
70677 + mod->module_core_rx = ptr;
70678 +
70679 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
70680 + kmemleak_ignore(ptr);
70681 + if (!ptr && mod->init_size_rx) {
70682 + module_free_exec(mod, mod->module_core_rx);
70683 + module_free(mod, mod->module_init_rw);
70684 + module_free(mod, mod->module_core_rw);
70685 + return -ENOMEM;
70686 + }
70687 +
70688 + pax_open_kernel();
70689 + memset(ptr, 0, mod->init_size_rx);
70690 + pax_close_kernel();
70691 + mod->module_init_rx = ptr;
70692
70693 /* Transfer each section which specifies SHF_ALLOC */
70694 pr_debug("final section addresses:\n");
70695 @@ -2785,16 +2856,45 @@ static int move_module(struct module *mod, struct load_info *info)
70696 if (!(shdr->sh_flags & SHF_ALLOC))
70697 continue;
70698
70699 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
70700 - dest = mod->module_init
70701 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
70702 - else
70703 - dest = mod->module_core + shdr->sh_entsize;
70704 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
70705 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
70706 + dest = mod->module_init_rw
70707 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
70708 + else
70709 + dest = mod->module_init_rx
70710 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
70711 + } else {
70712 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
70713 + dest = mod->module_core_rw + shdr->sh_entsize;
70714 + else
70715 + dest = mod->module_core_rx + shdr->sh_entsize;
70716 + }
70717 +
70718 + if (shdr->sh_type != SHT_NOBITS) {
70719 +
70720 +#ifdef CONFIG_PAX_KERNEXEC
70721 +#ifdef CONFIG_X86_64
70722 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
70723 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
70724 +#endif
70725 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
70726 + pax_open_kernel();
70727 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
70728 + pax_close_kernel();
70729 + } else
70730 +#endif
70731
70732 - if (shdr->sh_type != SHT_NOBITS)
70733 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
70734 + }
70735 /* Update sh_addr to point to copy in image. */
70736 - shdr->sh_addr = (unsigned long)dest;
70737 +
70738 +#ifdef CONFIG_PAX_KERNEXEC
70739 + if (shdr->sh_flags & SHF_EXECINSTR)
70740 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
70741 + else
70742 +#endif
70743 +
70744 + shdr->sh_addr = (unsigned long)dest;
70745 pr_debug("\t0x%lx %s\n",
70746 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
70747 }
70748 @@ -2849,12 +2949,12 @@ static void flush_module_icache(const struct module *mod)
70749 * Do it before processing of module parameters, so the module
70750 * can provide parameter accessor functions of its own.
70751 */
70752 - if (mod->module_init)
70753 - flush_icache_range((unsigned long)mod->module_init,
70754 - (unsigned long)mod->module_init
70755 - + mod->init_size);
70756 - flush_icache_range((unsigned long)mod->module_core,
70757 - (unsigned long)mod->module_core + mod->core_size);
70758 + if (mod->module_init_rx)
70759 + flush_icache_range((unsigned long)mod->module_init_rx,
70760 + (unsigned long)mod->module_init_rx
70761 + + mod->init_size_rx);
70762 + flush_icache_range((unsigned long)mod->module_core_rx,
70763 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
70764
70765 set_fs(old_fs);
70766 }
70767 @@ -2924,8 +3024,10 @@ out:
70768 static void module_deallocate(struct module *mod, struct load_info *info)
70769 {
70770 percpu_modfree(mod);
70771 - module_free(mod, mod->module_init);
70772 - module_free(mod, mod->module_core);
70773 + module_free_exec(mod, mod->module_init_rx);
70774 + module_free_exec(mod, mod->module_core_rx);
70775 + module_free(mod, mod->module_init_rw);
70776 + module_free(mod, mod->module_core_rw);
70777 }
70778
70779 int __weak module_finalize(const Elf_Ehdr *hdr,
70780 @@ -2938,7 +3040,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
70781 static int post_relocation(struct module *mod, const struct load_info *info)
70782 {
70783 /* Sort exception table now relocations are done. */
70784 + pax_open_kernel();
70785 sort_extable(mod->extable, mod->extable + mod->num_exentries);
70786 + pax_close_kernel();
70787
70788 /* Copy relocated percpu area over. */
70789 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
70790 @@ -3036,9 +3140,38 @@ again:
70791 if (err)
70792 goto free_unload;
70793
70794 + /* Now copy in args */
70795 + mod->args = strndup_user(uargs, ~0UL >> 1);
70796 + if (IS_ERR(mod->args)) {
70797 + err = PTR_ERR(mod->args);
70798 + goto free_unload;
70799 + }
70800 +
70801 /* Set up MODINFO_ATTR fields */
70802 setup_modinfo(mod, &info);
70803
70804 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
70805 + {
70806 + char *p, *p2;
70807 +
70808 + if (strstr(mod->args, "grsec_modharden_netdev")) {
70809 + 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);
70810 + err = -EPERM;
70811 + goto free_modinfo;
70812 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
70813 + p += sizeof("grsec_modharden_normal") - 1;
70814 + p2 = strstr(p, "_");
70815 + if (p2) {
70816 + *p2 = '\0';
70817 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
70818 + *p2 = '_';
70819 + }
70820 + err = -EPERM;
70821 + goto free_modinfo;
70822 + }
70823 + }
70824 +#endif
70825 +
70826 /* Fix up syms, so that st_value is a pointer to location. */
70827 err = simplify_symbols(mod, &info);
70828 if (err < 0)
70829 @@ -3104,11 +3237,11 @@ again:
70830 mutex_unlock(&module_mutex);
70831 dynamic_debug_remove(info.debug);
70832 synchronize_sched();
70833 - kfree(mod->args);
70834 free_arch_cleanup:
70835 module_arch_cleanup(mod);
70836 free_modinfo:
70837 free_modinfo(mod);
70838 + kfree(mod->args);
70839 free_unload:
70840 module_unload_free(mod);
70841 unlink_mod:
70842 @@ -3155,16 +3288,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
70843 MODULE_STATE_COMING, mod);
70844
70845 /* Set RO and NX regions for core */
70846 - set_section_ro_nx(mod->module_core,
70847 - mod->core_text_size,
70848 - mod->core_ro_size,
70849 - mod->core_size);
70850 + set_section_ro_nx(mod->module_core_rx,
70851 + mod->core_size_rx,
70852 + mod->core_size_rx,
70853 + mod->core_size_rx);
70854
70855 /* Set RO and NX regions for init */
70856 - set_section_ro_nx(mod->module_init,
70857 - mod->init_text_size,
70858 - mod->init_ro_size,
70859 - mod->init_size);
70860 + set_section_ro_nx(mod->module_init_rx,
70861 + mod->init_size_rx,
70862 + mod->init_size_rx,
70863 + mod->init_size_rx);
70864
70865 do_mod_ctors(mod);
70866 /* Start the module */
70867 @@ -3209,11 +3342,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
70868 mod->strtab = mod->core_strtab;
70869 #endif
70870 unset_module_init_ro_nx(mod);
70871 - module_free(mod, mod->module_init);
70872 - mod->module_init = NULL;
70873 - mod->init_size = 0;
70874 - mod->init_ro_size = 0;
70875 - mod->init_text_size = 0;
70876 + module_free(mod, mod->module_init_rw);
70877 + module_free_exec(mod, mod->module_init_rx);
70878 + mod->module_init_rw = NULL;
70879 + mod->module_init_rx = NULL;
70880 + mod->init_size_rw = 0;
70881 + mod->init_size_rx = 0;
70882 mutex_unlock(&module_mutex);
70883 wake_up_all(&module_wq);
70884
70885 @@ -3245,10 +3379,16 @@ static const char *get_ksymbol(struct module *mod,
70886 unsigned long nextval;
70887
70888 /* At worse, next value is at end of module */
70889 - if (within_module_init(addr, mod))
70890 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
70891 + if (within_module_init_rx(addr, mod))
70892 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
70893 + else if (within_module_init_rw(addr, mod))
70894 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
70895 + else if (within_module_core_rx(addr, mod))
70896 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
70897 + else if (within_module_core_rw(addr, mod))
70898 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
70899 else
70900 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
70901 + return NULL;
70902
70903 /* Scan for closest preceding symbol, and next symbol. (ELF
70904 starts real symbols at 1). */
70905 @@ -3501,7 +3641,7 @@ static int m_show(struct seq_file *m, void *p)
70906 return 0;
70907
70908 seq_printf(m, "%s %u",
70909 - mod->name, mod->init_size + mod->core_size);
70910 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
70911 print_unload_info(m, mod);
70912
70913 /* Informative for users. */
70914 @@ -3510,7 +3650,7 @@ static int m_show(struct seq_file *m, void *p)
70915 mod->state == MODULE_STATE_COMING ? "Loading":
70916 "Live");
70917 /* Used by oprofile and other similar tools. */
70918 - seq_printf(m, " 0x%pK", mod->module_core);
70919 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
70920
70921 /* Taints info */
70922 if (mod->taints)
70923 @@ -3546,7 +3686,17 @@ static const struct file_operations proc_modules_operations = {
70924
70925 static int __init proc_modules_init(void)
70926 {
70927 +#ifndef CONFIG_GRKERNSEC_HIDESYM
70928 +#ifdef CONFIG_GRKERNSEC_PROC_USER
70929 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
70930 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70931 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
70932 +#else
70933 proc_create("modules", 0, NULL, &proc_modules_operations);
70934 +#endif
70935 +#else
70936 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
70937 +#endif
70938 return 0;
70939 }
70940 module_init(proc_modules_init);
70941 @@ -3607,14 +3757,14 @@ struct module *__module_address(unsigned long addr)
70942 {
70943 struct module *mod;
70944
70945 - if (addr < module_addr_min || addr > module_addr_max)
70946 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
70947 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
70948 return NULL;
70949
70950 list_for_each_entry_rcu(mod, &modules, list) {
70951 if (mod->state == MODULE_STATE_UNFORMED)
70952 continue;
70953 - if (within_module_core(addr, mod)
70954 - || within_module_init(addr, mod))
70955 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
70956 return mod;
70957 }
70958 return NULL;
70959 @@ -3649,11 +3799,20 @@ bool is_module_text_address(unsigned long addr)
70960 */
70961 struct module *__module_text_address(unsigned long addr)
70962 {
70963 - struct module *mod = __module_address(addr);
70964 + struct module *mod;
70965 +
70966 +#ifdef CONFIG_X86_32
70967 + addr = ktla_ktva(addr);
70968 +#endif
70969 +
70970 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
70971 + return NULL;
70972 +
70973 + mod = __module_address(addr);
70974 +
70975 if (mod) {
70976 /* Make sure it's within the text section. */
70977 - if (!within(addr, mod->module_init, mod->init_text_size)
70978 - && !within(addr, mod->module_core, mod->core_text_size))
70979 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
70980 mod = NULL;
70981 }
70982 return mod;
70983 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
70984 index 7e3443f..b2a1e6b 100644
70985 --- a/kernel/mutex-debug.c
70986 +++ b/kernel/mutex-debug.c
70987 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
70988 }
70989
70990 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
70991 - struct thread_info *ti)
70992 + struct task_struct *task)
70993 {
70994 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
70995
70996 /* Mark the current thread as blocked on the lock: */
70997 - ti->task->blocked_on = waiter;
70998 + task->blocked_on = waiter;
70999 }
71000
71001 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
71002 - struct thread_info *ti)
71003 + struct task_struct *task)
71004 {
71005 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
71006 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
71007 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
71008 - ti->task->blocked_on = NULL;
71009 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
71010 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
71011 + task->blocked_on = NULL;
71012
71013 list_del_init(&waiter->list);
71014 waiter->task = NULL;
71015 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
71016 index 0799fd3..d06ae3b 100644
71017 --- a/kernel/mutex-debug.h
71018 +++ b/kernel/mutex-debug.h
71019 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
71020 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
71021 extern void debug_mutex_add_waiter(struct mutex *lock,
71022 struct mutex_waiter *waiter,
71023 - struct thread_info *ti);
71024 + struct task_struct *task);
71025 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
71026 - struct thread_info *ti);
71027 + struct task_struct *task);
71028 extern void debug_mutex_unlock(struct mutex *lock);
71029 extern void debug_mutex_init(struct mutex *lock, const char *name,
71030 struct lock_class_key *key);
71031 diff --git a/kernel/mutex.c b/kernel/mutex.c
71032 index a307cc9..27fd2e9 100644
71033 --- a/kernel/mutex.c
71034 +++ b/kernel/mutex.c
71035 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
71036 spin_lock_mutex(&lock->wait_lock, flags);
71037
71038 debug_mutex_lock_common(lock, &waiter);
71039 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
71040 + debug_mutex_add_waiter(lock, &waiter, task);
71041
71042 /* add waiting tasks to the end of the waitqueue (FIFO): */
71043 list_add_tail(&waiter.list, &lock->wait_list);
71044 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
71045 * TASK_UNINTERRUPTIBLE case.)
71046 */
71047 if (unlikely(signal_pending_state(state, task))) {
71048 - mutex_remove_waiter(lock, &waiter,
71049 - task_thread_info(task));
71050 + mutex_remove_waiter(lock, &waiter, task);
71051 mutex_release(&lock->dep_map, 1, ip);
71052 spin_unlock_mutex(&lock->wait_lock, flags);
71053
71054 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
71055 done:
71056 lock_acquired(&lock->dep_map, ip);
71057 /* got the lock - rejoice! */
71058 - mutex_remove_waiter(lock, &waiter, current_thread_info());
71059 + mutex_remove_waiter(lock, &waiter, task);
71060 mutex_set_owner(lock);
71061
71062 /* set it to 0 if there are no waiters left: */
71063 diff --git a/kernel/notifier.c b/kernel/notifier.c
71064 index 2d5cc4c..d9ea600 100644
71065 --- a/kernel/notifier.c
71066 +++ b/kernel/notifier.c
71067 @@ -5,6 +5,7 @@
71068 #include <linux/rcupdate.h>
71069 #include <linux/vmalloc.h>
71070 #include <linux/reboot.h>
71071 +#include <linux/mm.h>
71072
71073 /*
71074 * Notifier list for kernel code which wants to be called
71075 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
71076 while ((*nl) != NULL) {
71077 if (n->priority > (*nl)->priority)
71078 break;
71079 - nl = &((*nl)->next);
71080 + nl = (struct notifier_block **)&((*nl)->next);
71081 }
71082 - n->next = *nl;
71083 + pax_open_kernel();
71084 + *(const void **)&n->next = *nl;
71085 rcu_assign_pointer(*nl, n);
71086 + pax_close_kernel();
71087 return 0;
71088 }
71089
71090 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
71091 return 0;
71092 if (n->priority > (*nl)->priority)
71093 break;
71094 - nl = &((*nl)->next);
71095 + nl = (struct notifier_block **)&((*nl)->next);
71096 }
71097 - n->next = *nl;
71098 + pax_open_kernel();
71099 + *(const void **)&n->next = *nl;
71100 rcu_assign_pointer(*nl, n);
71101 + pax_close_kernel();
71102 return 0;
71103 }
71104
71105 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
71106 {
71107 while ((*nl) != NULL) {
71108 if ((*nl) == n) {
71109 + pax_open_kernel();
71110 rcu_assign_pointer(*nl, n->next);
71111 + pax_close_kernel();
71112 return 0;
71113 }
71114 - nl = &((*nl)->next);
71115 + nl = (struct notifier_block **)&((*nl)->next);
71116 }
71117 return -ENOENT;
71118 }
71119 diff --git a/kernel/panic.c b/kernel/panic.c
71120 index e1b2822..5edc1d9 100644
71121 --- a/kernel/panic.c
71122 +++ b/kernel/panic.c
71123 @@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
71124 const char *board;
71125
71126 printk(KERN_WARNING "------------[ cut here ]------------\n");
71127 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
71128 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
71129 board = dmi_get_system_info(DMI_PRODUCT_NAME);
71130 if (board)
71131 printk(KERN_WARNING "Hardware name: %s\n", board);
71132 @@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
71133 */
71134 void __stack_chk_fail(void)
71135 {
71136 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
71137 + dump_stack();
71138 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
71139 __builtin_return_address(0));
71140 }
71141 EXPORT_SYMBOL(__stack_chk_fail);
71142 diff --git a/kernel/pid.c b/kernel/pid.c
71143 index aebd4f5..1693c13 100644
71144 --- a/kernel/pid.c
71145 +++ b/kernel/pid.c
71146 @@ -33,6 +33,7 @@
71147 #include <linux/rculist.h>
71148 #include <linux/bootmem.h>
71149 #include <linux/hash.h>
71150 +#include <linux/security.h>
71151 #include <linux/pid_namespace.h>
71152 #include <linux/init_task.h>
71153 #include <linux/syscalls.h>
71154 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
71155
71156 int pid_max = PID_MAX_DEFAULT;
71157
71158 -#define RESERVED_PIDS 300
71159 +#define RESERVED_PIDS 500
71160
71161 int pid_max_min = RESERVED_PIDS + 1;
71162 int pid_max_max = PID_MAX_LIMIT;
71163 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
71164 */
71165 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
71166 {
71167 + struct task_struct *task;
71168 +
71169 rcu_lockdep_assert(rcu_read_lock_held(),
71170 "find_task_by_pid_ns() needs rcu_read_lock()"
71171 " protection");
71172 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
71173 +
71174 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
71175 +
71176 + if (gr_pid_is_chrooted(task))
71177 + return NULL;
71178 +
71179 + return task;
71180 }
71181
71182 struct task_struct *find_task_by_vpid(pid_t vnr)
71183 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
71184 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
71185 }
71186
71187 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
71188 +{
71189 + rcu_lockdep_assert(rcu_read_lock_held(),
71190 + "find_task_by_pid_ns() needs rcu_read_lock()"
71191 + " protection");
71192 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
71193 +}
71194 +
71195 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
71196 {
71197 struct pid *pid;
71198 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
71199 index 125cb67..2e5c8ad 100644
71200 --- a/kernel/posix-cpu-timers.c
71201 +++ b/kernel/posix-cpu-timers.c
71202 @@ -6,9 +6,11 @@
71203 #include <linux/posix-timers.h>
71204 #include <linux/errno.h>
71205 #include <linux/math64.h>
71206 +#include <linux/security.h>
71207 #include <asm/uaccess.h>
71208 #include <linux/kernel_stat.h>
71209 #include <trace/events/timer.h>
71210 +#include <linux/random.h>
71211
71212 /*
71213 * Called after updating RLIMIT_CPU to run cpu timer and update
71214 @@ -494,6 +496,8 @@ static void cleanup_timers(struct list_head *head,
71215 */
71216 void posix_cpu_timers_exit(struct task_struct *tsk)
71217 {
71218 + add_device_randomness((const void*) &tsk->se.sum_exec_runtime,
71219 + sizeof(unsigned long long));
71220 cleanup_timers(tsk->cpu_timers,
71221 tsk->utime, tsk->stime, tsk->se.sum_exec_runtime);
71222
71223 @@ -1578,14 +1582,14 @@ struct k_clock clock_posix_cpu = {
71224
71225 static __init int init_posix_cpu_timers(void)
71226 {
71227 - struct k_clock process = {
71228 + static struct k_clock process = {
71229 .clock_getres = process_cpu_clock_getres,
71230 .clock_get = process_cpu_clock_get,
71231 .timer_create = process_cpu_timer_create,
71232 .nsleep = process_cpu_nsleep,
71233 .nsleep_restart = process_cpu_nsleep_restart,
71234 };
71235 - struct k_clock thread = {
71236 + static struct k_clock thread = {
71237 .clock_getres = thread_cpu_clock_getres,
71238 .clock_get = thread_cpu_clock_get,
71239 .timer_create = thread_cpu_timer_create,
71240 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
71241 index 69185ae..cc2847a 100644
71242 --- a/kernel/posix-timers.c
71243 +++ b/kernel/posix-timers.c
71244 @@ -43,6 +43,7 @@
71245 #include <linux/idr.h>
71246 #include <linux/posix-clock.h>
71247 #include <linux/posix-timers.h>
71248 +#include <linux/grsecurity.h>
71249 #include <linux/syscalls.h>
71250 #include <linux/wait.h>
71251 #include <linux/workqueue.h>
71252 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
71253 * which we beg off on and pass to do_sys_settimeofday().
71254 */
71255
71256 -static struct k_clock posix_clocks[MAX_CLOCKS];
71257 +static struct k_clock *posix_clocks[MAX_CLOCKS];
71258
71259 /*
71260 * These ones are defined below.
71261 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
71262 */
71263 static __init int init_posix_timers(void)
71264 {
71265 - struct k_clock clock_realtime = {
71266 + static struct k_clock clock_realtime = {
71267 .clock_getres = hrtimer_get_res,
71268 .clock_get = posix_clock_realtime_get,
71269 .clock_set = posix_clock_realtime_set,
71270 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
71271 .timer_get = common_timer_get,
71272 .timer_del = common_timer_del,
71273 };
71274 - struct k_clock clock_monotonic = {
71275 + static struct k_clock clock_monotonic = {
71276 .clock_getres = hrtimer_get_res,
71277 .clock_get = posix_ktime_get_ts,
71278 .nsleep = common_nsleep,
71279 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
71280 .timer_get = common_timer_get,
71281 .timer_del = common_timer_del,
71282 };
71283 - struct k_clock clock_monotonic_raw = {
71284 + static struct k_clock clock_monotonic_raw = {
71285 .clock_getres = hrtimer_get_res,
71286 .clock_get = posix_get_monotonic_raw,
71287 };
71288 - struct k_clock clock_realtime_coarse = {
71289 + static struct k_clock clock_realtime_coarse = {
71290 .clock_getres = posix_get_coarse_res,
71291 .clock_get = posix_get_realtime_coarse,
71292 };
71293 - struct k_clock clock_monotonic_coarse = {
71294 + static struct k_clock clock_monotonic_coarse = {
71295 .clock_getres = posix_get_coarse_res,
71296 .clock_get = posix_get_monotonic_coarse,
71297 };
71298 - struct k_clock clock_boottime = {
71299 + static struct k_clock clock_boottime = {
71300 .clock_getres = hrtimer_get_res,
71301 .clock_get = posix_get_boottime,
71302 .nsleep = common_nsleep,
71303 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
71304 return;
71305 }
71306
71307 - posix_clocks[clock_id] = *new_clock;
71308 + posix_clocks[clock_id] = new_clock;
71309 }
71310 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
71311
71312 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
71313 return (id & CLOCKFD_MASK) == CLOCKFD ?
71314 &clock_posix_dynamic : &clock_posix_cpu;
71315
71316 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
71317 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
71318 return NULL;
71319 - return &posix_clocks[id];
71320 + return posix_clocks[id];
71321 }
71322
71323 static int common_timer_create(struct k_itimer *new_timer)
71324 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
71325 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
71326 return -EFAULT;
71327
71328 + /* only the CLOCK_REALTIME clock can be set, all other clocks
71329 + have their clock_set fptr set to a nosettime dummy function
71330 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
71331 + call common_clock_set, which calls do_sys_settimeofday, which
71332 + we hook
71333 + */
71334 +
71335 return kc->clock_set(which_clock, &new_tp);
71336 }
71337
71338 diff --git a/kernel/power/process.c b/kernel/power/process.c
71339 index 87da817..30ddd13 100644
71340 --- a/kernel/power/process.c
71341 +++ b/kernel/power/process.c
71342 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
71343 u64 elapsed_csecs64;
71344 unsigned int elapsed_csecs;
71345 bool wakeup = false;
71346 + bool timedout = false;
71347
71348 do_gettimeofday(&start);
71349
71350 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
71351
71352 while (true) {
71353 todo = 0;
71354 + if (time_after(jiffies, end_time))
71355 + timedout = true;
71356 read_lock(&tasklist_lock);
71357 do_each_thread(g, p) {
71358 if (p == current || !freeze_task(p))
71359 @@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
71360 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
71361 * transition can't race with task state testing here.
71362 */
71363 - if (!task_is_stopped_or_traced(p) &&
71364 - !freezer_should_skip(p))
71365 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
71366 todo++;
71367 + if (timedout) {
71368 + printk(KERN_ERR "Task refusing to freeze:\n");
71369 + sched_show_task(p);
71370 + }
71371 + }
71372 } while_each_thread(g, p);
71373 read_unlock(&tasklist_lock);
71374
71375 @@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
71376 todo += wq_busy;
71377 }
71378
71379 - if (!todo || time_after(jiffies, end_time))
71380 + if (!todo || timedout)
71381 break;
71382
71383 if (pm_wakeup_pending()) {
71384 diff --git a/kernel/printk.c b/kernel/printk.c
71385 index f8e0b5a..dda2a5c 100644
71386 --- a/kernel/printk.c
71387 +++ b/kernel/printk.c
71388 @@ -817,6 +817,11 @@ static int check_syslog_permissions(int type, bool from_file)
71389 if (from_file && type != SYSLOG_ACTION_OPEN)
71390 return 0;
71391
71392 +#ifdef CONFIG_GRKERNSEC_DMESG
71393 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
71394 + return -EPERM;
71395 +#endif
71396 +
71397 if (syslog_action_restricted(type)) {
71398 if (capable(CAP_SYSLOG))
71399 return 0;
71400 diff --git a/kernel/profile.c b/kernel/profile.c
71401 index 76b8e77..a2930e8 100644
71402 --- a/kernel/profile.c
71403 +++ b/kernel/profile.c
71404 @@ -39,7 +39,7 @@ struct profile_hit {
71405 /* Oprofile timer tick hook */
71406 static int (*timer_hook)(struct pt_regs *) __read_mostly;
71407
71408 -static atomic_t *prof_buffer;
71409 +static atomic_unchecked_t *prof_buffer;
71410 static unsigned long prof_len, prof_shift;
71411
71412 int prof_on __read_mostly;
71413 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
71414 hits[i].pc = 0;
71415 continue;
71416 }
71417 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
71418 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
71419 hits[i].hits = hits[i].pc = 0;
71420 }
71421 }
71422 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
71423 * Add the current hit(s) and flush the write-queue out
71424 * to the global buffer:
71425 */
71426 - atomic_add(nr_hits, &prof_buffer[pc]);
71427 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
71428 for (i = 0; i < NR_PROFILE_HIT; ++i) {
71429 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
71430 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
71431 hits[i].pc = hits[i].hits = 0;
71432 }
71433 out:
71434 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
71435 {
71436 unsigned long pc;
71437 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
71438 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
71439 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
71440 }
71441 #endif /* !CONFIG_SMP */
71442
71443 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
71444 return -EFAULT;
71445 buf++; p++; count--; read++;
71446 }
71447 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
71448 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
71449 if (copy_to_user(buf, (void *)pnt, count))
71450 return -EFAULT;
71451 read += count;
71452 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
71453 }
71454 #endif
71455 profile_discard_flip_buffers();
71456 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
71457 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
71458 return count;
71459 }
71460
71461 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
71462 index fbea91d..9bf15e8 100644
71463 --- a/kernel/ptrace.c
71464 +++ b/kernel/ptrace.c
71465 @@ -319,7 +319,7 @@ static int ptrace_attach(struct task_struct *task, long request,
71466
71467 if (seize)
71468 flags |= PT_SEIZED;
71469 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
71470 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
71471 flags |= PT_PTRACE_CAP;
71472 task->ptrace = flags;
71473
71474 @@ -526,7 +526,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
71475 break;
71476 return -EIO;
71477 }
71478 - if (copy_to_user(dst, buf, retval))
71479 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
71480 return -EFAULT;
71481 copied += retval;
71482 src += retval;
71483 @@ -711,7 +711,7 @@ int ptrace_request(struct task_struct *child, long request,
71484 bool seized = child->ptrace & PT_SEIZED;
71485 int ret = -EIO;
71486 siginfo_t siginfo, *si;
71487 - void __user *datavp = (void __user *) data;
71488 + void __user *datavp = (__force void __user *) data;
71489 unsigned long __user *datalp = datavp;
71490 unsigned long flags;
71491
71492 @@ -913,14 +913,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
71493 goto out;
71494 }
71495
71496 + if (gr_handle_ptrace(child, request)) {
71497 + ret = -EPERM;
71498 + goto out_put_task_struct;
71499 + }
71500 +
71501 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
71502 ret = ptrace_attach(child, request, addr, data);
71503 /*
71504 * Some architectures need to do book-keeping after
71505 * a ptrace attach.
71506 */
71507 - if (!ret)
71508 + if (!ret) {
71509 arch_ptrace_attach(child);
71510 + gr_audit_ptrace(child);
71511 + }
71512 goto out_put_task_struct;
71513 }
71514
71515 @@ -948,7 +955,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
71516 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
71517 if (copied != sizeof(tmp))
71518 return -EIO;
71519 - return put_user(tmp, (unsigned long __user *)data);
71520 + return put_user(tmp, (__force unsigned long __user *)data);
71521 }
71522
71523 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
71524 @@ -1058,14 +1065,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
71525 goto out;
71526 }
71527
71528 + if (gr_handle_ptrace(child, request)) {
71529 + ret = -EPERM;
71530 + goto out_put_task_struct;
71531 + }
71532 +
71533 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
71534 ret = ptrace_attach(child, request, addr, data);
71535 /*
71536 * Some architectures need to do book-keeping after
71537 * a ptrace attach.
71538 */
71539 - if (!ret)
71540 + if (!ret) {
71541 arch_ptrace_attach(child);
71542 + gr_audit_ptrace(child);
71543 + }
71544 goto out_put_task_struct;
71545 }
71546
71547 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
71548 index e4c6a59..c86621a 100644
71549 --- a/kernel/rcutiny.c
71550 +++ b/kernel/rcutiny.c
71551 @@ -46,7 +46,7 @@
71552 struct rcu_ctrlblk;
71553 static void invoke_rcu_callbacks(void);
71554 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
71555 -static void rcu_process_callbacks(struct softirq_action *unused);
71556 +static void rcu_process_callbacks(void);
71557 static void __call_rcu(struct rcu_head *head,
71558 void (*func)(struct rcu_head *rcu),
71559 struct rcu_ctrlblk *rcp);
71560 @@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
71561 rcu_is_callbacks_kthread()));
71562 }
71563
71564 -static void rcu_process_callbacks(struct softirq_action *unused)
71565 +static void rcu_process_callbacks(void)
71566 {
71567 __rcu_process_callbacks(&rcu_sched_ctrlblk);
71568 __rcu_process_callbacks(&rcu_bh_ctrlblk);
71569 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
71570 index 3d01902..afbf46e 100644
71571 --- a/kernel/rcutiny_plugin.h
71572 +++ b/kernel/rcutiny_plugin.h
71573 @@ -893,7 +893,7 @@ static int rcu_kthread(void *arg)
71574 have_rcu_kthread_work = morework;
71575 local_irq_restore(flags);
71576 if (work)
71577 - rcu_process_callbacks(NULL);
71578 + rcu_process_callbacks();
71579 schedule_timeout_interruptible(1); /* Leave CPU for others. */
71580 }
71581
71582 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
71583 index aaa7b9f..055ff1e 100644
71584 --- a/kernel/rcutorture.c
71585 +++ b/kernel/rcutorture.c
71586 @@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
71587 { 0 };
71588 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
71589 { 0 };
71590 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
71591 -static atomic_t n_rcu_torture_alloc;
71592 -static atomic_t n_rcu_torture_alloc_fail;
71593 -static atomic_t n_rcu_torture_free;
71594 -static atomic_t n_rcu_torture_mberror;
71595 -static atomic_t n_rcu_torture_error;
71596 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
71597 +static atomic_unchecked_t n_rcu_torture_alloc;
71598 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
71599 +static atomic_unchecked_t n_rcu_torture_free;
71600 +static atomic_unchecked_t n_rcu_torture_mberror;
71601 +static atomic_unchecked_t n_rcu_torture_error;
71602 static long n_rcu_torture_barrier_error;
71603 static long n_rcu_torture_boost_ktrerror;
71604 static long n_rcu_torture_boost_rterror;
71605 @@ -272,11 +272,11 @@ rcu_torture_alloc(void)
71606
71607 spin_lock_bh(&rcu_torture_lock);
71608 if (list_empty(&rcu_torture_freelist)) {
71609 - atomic_inc(&n_rcu_torture_alloc_fail);
71610 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
71611 spin_unlock_bh(&rcu_torture_lock);
71612 return NULL;
71613 }
71614 - atomic_inc(&n_rcu_torture_alloc);
71615 + atomic_inc_unchecked(&n_rcu_torture_alloc);
71616 p = rcu_torture_freelist.next;
71617 list_del_init(p);
71618 spin_unlock_bh(&rcu_torture_lock);
71619 @@ -289,7 +289,7 @@ rcu_torture_alloc(void)
71620 static void
71621 rcu_torture_free(struct rcu_torture *p)
71622 {
71623 - atomic_inc(&n_rcu_torture_free);
71624 + atomic_inc_unchecked(&n_rcu_torture_free);
71625 spin_lock_bh(&rcu_torture_lock);
71626 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
71627 spin_unlock_bh(&rcu_torture_lock);
71628 @@ -410,7 +410,7 @@ rcu_torture_cb(struct rcu_head *p)
71629 i = rp->rtort_pipe_count;
71630 if (i > RCU_TORTURE_PIPE_LEN)
71631 i = RCU_TORTURE_PIPE_LEN;
71632 - atomic_inc(&rcu_torture_wcount[i]);
71633 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
71634 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
71635 rp->rtort_mbtest = 0;
71636 rcu_torture_free(rp);
71637 @@ -459,7 +459,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
71638 i = rp->rtort_pipe_count;
71639 if (i > RCU_TORTURE_PIPE_LEN)
71640 i = RCU_TORTURE_PIPE_LEN;
71641 - atomic_inc(&rcu_torture_wcount[i]);
71642 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
71643 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
71644 rp->rtort_mbtest = 0;
71645 list_del(&rp->rtort_free);
71646 @@ -1002,7 +1002,7 @@ rcu_torture_writer(void *arg)
71647 i = old_rp->rtort_pipe_count;
71648 if (i > RCU_TORTURE_PIPE_LEN)
71649 i = RCU_TORTURE_PIPE_LEN;
71650 - atomic_inc(&rcu_torture_wcount[i]);
71651 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
71652 old_rp->rtort_pipe_count++;
71653 cur_ops->deferred_free(old_rp);
71654 }
71655 @@ -1087,7 +1087,7 @@ static void rcu_torture_timer(unsigned long unused)
71656 }
71657 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
71658 if (p->rtort_mbtest == 0)
71659 - atomic_inc(&n_rcu_torture_mberror);
71660 + atomic_inc_unchecked(&n_rcu_torture_mberror);
71661 spin_lock(&rand_lock);
71662 cur_ops->read_delay(&rand);
71663 n_rcu_torture_timers++;
71664 @@ -1151,7 +1151,7 @@ rcu_torture_reader(void *arg)
71665 }
71666 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
71667 if (p->rtort_mbtest == 0)
71668 - atomic_inc(&n_rcu_torture_mberror);
71669 + atomic_inc_unchecked(&n_rcu_torture_mberror);
71670 cur_ops->read_delay(&rand);
71671 preempt_disable();
71672 pipe_count = p->rtort_pipe_count;
71673 @@ -1210,11 +1210,11 @@ rcu_torture_printk(char *page)
71674 rcu_torture_current,
71675 rcu_torture_current_version,
71676 list_empty(&rcu_torture_freelist),
71677 - atomic_read(&n_rcu_torture_alloc),
71678 - atomic_read(&n_rcu_torture_alloc_fail),
71679 - atomic_read(&n_rcu_torture_free));
71680 + atomic_read_unchecked(&n_rcu_torture_alloc),
71681 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
71682 + atomic_read_unchecked(&n_rcu_torture_free));
71683 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
71684 - atomic_read(&n_rcu_torture_mberror),
71685 + atomic_read_unchecked(&n_rcu_torture_mberror),
71686 n_rcu_torture_boost_ktrerror,
71687 n_rcu_torture_boost_rterror);
71688 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
71689 @@ -1233,14 +1233,14 @@ rcu_torture_printk(char *page)
71690 n_barrier_attempts,
71691 n_rcu_torture_barrier_error);
71692 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
71693 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
71694 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
71695 n_rcu_torture_barrier_error != 0 ||
71696 n_rcu_torture_boost_ktrerror != 0 ||
71697 n_rcu_torture_boost_rterror != 0 ||
71698 n_rcu_torture_boost_failure != 0 ||
71699 i > 1) {
71700 cnt += sprintf(&page[cnt], "!!! ");
71701 - atomic_inc(&n_rcu_torture_error);
71702 + atomic_inc_unchecked(&n_rcu_torture_error);
71703 WARN_ON_ONCE(1);
71704 }
71705 cnt += sprintf(&page[cnt], "Reader Pipe: ");
71706 @@ -1254,7 +1254,7 @@ rcu_torture_printk(char *page)
71707 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
71708 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
71709 cnt += sprintf(&page[cnt], " %d",
71710 - atomic_read(&rcu_torture_wcount[i]));
71711 + atomic_read_unchecked(&rcu_torture_wcount[i]));
71712 }
71713 cnt += sprintf(&page[cnt], "\n");
71714 if (cur_ops->stats)
71715 @@ -1938,7 +1938,7 @@ rcu_torture_cleanup(void)
71716
71717 if (cur_ops->cleanup)
71718 cur_ops->cleanup();
71719 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
71720 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
71721 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
71722 else if (n_online_successes != n_online_attempts ||
71723 n_offline_successes != n_offline_attempts)
71724 @@ -2007,18 +2007,18 @@ rcu_torture_init(void)
71725
71726 rcu_torture_current = NULL;
71727 rcu_torture_current_version = 0;
71728 - atomic_set(&n_rcu_torture_alloc, 0);
71729 - atomic_set(&n_rcu_torture_alloc_fail, 0);
71730 - atomic_set(&n_rcu_torture_free, 0);
71731 - atomic_set(&n_rcu_torture_mberror, 0);
71732 - atomic_set(&n_rcu_torture_error, 0);
71733 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
71734 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
71735 + atomic_set_unchecked(&n_rcu_torture_free, 0);
71736 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
71737 + atomic_set_unchecked(&n_rcu_torture_error, 0);
71738 n_rcu_torture_barrier_error = 0;
71739 n_rcu_torture_boost_ktrerror = 0;
71740 n_rcu_torture_boost_rterror = 0;
71741 n_rcu_torture_boost_failure = 0;
71742 n_rcu_torture_boosts = 0;
71743 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
71744 - atomic_set(&rcu_torture_wcount[i], 0);
71745 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
71746 for_each_possible_cpu(cpu) {
71747 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
71748 per_cpu(rcu_torture_count, cpu)[i] = 0;
71749 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
71750 index 2682295..0f2297e 100644
71751 --- a/kernel/rcutree.c
71752 +++ b/kernel/rcutree.c
71753 @@ -348,9 +348,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
71754 rcu_prepare_for_idle(smp_processor_id());
71755 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
71756 smp_mb__before_atomic_inc(); /* See above. */
71757 - atomic_inc(&rdtp->dynticks);
71758 + atomic_inc_unchecked(&rdtp->dynticks);
71759 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
71760 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
71761 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
71762
71763 /*
71764 * It is illegal to enter an extended quiescent state while
71765 @@ -508,10 +508,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
71766 int user)
71767 {
71768 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
71769 - atomic_inc(&rdtp->dynticks);
71770 + atomic_inc_unchecked(&rdtp->dynticks);
71771 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
71772 smp_mb__after_atomic_inc(); /* See above. */
71773 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
71774 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
71775 rcu_cleanup_after_idle(smp_processor_id());
71776 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
71777 if (!user && !is_idle_task(current)) {
71778 @@ -670,14 +670,14 @@ void rcu_nmi_enter(void)
71779 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
71780
71781 if (rdtp->dynticks_nmi_nesting == 0 &&
71782 - (atomic_read(&rdtp->dynticks) & 0x1))
71783 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
71784 return;
71785 rdtp->dynticks_nmi_nesting++;
71786 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
71787 - atomic_inc(&rdtp->dynticks);
71788 + atomic_inc_unchecked(&rdtp->dynticks);
71789 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
71790 smp_mb__after_atomic_inc(); /* See above. */
71791 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
71792 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
71793 }
71794
71795 /**
71796 @@ -696,9 +696,9 @@ void rcu_nmi_exit(void)
71797 return;
71798 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
71799 smp_mb__before_atomic_inc(); /* See above. */
71800 - atomic_inc(&rdtp->dynticks);
71801 + atomic_inc_unchecked(&rdtp->dynticks);
71802 smp_mb__after_atomic_inc(); /* Force delay to next write. */
71803 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
71804 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
71805 }
71806
71807 /**
71808 @@ -712,7 +712,7 @@ int rcu_is_cpu_idle(void)
71809 int ret;
71810
71811 preempt_disable();
71812 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
71813 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
71814 preempt_enable();
71815 return ret;
71816 }
71817 @@ -795,7 +795,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
71818 */
71819 static int dyntick_save_progress_counter(struct rcu_data *rdp)
71820 {
71821 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
71822 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
71823 return (rdp->dynticks_snap & 0x1) == 0;
71824 }
71825
71826 @@ -810,7 +810,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
71827 unsigned int curr;
71828 unsigned int snap;
71829
71830 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
71831 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
71832 snap = (unsigned int)rdp->dynticks_snap;
71833
71834 /*
71835 @@ -858,10 +858,10 @@ static int jiffies_till_stall_check(void)
71836 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
71837 */
71838 if (till_stall_check < 3) {
71839 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
71840 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
71841 till_stall_check = 3;
71842 } else if (till_stall_check > 300) {
71843 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
71844 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
71845 till_stall_check = 300;
71846 }
71847 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
71848 @@ -1589,7 +1589,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
71849 rsp->qlen += rdp->qlen;
71850 rdp->n_cbs_orphaned += rdp->qlen;
71851 rdp->qlen_lazy = 0;
71852 - ACCESS_ONCE(rdp->qlen) = 0;
71853 + ACCESS_ONCE_RW(rdp->qlen) = 0;
71854 }
71855
71856 /*
71857 @@ -1831,7 +1831,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
71858 }
71859 smp_mb(); /* List handling before counting for rcu_barrier(). */
71860 rdp->qlen_lazy -= count_lazy;
71861 - ACCESS_ONCE(rdp->qlen) -= count;
71862 + ACCESS_ONCE_RW(rdp->qlen) -= count;
71863 rdp->n_cbs_invoked += count;
71864
71865 /* Reinstate batch limit if we have worked down the excess. */
71866 @@ -2024,7 +2024,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
71867 /*
71868 * Do RCU core processing for the current CPU.
71869 */
71870 -static void rcu_process_callbacks(struct softirq_action *unused)
71871 +static void rcu_process_callbacks(void)
71872 {
71873 struct rcu_state *rsp;
71874
71875 @@ -2136,7 +2136,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
71876 local_irq_restore(flags);
71877 return;
71878 }
71879 - ACCESS_ONCE(rdp->qlen)++;
71880 + ACCESS_ONCE_RW(rdp->qlen)++;
71881 if (lazy)
71882 rdp->qlen_lazy++;
71883 else
71884 @@ -2250,8 +2250,8 @@ void synchronize_rcu_bh(void)
71885 }
71886 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
71887
71888 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
71889 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
71890 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
71891 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
71892
71893 static int synchronize_sched_expedited_cpu_stop(void *data)
71894 {
71895 @@ -2312,7 +2312,7 @@ void synchronize_sched_expedited(void)
71896 int firstsnap, s, snap, trycount = 0;
71897
71898 /* Note that atomic_inc_return() implies full memory barrier. */
71899 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
71900 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
71901 get_online_cpus();
71902 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
71903
71904 @@ -2334,7 +2334,7 @@ void synchronize_sched_expedited(void)
71905 }
71906
71907 /* Check to see if someone else did our work for us. */
71908 - s = atomic_read(&sync_sched_expedited_done);
71909 + s = atomic_read_unchecked(&sync_sched_expedited_done);
71910 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
71911 smp_mb(); /* ensure test happens before caller kfree */
71912 return;
71913 @@ -2349,7 +2349,7 @@ void synchronize_sched_expedited(void)
71914 * grace period works for us.
71915 */
71916 get_online_cpus();
71917 - snap = atomic_read(&sync_sched_expedited_started);
71918 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
71919 smp_mb(); /* ensure read is before try_stop_cpus(). */
71920 }
71921
71922 @@ -2360,12 +2360,12 @@ void synchronize_sched_expedited(void)
71923 * than we did beat us to the punch.
71924 */
71925 do {
71926 - s = atomic_read(&sync_sched_expedited_done);
71927 + s = atomic_read_unchecked(&sync_sched_expedited_done);
71928 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
71929 smp_mb(); /* ensure test happens before caller kfree */
71930 break;
71931 }
71932 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
71933 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
71934
71935 put_online_cpus();
71936 }
71937 @@ -2539,7 +2539,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
71938 * ACCESS_ONCE() to prevent the compiler from speculating
71939 * the increment to precede the early-exit check.
71940 */
71941 - ACCESS_ONCE(rsp->n_barrier_done)++;
71942 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
71943 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
71944 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
71945 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
71946 @@ -2581,7 +2581,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
71947
71948 /* Increment ->n_barrier_done to prevent duplicate work. */
71949 smp_mb(); /* Keep increment after above mechanism. */
71950 - ACCESS_ONCE(rsp->n_barrier_done)++;
71951 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
71952 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
71953 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
71954 smp_mb(); /* Keep increment before caller's subsequent code. */
71955 @@ -2626,10 +2626,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
71956 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
71957 init_callback_list(rdp);
71958 rdp->qlen_lazy = 0;
71959 - ACCESS_ONCE(rdp->qlen) = 0;
71960 + ACCESS_ONCE_RW(rdp->qlen) = 0;
71961 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
71962 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
71963 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
71964 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
71965 #ifdef CONFIG_RCU_USER_QS
71966 WARN_ON_ONCE(rdp->dynticks->in_user);
71967 #endif
71968 @@ -2664,8 +2664,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
71969 rdp->blimit = blimit;
71970 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
71971 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
71972 - atomic_set(&rdp->dynticks->dynticks,
71973 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
71974 + atomic_set_unchecked(&rdp->dynticks->dynticks,
71975 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
71976 rcu_prepare_for_idle_init(cpu);
71977 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
71978
71979 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
71980 index a240f03..d469618 100644
71981 --- a/kernel/rcutree.h
71982 +++ b/kernel/rcutree.h
71983 @@ -86,7 +86,7 @@ struct rcu_dynticks {
71984 long long dynticks_nesting; /* Track irq/process nesting level. */
71985 /* Process level is worth LLONG_MAX/2. */
71986 int dynticks_nmi_nesting; /* Track NMI nesting level. */
71987 - atomic_t dynticks; /* Even value for idle, else odd. */
71988 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
71989 #ifdef CONFIG_RCU_FAST_NO_HZ
71990 int dyntick_drain; /* Prepare-for-idle state variable. */
71991 unsigned long dyntick_holdoff;
71992 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
71993 index f921154..34c4873 100644
71994 --- a/kernel/rcutree_plugin.h
71995 +++ b/kernel/rcutree_plugin.h
71996 @@ -865,7 +865,7 @@ void synchronize_rcu_expedited(void)
71997
71998 /* Clean up and exit. */
71999 smp_mb(); /* ensure expedited GP seen before counter increment. */
72000 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
72001 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
72002 unlock_mb_ret:
72003 mutex_unlock(&sync_rcu_preempt_exp_mutex);
72004 mb_ret:
72005 @@ -2040,7 +2040,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
72006 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
72007 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
72008 cpu, ticks_value, ticks_title,
72009 - atomic_read(&rdtp->dynticks) & 0xfff,
72010 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
72011 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
72012 fast_no_hz);
72013 }
72014 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
72015 index 693513b..b9f1d63 100644
72016 --- a/kernel/rcutree_trace.c
72017 +++ b/kernel/rcutree_trace.c
72018 @@ -92,7 +92,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
72019 rdp->completed, rdp->gpnum,
72020 rdp->passed_quiesce, rdp->qs_pending);
72021 seq_printf(m, " dt=%d/%llx/%d df=%lu",
72022 - atomic_read(&rdp->dynticks->dynticks),
72023 + atomic_read_unchecked(&rdp->dynticks->dynticks),
72024 rdp->dynticks->dynticks_nesting,
72025 rdp->dynticks->dynticks_nmi_nesting,
72026 rdp->dynticks_fqs);
72027 @@ -154,7 +154,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
72028 rdp->completed, rdp->gpnum,
72029 rdp->passed_quiesce, rdp->qs_pending);
72030 seq_printf(m, ",%d,%llx,%d,%lu",
72031 - atomic_read(&rdp->dynticks->dynticks),
72032 + atomic_read_unchecked(&rdp->dynticks->dynticks),
72033 rdp->dynticks->dynticks_nesting,
72034 rdp->dynticks->dynticks_nmi_nesting,
72035 rdp->dynticks_fqs);
72036 diff --git a/kernel/resource.c b/kernel/resource.c
72037 index 73f35d4..4684fc4 100644
72038 --- a/kernel/resource.c
72039 +++ b/kernel/resource.c
72040 @@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
72041
72042 static int __init ioresources_init(void)
72043 {
72044 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
72045 +#ifdef CONFIG_GRKERNSEC_PROC_USER
72046 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
72047 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
72048 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72049 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
72050 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
72051 +#endif
72052 +#else
72053 proc_create("ioports", 0, NULL, &proc_ioports_operations);
72054 proc_create("iomem", 0, NULL, &proc_iomem_operations);
72055 +#endif
72056 return 0;
72057 }
72058 __initcall(ioresources_init);
72059 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
72060 index 98ec494..4241d6d 100644
72061 --- a/kernel/rtmutex-tester.c
72062 +++ b/kernel/rtmutex-tester.c
72063 @@ -20,7 +20,7 @@
72064 #define MAX_RT_TEST_MUTEXES 8
72065
72066 static spinlock_t rttest_lock;
72067 -static atomic_t rttest_event;
72068 +static atomic_unchecked_t rttest_event;
72069
72070 struct test_thread_data {
72071 int opcode;
72072 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72073
72074 case RTTEST_LOCKCONT:
72075 td->mutexes[td->opdata] = 1;
72076 - td->event = atomic_add_return(1, &rttest_event);
72077 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72078 return 0;
72079
72080 case RTTEST_RESET:
72081 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72082 return 0;
72083
72084 case RTTEST_RESETEVENT:
72085 - atomic_set(&rttest_event, 0);
72086 + atomic_set_unchecked(&rttest_event, 0);
72087 return 0;
72088
72089 default:
72090 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72091 return ret;
72092
72093 td->mutexes[id] = 1;
72094 - td->event = atomic_add_return(1, &rttest_event);
72095 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72096 rt_mutex_lock(&mutexes[id]);
72097 - td->event = atomic_add_return(1, &rttest_event);
72098 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72099 td->mutexes[id] = 4;
72100 return 0;
72101
72102 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72103 return ret;
72104
72105 td->mutexes[id] = 1;
72106 - td->event = atomic_add_return(1, &rttest_event);
72107 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72108 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
72109 - td->event = atomic_add_return(1, &rttest_event);
72110 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72111 td->mutexes[id] = ret ? 0 : 4;
72112 return ret ? -EINTR : 0;
72113
72114 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72115 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
72116 return ret;
72117
72118 - td->event = atomic_add_return(1, &rttest_event);
72119 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72120 rt_mutex_unlock(&mutexes[id]);
72121 - td->event = atomic_add_return(1, &rttest_event);
72122 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72123 td->mutexes[id] = 0;
72124 return 0;
72125
72126 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
72127 break;
72128
72129 td->mutexes[dat] = 2;
72130 - td->event = atomic_add_return(1, &rttest_event);
72131 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72132 break;
72133
72134 default:
72135 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
72136 return;
72137
72138 td->mutexes[dat] = 3;
72139 - td->event = atomic_add_return(1, &rttest_event);
72140 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72141 break;
72142
72143 case RTTEST_LOCKNOWAIT:
72144 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
72145 return;
72146
72147 td->mutexes[dat] = 1;
72148 - td->event = atomic_add_return(1, &rttest_event);
72149 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72150 return;
72151
72152 default:
72153 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
72154 index 15f60d0..7e50319 100644
72155 --- a/kernel/sched/auto_group.c
72156 +++ b/kernel/sched/auto_group.c
72157 @@ -11,7 +11,7 @@
72158
72159 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
72160 static struct autogroup autogroup_default;
72161 -static atomic_t autogroup_seq_nr;
72162 +static atomic_unchecked_t autogroup_seq_nr;
72163
72164 void __init autogroup_init(struct task_struct *init_task)
72165 {
72166 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
72167
72168 kref_init(&ag->kref);
72169 init_rwsem(&ag->lock);
72170 - ag->id = atomic_inc_return(&autogroup_seq_nr);
72171 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
72172 ag->tg = tg;
72173 #ifdef CONFIG_RT_GROUP_SCHED
72174 /*
72175 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
72176 index c529d00..d00b4f3 100644
72177 --- a/kernel/sched/core.c
72178 +++ b/kernel/sched/core.c
72179 @@ -3563,6 +3563,8 @@ int can_nice(const struct task_struct *p, const int nice)
72180 /* convert nice value [19,-20] to rlimit style value [1,40] */
72181 int nice_rlim = 20 - nice;
72182
72183 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
72184 +
72185 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
72186 capable(CAP_SYS_NICE));
72187 }
72188 @@ -3596,7 +3598,8 @@ SYSCALL_DEFINE1(nice, int, increment)
72189 if (nice > 19)
72190 nice = 19;
72191
72192 - if (increment < 0 && !can_nice(current, nice))
72193 + if (increment < 0 && (!can_nice(current, nice) ||
72194 + gr_handle_chroot_nice()))
72195 return -EPERM;
72196
72197 retval = security_task_setnice(current, nice);
72198 @@ -3750,6 +3753,7 @@ recheck:
72199 unsigned long rlim_rtprio =
72200 task_rlimit(p, RLIMIT_RTPRIO);
72201
72202 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
72203 /* can't set/change the rt policy */
72204 if (policy != p->policy && !rlim_rtprio)
72205 return -EPERM;
72206 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
72207 index 6b800a1..0c36227 100644
72208 --- a/kernel/sched/fair.c
72209 +++ b/kernel/sched/fair.c
72210 @@ -4890,7 +4890,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
72211 * run_rebalance_domains is triggered when needed from the scheduler tick.
72212 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
72213 */
72214 -static void run_rebalance_domains(struct softirq_action *h)
72215 +static void run_rebalance_domains(void)
72216 {
72217 int this_cpu = smp_processor_id();
72218 struct rq *this_rq = cpu_rq(this_cpu);
72219 diff --git a/kernel/signal.c b/kernel/signal.c
72220 index 57dde52..2c561f0 100644
72221 --- a/kernel/signal.c
72222 +++ b/kernel/signal.c
72223 @@ -49,12 +49,12 @@ static struct kmem_cache *sigqueue_cachep;
72224
72225 int print_fatal_signals __read_mostly;
72226
72227 -static void __user *sig_handler(struct task_struct *t, int sig)
72228 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
72229 {
72230 return t->sighand->action[sig - 1].sa.sa_handler;
72231 }
72232
72233 -static int sig_handler_ignored(void __user *handler, int sig)
72234 +static int sig_handler_ignored(__sighandler_t handler, int sig)
72235 {
72236 /* Is it explicitly or implicitly ignored? */
72237 return handler == SIG_IGN ||
72238 @@ -63,7 +63,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
72239
72240 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
72241 {
72242 - void __user *handler;
72243 + __sighandler_t handler;
72244
72245 handler = sig_handler(t, sig);
72246
72247 @@ -367,6 +367,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
72248 atomic_inc(&user->sigpending);
72249 rcu_read_unlock();
72250
72251 + if (!override_rlimit)
72252 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
72253 +
72254 if (override_rlimit ||
72255 atomic_read(&user->sigpending) <=
72256 task_rlimit(t, RLIMIT_SIGPENDING)) {
72257 @@ -491,7 +494,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
72258
72259 int unhandled_signal(struct task_struct *tsk, int sig)
72260 {
72261 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
72262 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
72263 if (is_global_init(tsk))
72264 return 1;
72265 if (handler != SIG_IGN && handler != SIG_DFL)
72266 @@ -811,6 +814,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
72267 }
72268 }
72269
72270 + /* allow glibc communication via tgkill to other threads in our
72271 + thread group */
72272 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
72273 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
72274 + && gr_handle_signal(t, sig))
72275 + return -EPERM;
72276 +
72277 return security_task_kill(t, info, sig, 0);
72278 }
72279
72280 @@ -1192,7 +1202,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
72281 return send_signal(sig, info, p, 1);
72282 }
72283
72284 -static int
72285 +int
72286 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
72287 {
72288 return send_signal(sig, info, t, 0);
72289 @@ -1229,6 +1239,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
72290 unsigned long int flags;
72291 int ret, blocked, ignored;
72292 struct k_sigaction *action;
72293 + int is_unhandled = 0;
72294
72295 spin_lock_irqsave(&t->sighand->siglock, flags);
72296 action = &t->sighand->action[sig-1];
72297 @@ -1243,9 +1254,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
72298 }
72299 if (action->sa.sa_handler == SIG_DFL)
72300 t->signal->flags &= ~SIGNAL_UNKILLABLE;
72301 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
72302 + is_unhandled = 1;
72303 ret = specific_send_sig_info(sig, info, t);
72304 spin_unlock_irqrestore(&t->sighand->siglock, flags);
72305
72306 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
72307 + normal operation */
72308 + if (is_unhandled) {
72309 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
72310 + gr_handle_crash(t, sig);
72311 + }
72312 +
72313 return ret;
72314 }
72315
72316 @@ -1312,8 +1332,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
72317 ret = check_kill_permission(sig, info, p);
72318 rcu_read_unlock();
72319
72320 - if (!ret && sig)
72321 + if (!ret && sig) {
72322 ret = do_send_sig_info(sig, info, p, true);
72323 + if (!ret)
72324 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
72325 + }
72326
72327 return ret;
72328 }
72329 @@ -2863,7 +2886,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
72330 int error = -ESRCH;
72331
72332 rcu_read_lock();
72333 - p = find_task_by_vpid(pid);
72334 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
72335 + /* allow glibc communication via tgkill to other threads in our
72336 + thread group */
72337 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
72338 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
72339 + p = find_task_by_vpid_unrestricted(pid);
72340 + else
72341 +#endif
72342 + p = find_task_by_vpid(pid);
72343 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
72344 error = check_kill_permission(sig, info, p);
72345 /*
72346 diff --git a/kernel/softirq.c b/kernel/softirq.c
72347 index cc96bdc..8bb9750 100644
72348 --- a/kernel/softirq.c
72349 +++ b/kernel/softirq.c
72350 @@ -57,7 +57,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
72351
72352 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
72353
72354 -char *softirq_to_name[NR_SOFTIRQS] = {
72355 +const char * const softirq_to_name[NR_SOFTIRQS] = {
72356 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
72357 "TASKLET", "SCHED", "HRTIMER", "RCU"
72358 };
72359 @@ -244,7 +244,7 @@ restart:
72360 kstat_incr_softirqs_this_cpu(vec_nr);
72361
72362 trace_softirq_entry(vec_nr);
72363 - h->action(h);
72364 + h->action();
72365 trace_softirq_exit(vec_nr);
72366 if (unlikely(prev_count != preempt_count())) {
72367 printk(KERN_ERR "huh, entered softirq %u %s %p"
72368 @@ -391,9 +391,11 @@ void __raise_softirq_irqoff(unsigned int nr)
72369 or_softirq_pending(1UL << nr);
72370 }
72371
72372 -void open_softirq(int nr, void (*action)(struct softirq_action *))
72373 +void open_softirq(int nr, void (*action)(void))
72374 {
72375 - softirq_vec[nr].action = action;
72376 + pax_open_kernel();
72377 + *(void **)&softirq_vec[nr].action = action;
72378 + pax_close_kernel();
72379 }
72380
72381 /*
72382 @@ -447,7 +449,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
72383
72384 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
72385
72386 -static void tasklet_action(struct softirq_action *a)
72387 +static void tasklet_action(void)
72388 {
72389 struct tasklet_struct *list;
72390
72391 @@ -482,7 +484,7 @@ static void tasklet_action(struct softirq_action *a)
72392 }
72393 }
72394
72395 -static void tasklet_hi_action(struct softirq_action *a)
72396 +static void tasklet_hi_action(void)
72397 {
72398 struct tasklet_struct *list;
72399
72400 diff --git a/kernel/srcu.c b/kernel/srcu.c
72401 index 97c465e..d83f3bb 100644
72402 --- a/kernel/srcu.c
72403 +++ b/kernel/srcu.c
72404 @@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
72405 preempt_disable();
72406 idx = rcu_dereference_index_check(sp->completed,
72407 rcu_read_lock_sched_held()) & 0x1;
72408 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
72409 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
72410 smp_mb(); /* B */ /* Avoid leaking the critical section. */
72411 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
72412 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
72413 preempt_enable();
72414 return idx;
72415 }
72416 @@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
72417 {
72418 preempt_disable();
72419 smp_mb(); /* C */ /* Avoid leaking the critical section. */
72420 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
72421 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
72422 preempt_enable();
72423 }
72424 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
72425 diff --git a/kernel/sys.c b/kernel/sys.c
72426 index e6e0ece..1f2e413 100644
72427 --- a/kernel/sys.c
72428 +++ b/kernel/sys.c
72429 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
72430 error = -EACCES;
72431 goto out;
72432 }
72433 +
72434 + if (gr_handle_chroot_setpriority(p, niceval)) {
72435 + error = -EACCES;
72436 + goto out;
72437 + }
72438 +
72439 no_nice = security_task_setnice(p, niceval);
72440 if (no_nice) {
72441 error = no_nice;
72442 @@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
72443 goto error;
72444 }
72445
72446 + if (gr_check_group_change(new->gid, new->egid, -1))
72447 + goto error;
72448 +
72449 if (rgid != (gid_t) -1 ||
72450 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
72451 new->sgid = new->egid;
72452 @@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
72453 old = current_cred();
72454
72455 retval = -EPERM;
72456 +
72457 + if (gr_check_group_change(kgid, kgid, kgid))
72458 + goto error;
72459 +
72460 if (nsown_capable(CAP_SETGID))
72461 new->gid = new->egid = new->sgid = new->fsgid = kgid;
72462 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
72463 @@ -647,7 +660,7 @@ error:
72464 /*
72465 * change the user struct in a credentials set to match the new UID
72466 */
72467 -static int set_user(struct cred *new)
72468 +int set_user(struct cred *new)
72469 {
72470 struct user_struct *new_user;
72471
72472 @@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
72473 goto error;
72474 }
72475
72476 + if (gr_check_user_change(new->uid, new->euid, -1))
72477 + goto error;
72478 +
72479 if (!uid_eq(new->uid, old->uid)) {
72480 retval = set_user(new);
72481 if (retval < 0)
72482 @@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
72483 old = current_cred();
72484
72485 retval = -EPERM;
72486 +
72487 + if (gr_check_crash_uid(kuid))
72488 + goto error;
72489 + if (gr_check_user_change(kuid, kuid, kuid))
72490 + goto error;
72491 +
72492 if (nsown_capable(CAP_SETUID)) {
72493 new->suid = new->uid = kuid;
72494 if (!uid_eq(kuid, old->uid)) {
72495 @@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
72496 goto error;
72497 }
72498
72499 + if (gr_check_user_change(kruid, keuid, -1))
72500 + goto error;
72501 +
72502 if (ruid != (uid_t) -1) {
72503 new->uid = kruid;
72504 if (!uid_eq(kruid, old->uid)) {
72505 @@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
72506 goto error;
72507 }
72508
72509 + if (gr_check_group_change(krgid, kegid, -1))
72510 + goto error;
72511 +
72512 if (rgid != (gid_t) -1)
72513 new->gid = krgid;
72514 if (egid != (gid_t) -1)
72515 @@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
72516 if (!uid_valid(kuid))
72517 return old_fsuid;
72518
72519 + if (gr_check_user_change(-1, -1, kuid))
72520 + goto error;
72521 +
72522 new = prepare_creds();
72523 if (!new)
72524 return old_fsuid;
72525 @@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
72526 }
72527 }
72528
72529 +error:
72530 abort_creds(new);
72531 return old_fsuid;
72532
72533 @@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
72534 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
72535 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
72536 nsown_capable(CAP_SETGID)) {
72537 + if (gr_check_group_change(-1, -1, kgid))
72538 + goto error;
72539 +
72540 if (!gid_eq(kgid, old->fsgid)) {
72541 new->fsgid = kgid;
72542 goto change_okay;
72543 }
72544 }
72545
72546 +error:
72547 abort_creds(new);
72548 return old_fsgid;
72549
72550 @@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
72551 return -EFAULT;
72552
72553 down_read(&uts_sem);
72554 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
72555 + error = __copy_to_user(name->sysname, &utsname()->sysname,
72556 __OLD_UTS_LEN);
72557 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
72558 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
72559 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
72560 __OLD_UTS_LEN);
72561 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
72562 - error |= __copy_to_user(&name->release, &utsname()->release,
72563 + error |= __copy_to_user(name->release, &utsname()->release,
72564 __OLD_UTS_LEN);
72565 error |= __put_user(0, name->release + __OLD_UTS_LEN);
72566 - error |= __copy_to_user(&name->version, &utsname()->version,
72567 + error |= __copy_to_user(name->version, &utsname()->version,
72568 __OLD_UTS_LEN);
72569 error |= __put_user(0, name->version + __OLD_UTS_LEN);
72570 - error |= __copy_to_user(&name->machine, &utsname()->machine,
72571 + error |= __copy_to_user(name->machine, &utsname()->machine,
72572 __OLD_UTS_LEN);
72573 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
72574 up_read(&uts_sem);
72575 @@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
72576 error = get_dumpable(me->mm);
72577 break;
72578 case PR_SET_DUMPABLE:
72579 - if (arg2 < 0 || arg2 > 1) {
72580 + if (arg2 > 1) {
72581 error = -EINVAL;
72582 break;
72583 }
72584 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
72585 index 26f65ea..df8e5ad 100644
72586 --- a/kernel/sysctl.c
72587 +++ b/kernel/sysctl.c
72588 @@ -92,7 +92,6 @@
72589
72590
72591 #if defined(CONFIG_SYSCTL)
72592 -
72593 /* External variables not in a header file. */
72594 extern int sysctl_overcommit_memory;
72595 extern int sysctl_overcommit_ratio;
72596 @@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
72597 void __user *buffer, size_t *lenp, loff_t *ppos);
72598 #endif
72599
72600 -#ifdef CONFIG_PRINTK
72601 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
72602 void __user *buffer, size_t *lenp, loff_t *ppos);
72603 -#endif
72604
72605 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
72606 void __user *buffer, size_t *lenp, loff_t *ppos);
72607 @@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
72608
72609 #endif
72610
72611 +extern struct ctl_table grsecurity_table[];
72612 +
72613 static struct ctl_table kern_table[];
72614 static struct ctl_table vm_table[];
72615 static struct ctl_table fs_table[];
72616 @@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
72617 int sysctl_legacy_va_layout;
72618 #endif
72619
72620 +#ifdef CONFIG_PAX_SOFTMODE
72621 +static ctl_table pax_table[] = {
72622 + {
72623 + .procname = "softmode",
72624 + .data = &pax_softmode,
72625 + .maxlen = sizeof(unsigned int),
72626 + .mode = 0600,
72627 + .proc_handler = &proc_dointvec,
72628 + },
72629 +
72630 + { }
72631 +};
72632 +#endif
72633 +
72634 /* The default sysctl tables: */
72635
72636 static struct ctl_table sysctl_base_table[] = {
72637 @@ -266,6 +279,22 @@ static int max_extfrag_threshold = 1000;
72638 #endif
72639
72640 static struct ctl_table kern_table[] = {
72641 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
72642 + {
72643 + .procname = "grsecurity",
72644 + .mode = 0500,
72645 + .child = grsecurity_table,
72646 + },
72647 +#endif
72648 +
72649 +#ifdef CONFIG_PAX_SOFTMODE
72650 + {
72651 + .procname = "pax",
72652 + .mode = 0500,
72653 + .child = pax_table,
72654 + },
72655 +#endif
72656 +
72657 {
72658 .procname = "sched_child_runs_first",
72659 .data = &sysctl_sched_child_runs_first,
72660 @@ -552,7 +581,7 @@ static struct ctl_table kern_table[] = {
72661 .data = &modprobe_path,
72662 .maxlen = KMOD_PATH_LEN,
72663 .mode = 0644,
72664 - .proc_handler = proc_dostring,
72665 + .proc_handler = proc_dostring_modpriv,
72666 },
72667 {
72668 .procname = "modules_disabled",
72669 @@ -719,16 +748,20 @@ static struct ctl_table kern_table[] = {
72670 .extra1 = &zero,
72671 .extra2 = &one,
72672 },
72673 +#endif
72674 {
72675 .procname = "kptr_restrict",
72676 .data = &kptr_restrict,
72677 .maxlen = sizeof(int),
72678 .mode = 0644,
72679 .proc_handler = proc_dointvec_minmax_sysadmin,
72680 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72681 + .extra1 = &two,
72682 +#else
72683 .extra1 = &zero,
72684 +#endif
72685 .extra2 = &two,
72686 },
72687 -#endif
72688 {
72689 .procname = "ngroups_max",
72690 .data = &ngroups_max,
72691 @@ -1225,6 +1258,13 @@ static struct ctl_table vm_table[] = {
72692 .proc_handler = proc_dointvec_minmax,
72693 .extra1 = &zero,
72694 },
72695 + {
72696 + .procname = "heap_stack_gap",
72697 + .data = &sysctl_heap_stack_gap,
72698 + .maxlen = sizeof(sysctl_heap_stack_gap),
72699 + .mode = 0644,
72700 + .proc_handler = proc_doulongvec_minmax,
72701 + },
72702 #else
72703 {
72704 .procname = "nr_trim_pages",
72705 @@ -1675,6 +1715,16 @@ int proc_dostring(struct ctl_table *table, int write,
72706 buffer, lenp, ppos);
72707 }
72708
72709 +int proc_dostring_modpriv(struct ctl_table *table, int write,
72710 + void __user *buffer, size_t *lenp, loff_t *ppos)
72711 +{
72712 + if (write && !capable(CAP_SYS_MODULE))
72713 + return -EPERM;
72714 +
72715 + return _proc_do_string(table->data, table->maxlen, write,
72716 + buffer, lenp, ppos);
72717 +}
72718 +
72719 static size_t proc_skip_spaces(char **buf)
72720 {
72721 size_t ret;
72722 @@ -1780,6 +1830,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
72723 len = strlen(tmp);
72724 if (len > *size)
72725 len = *size;
72726 + if (len > sizeof(tmp))
72727 + len = sizeof(tmp);
72728 if (copy_to_user(*buf, tmp, len))
72729 return -EFAULT;
72730 *size -= len;
72731 @@ -1972,7 +2024,6 @@ static int proc_taint(struct ctl_table *table, int write,
72732 return err;
72733 }
72734
72735 -#ifdef CONFIG_PRINTK
72736 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
72737 void __user *buffer, size_t *lenp, loff_t *ppos)
72738 {
72739 @@ -1981,7 +2032,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
72740
72741 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
72742 }
72743 -#endif
72744
72745 struct do_proc_dointvec_minmax_conv_param {
72746 int *min;
72747 @@ -2128,8 +2178,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
72748 *i = val;
72749 } else {
72750 val = convdiv * (*i) / convmul;
72751 - if (!first)
72752 + if (!first) {
72753 err = proc_put_char(&buffer, &left, '\t');
72754 + if (err)
72755 + break;
72756 + }
72757 err = proc_put_long(&buffer, &left, val, false);
72758 if (err)
72759 break;
72760 @@ -2521,6 +2574,12 @@ int proc_dostring(struct ctl_table *table, int write,
72761 return -ENOSYS;
72762 }
72763
72764 +int proc_dostring_modpriv(struct ctl_table *table, int write,
72765 + void __user *buffer, size_t *lenp, loff_t *ppos)
72766 +{
72767 + return -ENOSYS;
72768 +}
72769 +
72770 int proc_dointvec(struct ctl_table *table, int write,
72771 void __user *buffer, size_t *lenp, loff_t *ppos)
72772 {
72773 @@ -2577,5 +2636,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
72774 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
72775 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
72776 EXPORT_SYMBOL(proc_dostring);
72777 +EXPORT_SYMBOL(proc_dostring_modpriv);
72778 EXPORT_SYMBOL(proc_doulongvec_minmax);
72779 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
72780 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
72781 index 65bdcf1..21eb831 100644
72782 --- a/kernel/sysctl_binary.c
72783 +++ b/kernel/sysctl_binary.c
72784 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
72785 int i;
72786
72787 set_fs(KERNEL_DS);
72788 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
72789 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
72790 set_fs(old_fs);
72791 if (result < 0)
72792 goto out_kfree;
72793 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
72794 }
72795
72796 set_fs(KERNEL_DS);
72797 - result = vfs_write(file, buffer, str - buffer, &pos);
72798 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
72799 set_fs(old_fs);
72800 if (result < 0)
72801 goto out_kfree;
72802 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
72803 int i;
72804
72805 set_fs(KERNEL_DS);
72806 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
72807 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
72808 set_fs(old_fs);
72809 if (result < 0)
72810 goto out_kfree;
72811 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
72812 }
72813
72814 set_fs(KERNEL_DS);
72815 - result = vfs_write(file, buffer, str - buffer, &pos);
72816 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
72817 set_fs(old_fs);
72818 if (result < 0)
72819 goto out_kfree;
72820 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
72821 int i;
72822
72823 set_fs(KERNEL_DS);
72824 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
72825 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
72826 set_fs(old_fs);
72827 if (result < 0)
72828 goto out;
72829 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
72830 __le16 dnaddr;
72831
72832 set_fs(KERNEL_DS);
72833 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
72834 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
72835 set_fs(old_fs);
72836 if (result < 0)
72837 goto out;
72838 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
72839 le16_to_cpu(dnaddr) & 0x3ff);
72840
72841 set_fs(KERNEL_DS);
72842 - result = vfs_write(file, buf, len, &pos);
72843 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
72844 set_fs(old_fs);
72845 if (result < 0)
72846 goto out;
72847 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
72848 index 145bb4d..b2aa969 100644
72849 --- a/kernel/taskstats.c
72850 +++ b/kernel/taskstats.c
72851 @@ -28,9 +28,12 @@
72852 #include <linux/fs.h>
72853 #include <linux/file.h>
72854 #include <linux/pid_namespace.h>
72855 +#include <linux/grsecurity.h>
72856 #include <net/genetlink.h>
72857 #include <linux/atomic.h>
72858
72859 +extern int gr_is_taskstats_denied(int pid);
72860 +
72861 /*
72862 * Maximum length of a cpumask that can be specified in
72863 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
72864 @@ -570,6 +573,9 @@ err:
72865
72866 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
72867 {
72868 + if (gr_is_taskstats_denied(current->pid))
72869 + return -EACCES;
72870 +
72871 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
72872 return cmd_attr_register_cpumask(info);
72873 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
72874 diff --git a/kernel/time.c b/kernel/time.c
72875 index d226c6a..c7c0960 100644
72876 --- a/kernel/time.c
72877 +++ b/kernel/time.c
72878 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
72879 return error;
72880
72881 if (tz) {
72882 + /* we log in do_settimeofday called below, so don't log twice
72883 + */
72884 + if (!tv)
72885 + gr_log_timechange();
72886 +
72887 sys_tz = *tz;
72888 update_vsyscall_tz();
72889 if (firsttime) {
72890 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
72891 index f11d83b..d016d91 100644
72892 --- a/kernel/time/alarmtimer.c
72893 +++ b/kernel/time/alarmtimer.c
72894 @@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
72895 struct platform_device *pdev;
72896 int error = 0;
72897 int i;
72898 - struct k_clock alarm_clock = {
72899 + static struct k_clock alarm_clock = {
72900 .clock_getres = alarm_clock_getres,
72901 .clock_get = alarm_clock_get,
72902 .timer_create = alarm_timer_create,
72903 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
72904 index f113755..ec24223 100644
72905 --- a/kernel/time/tick-broadcast.c
72906 +++ b/kernel/time/tick-broadcast.c
72907 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
72908 * then clear the broadcast bit.
72909 */
72910 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
72911 - int cpu = smp_processor_id();
72912 + cpu = smp_processor_id();
72913
72914 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
72915 tick_broadcast_clear_oneshot(cpu);
72916 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
72917 index e424970..4c7962b 100644
72918 --- a/kernel/time/timekeeping.c
72919 +++ b/kernel/time/timekeeping.c
72920 @@ -15,6 +15,7 @@
72921 #include <linux/init.h>
72922 #include <linux/mm.h>
72923 #include <linux/sched.h>
72924 +#include <linux/grsecurity.h>
72925 #include <linux/syscore_ops.h>
72926 #include <linux/clocksource.h>
72927 #include <linux/jiffies.h>
72928 @@ -368,6 +369,8 @@ int do_settimeofday(const struct timespec *tv)
72929 if (!timespec_valid_strict(tv))
72930 return -EINVAL;
72931
72932 + gr_log_timechange();
72933 +
72934 write_seqlock_irqsave(&tk->lock, flags);
72935
72936 timekeeping_forward_now(tk);
72937 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
72938 index af5a7e9..715611a 100644
72939 --- a/kernel/time/timer_list.c
72940 +++ b/kernel/time/timer_list.c
72941 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
72942
72943 static void print_name_offset(struct seq_file *m, void *sym)
72944 {
72945 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72946 + SEQ_printf(m, "<%p>", NULL);
72947 +#else
72948 char symname[KSYM_NAME_LEN];
72949
72950 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
72951 SEQ_printf(m, "<%pK>", sym);
72952 else
72953 SEQ_printf(m, "%s", symname);
72954 +#endif
72955 }
72956
72957 static void
72958 @@ -112,7 +116,11 @@ next_one:
72959 static void
72960 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
72961 {
72962 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72963 + SEQ_printf(m, " .base: %p\n", NULL);
72964 +#else
72965 SEQ_printf(m, " .base: %pK\n", base);
72966 +#endif
72967 SEQ_printf(m, " .index: %d\n",
72968 base->index);
72969 SEQ_printf(m, " .resolution: %Lu nsecs\n",
72970 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
72971 {
72972 struct proc_dir_entry *pe;
72973
72974 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
72975 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
72976 +#else
72977 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
72978 +#endif
72979 if (!pe)
72980 return -ENOMEM;
72981 return 0;
72982 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
72983 index 0b537f2..40d6c20 100644
72984 --- a/kernel/time/timer_stats.c
72985 +++ b/kernel/time/timer_stats.c
72986 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
72987 static unsigned long nr_entries;
72988 static struct entry entries[MAX_ENTRIES];
72989
72990 -static atomic_t overflow_count;
72991 +static atomic_unchecked_t overflow_count;
72992
72993 /*
72994 * The entries are in a hash-table, for fast lookup:
72995 @@ -140,7 +140,7 @@ static void reset_entries(void)
72996 nr_entries = 0;
72997 memset(entries, 0, sizeof(entries));
72998 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
72999 - atomic_set(&overflow_count, 0);
73000 + atomic_set_unchecked(&overflow_count, 0);
73001 }
73002
73003 static struct entry *alloc_entry(void)
73004 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
73005 if (likely(entry))
73006 entry->count++;
73007 else
73008 - atomic_inc(&overflow_count);
73009 + atomic_inc_unchecked(&overflow_count);
73010
73011 out_unlock:
73012 raw_spin_unlock_irqrestore(lock, flags);
73013 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
73014
73015 static void print_name_offset(struct seq_file *m, unsigned long addr)
73016 {
73017 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73018 + seq_printf(m, "<%p>", NULL);
73019 +#else
73020 char symname[KSYM_NAME_LEN];
73021
73022 if (lookup_symbol_name(addr, symname) < 0)
73023 - seq_printf(m, "<%p>", (void *)addr);
73024 + seq_printf(m, "<%pK>", (void *)addr);
73025 else
73026 seq_printf(m, "%s", symname);
73027 +#endif
73028 }
73029
73030 static int tstats_show(struct seq_file *m, void *v)
73031 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
73032
73033 seq_puts(m, "Timer Stats Version: v0.2\n");
73034 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
73035 - if (atomic_read(&overflow_count))
73036 + if (atomic_read_unchecked(&overflow_count))
73037 seq_printf(m, "Overflow: %d entries\n",
73038 - atomic_read(&overflow_count));
73039 + atomic_read_unchecked(&overflow_count));
73040
73041 for (i = 0; i < nr_entries; i++) {
73042 entry = entries + i;
73043 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
73044 {
73045 struct proc_dir_entry *pe;
73046
73047 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
73048 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
73049 +#else
73050 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
73051 +#endif
73052 if (!pe)
73053 return -ENOMEM;
73054 return 0;
73055 diff --git a/kernel/timer.c b/kernel/timer.c
73056 index 367d008..46857a0 100644
73057 --- a/kernel/timer.c
73058 +++ b/kernel/timer.c
73059 @@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
73060 /*
73061 * This function runs timers and the timer-tq in bottom half context.
73062 */
73063 -static void run_timer_softirq(struct softirq_action *h)
73064 +static void run_timer_softirq(void)
73065 {
73066 struct tvec_base *base = __this_cpu_read(tvec_bases);
73067
73068 @@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
73069 return NOTIFY_OK;
73070 }
73071
73072 -static struct notifier_block __cpuinitdata timers_nb = {
73073 +static struct notifier_block __cpuinitconst timers_nb = {
73074 .notifier_call = timer_cpu_notify,
73075 };
73076
73077 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
73078 index c0bd030..62a1927 100644
73079 --- a/kernel/trace/blktrace.c
73080 +++ b/kernel/trace/blktrace.c
73081 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
73082 struct blk_trace *bt = filp->private_data;
73083 char buf[16];
73084
73085 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
73086 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
73087
73088 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
73089 }
73090 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
73091 return 1;
73092
73093 bt = buf->chan->private_data;
73094 - atomic_inc(&bt->dropped);
73095 + atomic_inc_unchecked(&bt->dropped);
73096 return 0;
73097 }
73098
73099 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
73100
73101 bt->dir = dir;
73102 bt->dev = dev;
73103 - atomic_set(&bt->dropped, 0);
73104 + atomic_set_unchecked(&bt->dropped, 0);
73105
73106 ret = -EIO;
73107 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
73108 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
73109 index 356bc2f..7c94fc0 100644
73110 --- a/kernel/trace/ftrace.c
73111 +++ b/kernel/trace/ftrace.c
73112 @@ -1874,12 +1874,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
73113 if (unlikely(ftrace_disabled))
73114 return 0;
73115
73116 + ret = ftrace_arch_code_modify_prepare();
73117 + FTRACE_WARN_ON(ret);
73118 + if (ret)
73119 + return 0;
73120 +
73121 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
73122 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
73123 if (ret) {
73124 ftrace_bug(ret, ip);
73125 - return 0;
73126 }
73127 - return 1;
73128 + return ret ? 0 : 1;
73129 }
73130
73131 /*
73132 @@ -2965,7 +2970,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
73133
73134 int
73135 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
73136 - void *data)
73137 + void *data)
73138 {
73139 struct ftrace_func_probe *entry;
73140 struct ftrace_page *pg;
73141 @@ -3832,8 +3837,10 @@ static int ftrace_process_locs(struct module *mod,
73142 if (!count)
73143 return 0;
73144
73145 + pax_open_kernel();
73146 sort(start, count, sizeof(*start),
73147 ftrace_cmp_ips, ftrace_swap_ips);
73148 + pax_close_kernel();
73149
73150 start_pg = ftrace_allocate_pages(count);
73151 if (!start_pg)
73152 @@ -4541,8 +4548,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
73153 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
73154
73155 static int ftrace_graph_active;
73156 -static struct notifier_block ftrace_suspend_notifier;
73157 -
73158 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
73159 {
73160 return 0;
73161 @@ -4686,6 +4691,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
73162 return NOTIFY_DONE;
73163 }
73164
73165 +static struct notifier_block ftrace_suspend_notifier = {
73166 + .notifier_call = ftrace_suspend_notifier_call
73167 +};
73168 +
73169 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
73170 trace_func_graph_ent_t entryfunc)
73171 {
73172 @@ -4699,7 +4708,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
73173 goto out;
73174 }
73175
73176 - ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
73177 register_pm_notifier(&ftrace_suspend_notifier);
73178
73179 ftrace_graph_active++;
73180 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
73181 index 4cb5e51..e7e05d9 100644
73182 --- a/kernel/trace/ring_buffer.c
73183 +++ b/kernel/trace/ring_buffer.c
73184 @@ -346,9 +346,9 @@ struct buffer_data_page {
73185 */
73186 struct buffer_page {
73187 struct list_head list; /* list of buffer pages */
73188 - local_t write; /* index for next write */
73189 + local_unchecked_t write; /* index for next write */
73190 unsigned read; /* index for next read */
73191 - local_t entries; /* entries on this page */
73192 + local_unchecked_t entries; /* entries on this page */
73193 unsigned long real_end; /* real end of data */
73194 struct buffer_data_page *page; /* Actual data page */
73195 };
73196 @@ -460,8 +460,8 @@ struct ring_buffer_per_cpu {
73197 unsigned long lost_events;
73198 unsigned long last_overrun;
73199 local_t entries_bytes;
73200 - local_t commit_overrun;
73201 - local_t overrun;
73202 + local_unchecked_t commit_overrun;
73203 + local_unchecked_t overrun;
73204 local_t entries;
73205 local_t committing;
73206 local_t commits;
73207 @@ -860,8 +860,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
73208 *
73209 * We add a counter to the write field to denote this.
73210 */
73211 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
73212 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
73213 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
73214 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
73215
73216 /*
73217 * Just make sure we have seen our old_write and synchronize
73218 @@ -889,8 +889,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
73219 * cmpxchg to only update if an interrupt did not already
73220 * do it for us. If the cmpxchg fails, we don't care.
73221 */
73222 - (void)local_cmpxchg(&next_page->write, old_write, val);
73223 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
73224 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
73225 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
73226
73227 /*
73228 * No need to worry about races with clearing out the commit.
73229 @@ -1249,12 +1249,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
73230
73231 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
73232 {
73233 - return local_read(&bpage->entries) & RB_WRITE_MASK;
73234 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
73235 }
73236
73237 static inline unsigned long rb_page_write(struct buffer_page *bpage)
73238 {
73239 - return local_read(&bpage->write) & RB_WRITE_MASK;
73240 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
73241 }
73242
73243 static int
73244 @@ -1349,7 +1349,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
73245 * bytes consumed in ring buffer from here.
73246 * Increment overrun to account for the lost events.
73247 */
73248 - local_add(page_entries, &cpu_buffer->overrun);
73249 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
73250 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
73251 }
73252
73253 @@ -1905,7 +1905,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
73254 * it is our responsibility to update
73255 * the counters.
73256 */
73257 - local_add(entries, &cpu_buffer->overrun);
73258 + local_add_unchecked(entries, &cpu_buffer->overrun);
73259 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
73260
73261 /*
73262 @@ -2055,7 +2055,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
73263 if (tail == BUF_PAGE_SIZE)
73264 tail_page->real_end = 0;
73265
73266 - local_sub(length, &tail_page->write);
73267 + local_sub_unchecked(length, &tail_page->write);
73268 return;
73269 }
73270
73271 @@ -2090,7 +2090,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
73272 rb_event_set_padding(event);
73273
73274 /* Set the write back to the previous setting */
73275 - local_sub(length, &tail_page->write);
73276 + local_sub_unchecked(length, &tail_page->write);
73277 return;
73278 }
73279
73280 @@ -2102,7 +2102,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
73281
73282 /* Set write to end of buffer */
73283 length = (tail + length) - BUF_PAGE_SIZE;
73284 - local_sub(length, &tail_page->write);
73285 + local_sub_unchecked(length, &tail_page->write);
73286 }
73287
73288 /*
73289 @@ -2128,7 +2128,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
73290 * about it.
73291 */
73292 if (unlikely(next_page == commit_page)) {
73293 - local_inc(&cpu_buffer->commit_overrun);
73294 + local_inc_unchecked(&cpu_buffer->commit_overrun);
73295 goto out_reset;
73296 }
73297
73298 @@ -2182,7 +2182,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
73299 cpu_buffer->tail_page) &&
73300 (cpu_buffer->commit_page ==
73301 cpu_buffer->reader_page))) {
73302 - local_inc(&cpu_buffer->commit_overrun);
73303 + local_inc_unchecked(&cpu_buffer->commit_overrun);
73304 goto out_reset;
73305 }
73306 }
73307 @@ -2230,7 +2230,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
73308 length += RB_LEN_TIME_EXTEND;
73309
73310 tail_page = cpu_buffer->tail_page;
73311 - write = local_add_return(length, &tail_page->write);
73312 + write = local_add_return_unchecked(length, &tail_page->write);
73313
73314 /* set write to only the index of the write */
73315 write &= RB_WRITE_MASK;
73316 @@ -2247,7 +2247,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
73317 kmemcheck_annotate_bitfield(event, bitfield);
73318 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
73319
73320 - local_inc(&tail_page->entries);
73321 + local_inc_unchecked(&tail_page->entries);
73322
73323 /*
73324 * If this is the first commit on the page, then update
73325 @@ -2280,7 +2280,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
73326
73327 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
73328 unsigned long write_mask =
73329 - local_read(&bpage->write) & ~RB_WRITE_MASK;
73330 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
73331 unsigned long event_length = rb_event_length(event);
73332 /*
73333 * This is on the tail page. It is possible that
73334 @@ -2290,7 +2290,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
73335 */
73336 old_index += write_mask;
73337 new_index += write_mask;
73338 - index = local_cmpxchg(&bpage->write, old_index, new_index);
73339 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
73340 if (index == old_index) {
73341 /* update counters */
73342 local_sub(event_length, &cpu_buffer->entries_bytes);
73343 @@ -2629,7 +2629,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
73344
73345 /* Do the likely case first */
73346 if (likely(bpage->page == (void *)addr)) {
73347 - local_dec(&bpage->entries);
73348 + local_dec_unchecked(&bpage->entries);
73349 return;
73350 }
73351
73352 @@ -2641,7 +2641,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
73353 start = bpage;
73354 do {
73355 if (bpage->page == (void *)addr) {
73356 - local_dec(&bpage->entries);
73357 + local_dec_unchecked(&bpage->entries);
73358 return;
73359 }
73360 rb_inc_page(cpu_buffer, &bpage);
73361 @@ -2923,7 +2923,7 @@ static inline unsigned long
73362 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
73363 {
73364 return local_read(&cpu_buffer->entries) -
73365 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
73366 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
73367 }
73368
73369 /**
73370 @@ -3011,7 +3011,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
73371 return 0;
73372
73373 cpu_buffer = buffer->buffers[cpu];
73374 - ret = local_read(&cpu_buffer->overrun);
73375 + ret = local_read_unchecked(&cpu_buffer->overrun);
73376
73377 return ret;
73378 }
73379 @@ -3032,7 +3032,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
73380 return 0;
73381
73382 cpu_buffer = buffer->buffers[cpu];
73383 - ret = local_read(&cpu_buffer->commit_overrun);
73384 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
73385
73386 return ret;
73387 }
73388 @@ -3077,7 +3077,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
73389 /* if you care about this being correct, lock the buffer */
73390 for_each_buffer_cpu(buffer, cpu) {
73391 cpu_buffer = buffer->buffers[cpu];
73392 - overruns += local_read(&cpu_buffer->overrun);
73393 + overruns += local_read_unchecked(&cpu_buffer->overrun);
73394 }
73395
73396 return overruns;
73397 @@ -3253,8 +3253,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
73398 /*
73399 * Reset the reader page to size zero.
73400 */
73401 - local_set(&cpu_buffer->reader_page->write, 0);
73402 - local_set(&cpu_buffer->reader_page->entries, 0);
73403 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
73404 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
73405 local_set(&cpu_buffer->reader_page->page->commit, 0);
73406 cpu_buffer->reader_page->real_end = 0;
73407
73408 @@ -3288,7 +3288,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
73409 * want to compare with the last_overrun.
73410 */
73411 smp_mb();
73412 - overwrite = local_read(&(cpu_buffer->overrun));
73413 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
73414
73415 /*
73416 * Here's the tricky part.
73417 @@ -3858,8 +3858,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
73418
73419 cpu_buffer->head_page
73420 = list_entry(cpu_buffer->pages, struct buffer_page, list);
73421 - local_set(&cpu_buffer->head_page->write, 0);
73422 - local_set(&cpu_buffer->head_page->entries, 0);
73423 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
73424 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
73425 local_set(&cpu_buffer->head_page->page->commit, 0);
73426
73427 cpu_buffer->head_page->read = 0;
73428 @@ -3869,14 +3869,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
73429
73430 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
73431 INIT_LIST_HEAD(&cpu_buffer->new_pages);
73432 - local_set(&cpu_buffer->reader_page->write, 0);
73433 - local_set(&cpu_buffer->reader_page->entries, 0);
73434 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
73435 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
73436 local_set(&cpu_buffer->reader_page->page->commit, 0);
73437 cpu_buffer->reader_page->read = 0;
73438
73439 - local_set(&cpu_buffer->commit_overrun, 0);
73440 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
73441 local_set(&cpu_buffer->entries_bytes, 0);
73442 - local_set(&cpu_buffer->overrun, 0);
73443 + local_set_unchecked(&cpu_buffer->overrun, 0);
73444 local_set(&cpu_buffer->entries, 0);
73445 local_set(&cpu_buffer->committing, 0);
73446 local_set(&cpu_buffer->commits, 0);
73447 @@ -4279,8 +4279,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
73448 rb_init_page(bpage);
73449 bpage = reader->page;
73450 reader->page = *data_page;
73451 - local_set(&reader->write, 0);
73452 - local_set(&reader->entries, 0);
73453 + local_set_unchecked(&reader->write, 0);
73454 + local_set_unchecked(&reader->entries, 0);
73455 reader->read = 0;
73456 *data_page = bpage;
73457
73458 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
73459 index 31e4f55..62da00f 100644
73460 --- a/kernel/trace/trace.c
73461 +++ b/kernel/trace/trace.c
73462 @@ -4436,10 +4436,9 @@ static const struct file_operations tracing_dyn_info_fops = {
73463 };
73464 #endif
73465
73466 -static struct dentry *d_tracer;
73467 -
73468 struct dentry *tracing_init_dentry(void)
73469 {
73470 + static struct dentry *d_tracer;
73471 static int once;
73472
73473 if (d_tracer)
73474 @@ -4459,10 +4458,9 @@ struct dentry *tracing_init_dentry(void)
73475 return d_tracer;
73476 }
73477
73478 -static struct dentry *d_percpu;
73479 -
73480 struct dentry *tracing_dentry_percpu(void)
73481 {
73482 + static struct dentry *d_percpu;
73483 static int once;
73484 struct dentry *d_tracer;
73485
73486 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
73487 index d608d09..7eddcb1 100644
73488 --- a/kernel/trace/trace_events.c
73489 +++ b/kernel/trace/trace_events.c
73490 @@ -1320,10 +1320,6 @@ static LIST_HEAD(ftrace_module_file_list);
73491 struct ftrace_module_file_ops {
73492 struct list_head list;
73493 struct module *mod;
73494 - struct file_operations id;
73495 - struct file_operations enable;
73496 - struct file_operations format;
73497 - struct file_operations filter;
73498 };
73499
73500 static struct ftrace_module_file_ops *
73501 @@ -1344,17 +1340,12 @@ trace_create_file_ops(struct module *mod)
73502
73503 file_ops->mod = mod;
73504
73505 - file_ops->id = ftrace_event_id_fops;
73506 - file_ops->id.owner = mod;
73507 -
73508 - file_ops->enable = ftrace_enable_fops;
73509 - file_ops->enable.owner = mod;
73510 -
73511 - file_ops->filter = ftrace_event_filter_fops;
73512 - file_ops->filter.owner = mod;
73513 -
73514 - file_ops->format = ftrace_event_format_fops;
73515 - file_ops->format.owner = mod;
73516 + pax_open_kernel();
73517 + *(void **)&mod->trace_id.owner = mod;
73518 + *(void **)&mod->trace_enable.owner = mod;
73519 + *(void **)&mod->trace_filter.owner = mod;
73520 + *(void **)&mod->trace_format.owner = mod;
73521 + pax_close_kernel();
73522
73523 list_add(&file_ops->list, &ftrace_module_file_list);
73524
73525 @@ -1378,8 +1369,8 @@ static void trace_module_add_events(struct module *mod)
73526
73527 for_each_event(call, start, end) {
73528 __trace_add_event_call(*call, mod,
73529 - &file_ops->id, &file_ops->enable,
73530 - &file_ops->filter, &file_ops->format);
73531 + &mod->trace_id, &mod->trace_enable,
73532 + &mod->trace_filter, &mod->trace_format);
73533 }
73534 }
73535
73536 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
73537 index fd3c8aa..5f324a6 100644
73538 --- a/kernel/trace/trace_mmiotrace.c
73539 +++ b/kernel/trace/trace_mmiotrace.c
73540 @@ -24,7 +24,7 @@ struct header_iter {
73541 static struct trace_array *mmio_trace_array;
73542 static bool overrun_detected;
73543 static unsigned long prev_overruns;
73544 -static atomic_t dropped_count;
73545 +static atomic_unchecked_t dropped_count;
73546
73547 static void mmio_reset_data(struct trace_array *tr)
73548 {
73549 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
73550
73551 static unsigned long count_overruns(struct trace_iterator *iter)
73552 {
73553 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
73554 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
73555 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
73556
73557 if (over > prev_overruns)
73558 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
73559 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
73560 sizeof(*entry), 0, pc);
73561 if (!event) {
73562 - atomic_inc(&dropped_count);
73563 + atomic_inc_unchecked(&dropped_count);
73564 return;
73565 }
73566 entry = ring_buffer_event_data(event);
73567 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
73568 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
73569 sizeof(*entry), 0, pc);
73570 if (!event) {
73571 - atomic_inc(&dropped_count);
73572 + atomic_inc_unchecked(&dropped_count);
73573 return;
73574 }
73575 entry = ring_buffer_event_data(event);
73576 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
73577 index 123b189..1e9e2a6 100644
73578 --- a/kernel/trace/trace_output.c
73579 +++ b/kernel/trace/trace_output.c
73580 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
73581
73582 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
73583 if (!IS_ERR(p)) {
73584 - p = mangle_path(s->buffer + s->len, p, "\n");
73585 + p = mangle_path(s->buffer + s->len, p, "\n\\");
73586 if (p) {
73587 s->len = p - s->buffer;
73588 return 1;
73589 @@ -824,14 +824,16 @@ int register_ftrace_event(struct trace_event *event)
73590 goto out;
73591 }
73592
73593 + pax_open_kernel();
73594 if (event->funcs->trace == NULL)
73595 - event->funcs->trace = trace_nop_print;
73596 + *(void **)&event->funcs->trace = trace_nop_print;
73597 if (event->funcs->raw == NULL)
73598 - event->funcs->raw = trace_nop_print;
73599 + *(void **)&event->funcs->raw = trace_nop_print;
73600 if (event->funcs->hex == NULL)
73601 - event->funcs->hex = trace_nop_print;
73602 + *(void **)&event->funcs->hex = trace_nop_print;
73603 if (event->funcs->binary == NULL)
73604 - event->funcs->binary = trace_nop_print;
73605 + *(void **)&event->funcs->binary = trace_nop_print;
73606 + pax_close_kernel();
73607
73608 key = event->type & (EVENT_HASHSIZE - 1);
73609
73610 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
73611 index 0c1b1657..95337e9 100644
73612 --- a/kernel/trace/trace_stack.c
73613 +++ b/kernel/trace/trace_stack.c
73614 @@ -53,7 +53,7 @@ static inline void check_stack(void)
73615 return;
73616
73617 /* we do not handle interrupt stacks yet */
73618 - if (!object_is_on_stack(&this_size))
73619 + if (!object_starts_on_stack(&this_size))
73620 return;
73621
73622 local_irq_save(flags);
73623 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
73624 index 28e9d6c9..50381bd 100644
73625 --- a/lib/Kconfig.debug
73626 +++ b/lib/Kconfig.debug
73627 @@ -1278,6 +1278,7 @@ config LATENCYTOP
73628 depends on DEBUG_KERNEL
73629 depends on STACKTRACE_SUPPORT
73630 depends on PROC_FS
73631 + depends on !GRKERNSEC_HIDESYM
73632 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
73633 select KALLSYMS
73634 select KALLSYMS_ALL
73635 @@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
73636
73637 config PROVIDE_OHCI1394_DMA_INIT
73638 bool "Remote debugging over FireWire early on boot"
73639 - depends on PCI && X86
73640 + depends on PCI && X86 && !GRKERNSEC
73641 help
73642 If you want to debug problems which hang or crash the kernel early
73643 on boot and the crashing machine has a FireWire port, you can use
73644 @@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
73645
73646 config FIREWIRE_OHCI_REMOTE_DMA
73647 bool "Remote debugging over FireWire with firewire-ohci"
73648 - depends on FIREWIRE_OHCI
73649 + depends on FIREWIRE_OHCI && !GRKERNSEC
73650 help
73651 This option lets you use the FireWire bus for remote debugging
73652 with help of the firewire-ohci driver. It enables unfiltered
73653 diff --git a/lib/Makefile b/lib/Makefile
73654 index a08b791..a3ff1eb 100644
73655 --- a/lib/Makefile
73656 +++ b/lib/Makefile
73657 @@ -46,7 +46,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
73658
73659 obj-$(CONFIG_BTREE) += btree.o
73660 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
73661 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
73662 +obj-y += list_debug.o
73663 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
73664
73665 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
73666 diff --git a/lib/bitmap.c b/lib/bitmap.c
73667 index 06fdfa1..97c5c7d 100644
73668 --- a/lib/bitmap.c
73669 +++ b/lib/bitmap.c
73670 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
73671 {
73672 int c, old_c, totaldigits, ndigits, nchunks, nbits;
73673 u32 chunk;
73674 - const char __user __force *ubuf = (const char __user __force *)buf;
73675 + const char __user *ubuf = (const char __force_user *)buf;
73676
73677 bitmap_zero(maskp, nmaskbits);
73678
73679 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
73680 {
73681 if (!access_ok(VERIFY_READ, ubuf, ulen))
73682 return -EFAULT;
73683 - return __bitmap_parse((const char __force *)ubuf,
73684 + return __bitmap_parse((const char __force_kernel *)ubuf,
73685 ulen, 1, maskp, nmaskbits);
73686
73687 }
73688 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
73689 {
73690 unsigned a, b;
73691 int c, old_c, totaldigits;
73692 - const char __user __force *ubuf = (const char __user __force *)buf;
73693 + const char __user *ubuf = (const char __force_user *)buf;
73694 int exp_digit, in_range;
73695
73696 totaldigits = c = 0;
73697 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
73698 {
73699 if (!access_ok(VERIFY_READ, ubuf, ulen))
73700 return -EFAULT;
73701 - return __bitmap_parselist((const char __force *)ubuf,
73702 + return __bitmap_parselist((const char __force_kernel *)ubuf,
73703 ulen, 1, maskp, nmaskbits);
73704 }
73705 EXPORT_SYMBOL(bitmap_parselist_user);
73706 diff --git a/lib/bug.c b/lib/bug.c
73707 index d0cdf14..4d07bd2 100644
73708 --- a/lib/bug.c
73709 +++ b/lib/bug.c
73710 @@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
73711 return BUG_TRAP_TYPE_NONE;
73712
73713 bug = find_bug(bugaddr);
73714 + if (!bug)
73715 + return BUG_TRAP_TYPE_NONE;
73716
73717 file = NULL;
73718 line = 0;
73719 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
73720 index d11808c..dc2d6f8 100644
73721 --- a/lib/debugobjects.c
73722 +++ b/lib/debugobjects.c
73723 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
73724 if (limit > 4)
73725 return;
73726
73727 - is_on_stack = object_is_on_stack(addr);
73728 + is_on_stack = object_starts_on_stack(addr);
73729 if (is_on_stack == onstack)
73730 return;
73731
73732 diff --git a/lib/devres.c b/lib/devres.c
73733 index 80b9c76..9e32279 100644
73734 --- a/lib/devres.c
73735 +++ b/lib/devres.c
73736 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
73737 void devm_iounmap(struct device *dev, void __iomem *addr)
73738 {
73739 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
73740 - (void *)addr));
73741 + (void __force *)addr));
73742 iounmap(addr);
73743 }
73744 EXPORT_SYMBOL(devm_iounmap);
73745 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
73746 {
73747 ioport_unmap(addr);
73748 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
73749 - devm_ioport_map_match, (void *)addr));
73750 + devm_ioport_map_match, (void __force *)addr));
73751 }
73752 EXPORT_SYMBOL(devm_ioport_unmap);
73753
73754 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
73755 index d84beb9..da44791 100644
73756 --- a/lib/dma-debug.c
73757 +++ b/lib/dma-debug.c
73758 @@ -754,7 +754,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
73759
73760 void dma_debug_add_bus(struct bus_type *bus)
73761 {
73762 - struct notifier_block *nb;
73763 + notifier_block_no_const *nb;
73764
73765 if (global_disable)
73766 return;
73767 @@ -919,7 +919,7 @@ out:
73768
73769 static void check_for_stack(struct device *dev, void *addr)
73770 {
73771 - if (object_is_on_stack(addr))
73772 + if (object_starts_on_stack(addr))
73773 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
73774 "stack [addr=%p]\n", addr);
73775 }
73776 diff --git a/lib/inflate.c b/lib/inflate.c
73777 index 013a761..c28f3fc 100644
73778 --- a/lib/inflate.c
73779 +++ b/lib/inflate.c
73780 @@ -269,7 +269,7 @@ static void free(void *where)
73781 malloc_ptr = free_mem_ptr;
73782 }
73783 #else
73784 -#define malloc(a) kmalloc(a, GFP_KERNEL)
73785 +#define malloc(a) kmalloc((a), GFP_KERNEL)
73786 #define free(a) kfree(a)
73787 #endif
73788
73789 diff --git a/lib/ioremap.c b/lib/ioremap.c
73790 index 0c9216c..863bd89 100644
73791 --- a/lib/ioremap.c
73792 +++ b/lib/ioremap.c
73793 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
73794 unsigned long next;
73795
73796 phys_addr -= addr;
73797 - pmd = pmd_alloc(&init_mm, pud, addr);
73798 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
73799 if (!pmd)
73800 return -ENOMEM;
73801 do {
73802 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
73803 unsigned long next;
73804
73805 phys_addr -= addr;
73806 - pud = pud_alloc(&init_mm, pgd, addr);
73807 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
73808 if (!pud)
73809 return -ENOMEM;
73810 do {
73811 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
73812 index bd2bea9..6b3c95e 100644
73813 --- a/lib/is_single_threaded.c
73814 +++ b/lib/is_single_threaded.c
73815 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
73816 struct task_struct *p, *t;
73817 bool ret;
73818
73819 + if (!mm)
73820 + return true;
73821 +
73822 if (atomic_read(&task->signal->live) != 1)
73823 return false;
73824
73825 diff --git a/lib/list_debug.c b/lib/list_debug.c
73826 index c24c2f7..3fc5da0 100644
73827 --- a/lib/list_debug.c
73828 +++ b/lib/list_debug.c
73829 @@ -11,7 +11,9 @@
73830 #include <linux/bug.h>
73831 #include <linux/kernel.h>
73832 #include <linux/rculist.h>
73833 +#include <linux/mm.h>
73834
73835 +#ifdef CONFIG_DEBUG_LIST
73836 /*
73837 * Insert a new entry between two known consecutive entries.
73838 *
73839 @@ -19,21 +21,32 @@
73840 * the prev/next entries already!
73841 */
73842
73843 -void __list_add(struct list_head *new,
73844 - struct list_head *prev,
73845 - struct list_head *next)
73846 +static bool __list_add_debug(struct list_head *new,
73847 + struct list_head *prev,
73848 + struct list_head *next)
73849 {
73850 - WARN(next->prev != prev,
73851 + if (WARN(next->prev != prev,
73852 "list_add corruption. next->prev should be "
73853 "prev (%p), but was %p. (next=%p).\n",
73854 - prev, next->prev, next);
73855 - WARN(prev->next != next,
73856 + prev, next->prev, next) ||
73857 + WARN(prev->next != next,
73858 "list_add corruption. prev->next should be "
73859 "next (%p), but was %p. (prev=%p).\n",
73860 - next, prev->next, prev);
73861 - WARN(new == prev || new == next,
73862 + next, prev->next, prev) ||
73863 + WARN(new == prev || new == next,
73864 "list_add double add: new=%p, prev=%p, next=%p.\n",
73865 - new, prev, next);
73866 + new, prev, next))
73867 + return false;
73868 + return true;
73869 +}
73870 +
73871 +void __list_add(struct list_head *new,
73872 + struct list_head *prev,
73873 + struct list_head *next)
73874 +{
73875 + if (!__list_add_debug(new, prev, next))
73876 + return;
73877 +
73878 next->prev = new;
73879 new->next = next;
73880 new->prev = prev;
73881 @@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
73882 }
73883 EXPORT_SYMBOL(__list_add);
73884
73885 -void __list_del_entry(struct list_head *entry)
73886 +static bool __list_del_entry_debug(struct list_head *entry)
73887 {
73888 struct list_head *prev, *next;
73889
73890 @@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
73891 WARN(next->prev != entry,
73892 "list_del corruption. next->prev should be %p, "
73893 "but was %p\n", entry, next->prev))
73894 + return false;
73895 + return true;
73896 +}
73897 +
73898 +void __list_del_entry(struct list_head *entry)
73899 +{
73900 + if (!__list_del_entry_debug(entry))
73901 return;
73902
73903 - __list_del(prev, next);
73904 + __list_del(entry->prev, entry->next);
73905 }
73906 EXPORT_SYMBOL(__list_del_entry);
73907
73908 @@ -86,15 +106,54 @@ EXPORT_SYMBOL(list_del);
73909 void __list_add_rcu(struct list_head *new,
73910 struct list_head *prev, struct list_head *next)
73911 {
73912 - WARN(next->prev != prev,
73913 + if (WARN(next->prev != prev,
73914 "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
73915 - prev, next->prev, next);
73916 - WARN(prev->next != next,
73917 + prev, next->prev, next) ||
73918 + WARN(prev->next != next,
73919 "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
73920 - next, prev->next, prev);
73921 + next, prev->next, prev))
73922 + return;
73923 +
73924 new->next = next;
73925 new->prev = prev;
73926 rcu_assign_pointer(list_next_rcu(prev), new);
73927 next->prev = new;
73928 }
73929 EXPORT_SYMBOL(__list_add_rcu);
73930 +#endif
73931 +
73932 +void pax_list_add_tail(struct list_head *new, struct list_head *head)
73933 +{
73934 + struct list_head *prev, *next;
73935 +
73936 + prev = head->prev;
73937 + next = head;
73938 +
73939 +#ifdef CONFIG_DEBUG_LIST
73940 + if (!__list_add_debug(new, prev, next))
73941 + return;
73942 +#endif
73943 +
73944 + pax_open_kernel();
73945 + next->prev = new;
73946 + new->next = next;
73947 + new->prev = prev;
73948 + prev->next = new;
73949 + pax_close_kernel();
73950 +}
73951 +EXPORT_SYMBOL(pax_list_add_tail);
73952 +
73953 +void pax_list_del(struct list_head *entry)
73954 +{
73955 +#ifdef CONFIG_DEBUG_LIST
73956 + if (!__list_del_entry_debug(entry))
73957 + return;
73958 +#endif
73959 +
73960 + pax_open_kernel();
73961 + __list_del(entry->prev, entry->next);
73962 + entry->next = LIST_POISON1;
73963 + entry->prev = LIST_POISON2;
73964 + pax_close_kernel();
73965 +}
73966 +EXPORT_SYMBOL(pax_list_del);
73967 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
73968 index e796429..6e38f9f 100644
73969 --- a/lib/radix-tree.c
73970 +++ b/lib/radix-tree.c
73971 @@ -92,7 +92,7 @@ struct radix_tree_preload {
73972 int nr;
73973 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
73974 };
73975 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
73976 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
73977
73978 static inline void *ptr_to_indirect(void *ptr)
73979 {
73980 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
73981 index bb2b201..46abaf9 100644
73982 --- a/lib/strncpy_from_user.c
73983 +++ b/lib/strncpy_from_user.c
73984 @@ -21,7 +21,7 @@
73985 */
73986 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
73987 {
73988 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73989 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73990 long res = 0;
73991
73992 /*
73993 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
73994 index a28df52..3d55877 100644
73995 --- a/lib/strnlen_user.c
73996 +++ b/lib/strnlen_user.c
73997 @@ -26,7 +26,7 @@
73998 */
73999 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
74000 {
74001 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
74002 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
74003 long align, res = 0;
74004 unsigned long c;
74005
74006 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
74007 index 39c99fe..18f060b 100644
74008 --- a/lib/vsprintf.c
74009 +++ b/lib/vsprintf.c
74010 @@ -16,6 +16,9 @@
74011 * - scnprintf and vscnprintf
74012 */
74013
74014 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74015 +#define __INCLUDED_BY_HIDESYM 1
74016 +#endif
74017 #include <stdarg.h>
74018 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
74019 #include <linux/types.h>
74020 @@ -533,7 +536,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
74021 char sym[KSYM_SYMBOL_LEN];
74022 if (ext == 'B')
74023 sprint_backtrace(sym, value);
74024 - else if (ext != 'f' && ext != 's')
74025 + else if (ext != 'f' && ext != 's' && ext != 'a')
74026 sprint_symbol(sym, value);
74027 else
74028 sprint_symbol_no_offset(sym, value);
74029 @@ -966,7 +969,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
74030 return number(buf, end, *(const netdev_features_t *)addr, spec);
74031 }
74032
74033 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74034 +int kptr_restrict __read_mostly = 2;
74035 +#else
74036 int kptr_restrict __read_mostly;
74037 +#endif
74038
74039 /*
74040 * Show a '%p' thing. A kernel extension is that the '%p' is followed
74041 @@ -980,6 +987,8 @@ int kptr_restrict __read_mostly;
74042 * - 'S' For symbolic direct pointers with offset
74043 * - 's' For symbolic direct pointers without offset
74044 * - 'B' For backtraced symbolic direct pointers with offset
74045 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
74046 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
74047 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
74048 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
74049 * - 'M' For a 6-byte MAC address, it prints the address in the
74050 @@ -1035,12 +1044,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
74051
74052 if (!ptr && *fmt != 'K') {
74053 /*
74054 - * Print (null) with the same width as a pointer so it makes
74055 + * Print (nil) with the same width as a pointer so it makes
74056 * tabular output look nice.
74057 */
74058 if (spec.field_width == -1)
74059 spec.field_width = default_width;
74060 - return string(buf, end, "(null)", spec);
74061 + return string(buf, end, "(nil)", spec);
74062 }
74063
74064 switch (*fmt) {
74065 @@ -1050,6 +1059,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
74066 /* Fallthrough */
74067 case 'S':
74068 case 's':
74069 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74070 + break;
74071 +#else
74072 + return symbol_string(buf, end, ptr, spec, *fmt);
74073 +#endif
74074 + case 'A':
74075 + case 'a':
74076 case 'B':
74077 return symbol_string(buf, end, ptr, spec, *fmt);
74078 case 'R':
74079 @@ -1090,6 +1106,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
74080 va_end(va);
74081 return buf;
74082 }
74083 + case 'P':
74084 + break;
74085 case 'K':
74086 /*
74087 * %pK cannot be used in IRQ context because its test
74088 @@ -1113,6 +1131,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
74089 }
74090 break;
74091 }
74092 +
74093 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74094 + /* 'P' = approved pointers to copy to userland,
74095 + as in the /proc/kallsyms case, as we make it display nothing
74096 + for non-root users, and the real contents for root users
74097 + Also ignore 'K' pointers, since we force their NULLing for non-root users
74098 + above
74099 + */
74100 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
74101 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
74102 + dump_stack();
74103 + ptr = NULL;
74104 + }
74105 +#endif
74106 +
74107 spec.flags |= SMALL;
74108 if (spec.field_width == -1) {
74109 spec.field_width = default_width;
74110 @@ -1831,11 +1864,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
74111 typeof(type) value; \
74112 if (sizeof(type) == 8) { \
74113 args = PTR_ALIGN(args, sizeof(u32)); \
74114 - *(u32 *)&value = *(u32 *)args; \
74115 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
74116 + *(u32 *)&value = *(const u32 *)args; \
74117 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
74118 } else { \
74119 args = PTR_ALIGN(args, sizeof(type)); \
74120 - value = *(typeof(type) *)args; \
74121 + value = *(const typeof(type) *)args; \
74122 } \
74123 args += sizeof(type); \
74124 value; \
74125 @@ -1898,7 +1931,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
74126 case FORMAT_TYPE_STR: {
74127 const char *str_arg = args;
74128 args += strlen(str_arg) + 1;
74129 - str = string(str, end, (char *)str_arg, spec);
74130 + str = string(str, end, str_arg, spec);
74131 break;
74132 }
74133
74134 diff --git a/localversion-grsec b/localversion-grsec
74135 new file mode 100644
74136 index 0000000..7cd6065
74137 --- /dev/null
74138 +++ b/localversion-grsec
74139 @@ -0,0 +1 @@
74140 +-grsec
74141 diff --git a/mm/Kconfig b/mm/Kconfig
74142 index a3f8ddd..f31e92e 100644
74143 --- a/mm/Kconfig
74144 +++ b/mm/Kconfig
74145 @@ -252,10 +252,10 @@ config KSM
74146 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
74147
74148 config DEFAULT_MMAP_MIN_ADDR
74149 - int "Low address space to protect from user allocation"
74150 + int "Low address space to protect from user allocation"
74151 depends on MMU
74152 - default 4096
74153 - help
74154 + default 65536
74155 + help
74156 This is the portion of low virtual memory which should be protected
74157 from userspace allocation. Keeping a user from writing to low pages
74158 can help reduce the impact of kernel NULL pointer bugs.
74159 @@ -286,7 +286,7 @@ config MEMORY_FAILURE
74160
74161 config HWPOISON_INJECT
74162 tristate "HWPoison pages injector"
74163 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
74164 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
74165 select PROC_PAGE_MONITOR
74166
74167 config NOMMU_INITIAL_TRIM_EXCESS
74168 diff --git a/mm/filemap.c b/mm/filemap.c
74169 index 83efee7..3f99381 100644
74170 --- a/mm/filemap.c
74171 +++ b/mm/filemap.c
74172 @@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
74173 struct address_space *mapping = file->f_mapping;
74174
74175 if (!mapping->a_ops->readpage)
74176 - return -ENOEXEC;
74177 + return -ENODEV;
74178 file_accessed(file);
74179 vma->vm_ops = &generic_file_vm_ops;
74180 return 0;
74181 @@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
74182 *pos = i_size_read(inode);
74183
74184 if (limit != RLIM_INFINITY) {
74185 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
74186 if (*pos >= limit) {
74187 send_sig(SIGXFSZ, current, 0);
74188 return -EFBIG;
74189 diff --git a/mm/fremap.c b/mm/fremap.c
74190 index a0aaf0e..20325c3 100644
74191 --- a/mm/fremap.c
74192 +++ b/mm/fremap.c
74193 @@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
74194 retry:
74195 vma = find_vma(mm, start);
74196
74197 +#ifdef CONFIG_PAX_SEGMEXEC
74198 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
74199 + goto out;
74200 +#endif
74201 +
74202 /*
74203 * Make sure the vma is shared, that it supports prefaulting,
74204 * and that the remapped range is valid and fully within
74205 diff --git a/mm/highmem.c b/mm/highmem.c
74206 index 09fc744..3936897 100644
74207 --- a/mm/highmem.c
74208 +++ b/mm/highmem.c
74209 @@ -138,9 +138,10 @@ static void flush_all_zero_pkmaps(void)
74210 * So no dangers, even with speculative execution.
74211 */
74212 page = pte_page(pkmap_page_table[i]);
74213 + pax_open_kernel();
74214 pte_clear(&init_mm, (unsigned long)page_address(page),
74215 &pkmap_page_table[i]);
74216 -
74217 + pax_close_kernel();
74218 set_page_address(page, NULL);
74219 need_flush = 1;
74220 }
74221 @@ -199,9 +200,11 @@ start:
74222 }
74223 }
74224 vaddr = PKMAP_ADDR(last_pkmap_nr);
74225 +
74226 + pax_open_kernel();
74227 set_pte_at(&init_mm, vaddr,
74228 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
74229 -
74230 + pax_close_kernel();
74231 pkmap_count[last_pkmap_nr] = 1;
74232 set_page_address(page, (void *)vaddr);
74233
74234 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
74235 index 40f17c3..c1cc011 100644
74236 --- a/mm/huge_memory.c
74237 +++ b/mm/huge_memory.c
74238 @@ -710,7 +710,7 @@ out:
74239 * run pte_offset_map on the pmd, if an huge pmd could
74240 * materialize from under us from a different thread.
74241 */
74242 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
74243 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
74244 return VM_FAULT_OOM;
74245 /* if an huge pmd materialized from under us just retry later */
74246 if (unlikely(pmd_trans_huge(*pmd)))
74247 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
74248 index b969ed4..10e3e37 100644
74249 --- a/mm/hugetlb.c
74250 +++ b/mm/hugetlb.c
74251 @@ -2509,6 +2509,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
74252 return 1;
74253 }
74254
74255 +#ifdef CONFIG_PAX_SEGMEXEC
74256 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
74257 +{
74258 + struct mm_struct *mm = vma->vm_mm;
74259 + struct vm_area_struct *vma_m;
74260 + unsigned long address_m;
74261 + pte_t *ptep_m;
74262 +
74263 + vma_m = pax_find_mirror_vma(vma);
74264 + if (!vma_m)
74265 + return;
74266 +
74267 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74268 + address_m = address + SEGMEXEC_TASK_SIZE;
74269 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
74270 + get_page(page_m);
74271 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
74272 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
74273 +}
74274 +#endif
74275 +
74276 /*
74277 * Hugetlb_cow() should be called with page lock of the original hugepage held.
74278 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
74279 @@ -2627,6 +2648,11 @@ retry_avoidcopy:
74280 make_huge_pte(vma, new_page, 1));
74281 page_remove_rmap(old_page);
74282 hugepage_add_new_anon_rmap(new_page, vma, address);
74283 +
74284 +#ifdef CONFIG_PAX_SEGMEXEC
74285 + pax_mirror_huge_pte(vma, address, new_page);
74286 +#endif
74287 +
74288 /* Make the old page be freed below */
74289 new_page = old_page;
74290 }
74291 @@ -2786,6 +2812,10 @@ retry:
74292 && (vma->vm_flags & VM_SHARED)));
74293 set_huge_pte_at(mm, address, ptep, new_pte);
74294
74295 +#ifdef CONFIG_PAX_SEGMEXEC
74296 + pax_mirror_huge_pte(vma, address, page);
74297 +#endif
74298 +
74299 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
74300 /* Optimization, do the COW without a second fault */
74301 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
74302 @@ -2815,6 +2845,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74303 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
74304 struct hstate *h = hstate_vma(vma);
74305
74306 +#ifdef CONFIG_PAX_SEGMEXEC
74307 + struct vm_area_struct *vma_m;
74308 +#endif
74309 +
74310 address &= huge_page_mask(h);
74311
74312 ptep = huge_pte_offset(mm, address);
74313 @@ -2828,6 +2862,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74314 VM_FAULT_SET_HINDEX(hstate_index(h));
74315 }
74316
74317 +#ifdef CONFIG_PAX_SEGMEXEC
74318 + vma_m = pax_find_mirror_vma(vma);
74319 + if (vma_m) {
74320 + unsigned long address_m;
74321 +
74322 + if (vma->vm_start > vma_m->vm_start) {
74323 + address_m = address;
74324 + address -= SEGMEXEC_TASK_SIZE;
74325 + vma = vma_m;
74326 + h = hstate_vma(vma);
74327 + } else
74328 + address_m = address + SEGMEXEC_TASK_SIZE;
74329 +
74330 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
74331 + return VM_FAULT_OOM;
74332 + address_m &= HPAGE_MASK;
74333 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
74334 + }
74335 +#endif
74336 +
74337 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
74338 if (!ptep)
74339 return VM_FAULT_OOM;
74340 diff --git a/mm/internal.h b/mm/internal.h
74341 index 3c5197d..08d0065 100644
74342 --- a/mm/internal.h
74343 +++ b/mm/internal.h
74344 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
74345 * in mm/page_alloc.c
74346 */
74347 extern void __free_pages_bootmem(struct page *page, unsigned int order);
74348 +extern void free_compound_page(struct page *page);
74349 extern void prep_compound_page(struct page *page, unsigned long order);
74350 #ifdef CONFIG_MEMORY_FAILURE
74351 extern bool is_free_buddy_page(struct page *page);
74352 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
74353 index a217cc5..44b2b35 100644
74354 --- a/mm/kmemleak.c
74355 +++ b/mm/kmemleak.c
74356 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
74357
74358 for (i = 0; i < object->trace_len; i++) {
74359 void *ptr = (void *)object->trace[i];
74360 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
74361 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
74362 }
74363 }
74364
74365 @@ -1852,7 +1852,7 @@ static int __init kmemleak_late_init(void)
74366 return -ENOMEM;
74367 }
74368
74369 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
74370 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
74371 &kmemleak_fops);
74372 if (!dentry)
74373 pr_warning("Failed to create the debugfs kmemleak file\n");
74374 diff --git a/mm/maccess.c b/mm/maccess.c
74375 index d53adf9..03a24bf 100644
74376 --- a/mm/maccess.c
74377 +++ b/mm/maccess.c
74378 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
74379 set_fs(KERNEL_DS);
74380 pagefault_disable();
74381 ret = __copy_from_user_inatomic(dst,
74382 - (__force const void __user *)src, size);
74383 + (const void __force_user *)src, size);
74384 pagefault_enable();
74385 set_fs(old_fs);
74386
74387 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
74388
74389 set_fs(KERNEL_DS);
74390 pagefault_disable();
74391 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
74392 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
74393 pagefault_enable();
74394 set_fs(old_fs);
74395
74396 diff --git a/mm/madvise.c b/mm/madvise.c
74397 index 03dfa5c..b032917 100644
74398 --- a/mm/madvise.c
74399 +++ b/mm/madvise.c
74400 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
74401 pgoff_t pgoff;
74402 unsigned long new_flags = vma->vm_flags;
74403
74404 +#ifdef CONFIG_PAX_SEGMEXEC
74405 + struct vm_area_struct *vma_m;
74406 +#endif
74407 +
74408 switch (behavior) {
74409 case MADV_NORMAL:
74410 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
74411 @@ -123,6 +127,13 @@ success:
74412 /*
74413 * vm_flags is protected by the mmap_sem held in write mode.
74414 */
74415 +
74416 +#ifdef CONFIG_PAX_SEGMEXEC
74417 + vma_m = pax_find_mirror_vma(vma);
74418 + if (vma_m)
74419 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
74420 +#endif
74421 +
74422 vma->vm_flags = new_flags;
74423
74424 out:
74425 @@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
74426 struct vm_area_struct ** prev,
74427 unsigned long start, unsigned long end)
74428 {
74429 +
74430 +#ifdef CONFIG_PAX_SEGMEXEC
74431 + struct vm_area_struct *vma_m;
74432 +#endif
74433 +
74434 *prev = vma;
74435 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
74436 return -EINVAL;
74437 @@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
74438 zap_page_range(vma, start, end - start, &details);
74439 } else
74440 zap_page_range(vma, start, end - start, NULL);
74441 +
74442 +#ifdef CONFIG_PAX_SEGMEXEC
74443 + vma_m = pax_find_mirror_vma(vma);
74444 + if (vma_m) {
74445 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
74446 + struct zap_details details = {
74447 + .nonlinear_vma = vma_m,
74448 + .last_index = ULONG_MAX,
74449 + };
74450 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
74451 + } else
74452 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
74453 + }
74454 +#endif
74455 +
74456 return 0;
74457 }
74458
74459 @@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
74460 if (end < start)
74461 goto out;
74462
74463 +#ifdef CONFIG_PAX_SEGMEXEC
74464 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
74465 + if (end > SEGMEXEC_TASK_SIZE)
74466 + goto out;
74467 + } else
74468 +#endif
74469 +
74470 + if (end > TASK_SIZE)
74471 + goto out;
74472 +
74473 error = 0;
74474 if (end == start)
74475 goto out;
74476 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
74477 index 8b20278..05dac18 100644
74478 --- a/mm/memory-failure.c
74479 +++ b/mm/memory-failure.c
74480 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
74481
74482 int sysctl_memory_failure_recovery __read_mostly = 1;
74483
74484 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
74485 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
74486
74487 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
74488
74489 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
74490 pfn, t->comm, t->pid);
74491 si.si_signo = SIGBUS;
74492 si.si_errno = 0;
74493 - si.si_addr = (void *)addr;
74494 + si.si_addr = (void __user *)addr;
74495 #ifdef __ARCH_SI_TRAPNO
74496 si.si_trapno = trapno;
74497 #endif
74498 @@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
74499 }
74500
74501 nr_pages = 1 << compound_trans_order(hpage);
74502 - atomic_long_add(nr_pages, &mce_bad_pages);
74503 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
74504
74505 /*
74506 * We need/can do nothing about count=0 pages.
74507 @@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
74508 if (!PageHWPoison(hpage)
74509 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
74510 || (p != hpage && TestSetPageHWPoison(hpage))) {
74511 - atomic_long_sub(nr_pages, &mce_bad_pages);
74512 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74513 return 0;
74514 }
74515 set_page_hwpoison_huge_page(hpage);
74516 @@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
74517 }
74518 if (hwpoison_filter(p)) {
74519 if (TestClearPageHWPoison(p))
74520 - atomic_long_sub(nr_pages, &mce_bad_pages);
74521 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74522 unlock_page(hpage);
74523 put_page(hpage);
74524 return 0;
74525 @@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
74526 return 0;
74527 }
74528 if (TestClearPageHWPoison(p))
74529 - atomic_long_sub(nr_pages, &mce_bad_pages);
74530 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74531 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
74532 return 0;
74533 }
74534 @@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
74535 */
74536 if (TestClearPageHWPoison(page)) {
74537 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
74538 - atomic_long_sub(nr_pages, &mce_bad_pages);
74539 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74540 freeit = 1;
74541 if (PageHuge(page))
74542 clear_page_hwpoison_huge_page(page);
74543 @@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
74544 }
74545 done:
74546 if (!PageHWPoison(hpage))
74547 - atomic_long_add(1 << compound_trans_order(hpage),
74548 + atomic_long_add_unchecked(1 << compound_trans_order(hpage),
74549 &mce_bad_pages);
74550 set_page_hwpoison_huge_page(hpage);
74551 dequeue_hwpoisoned_huge_page(hpage);
74552 @@ -1582,7 +1582,7 @@ int soft_offline_page(struct page *page, int flags)
74553 return ret;
74554
74555 done:
74556 - atomic_long_add(1, &mce_bad_pages);
74557 + atomic_long_add_unchecked(1, &mce_bad_pages);
74558 SetPageHWPoison(page);
74559 /* keep elevated page count for bad page */
74560 return ret;
74561 diff --git a/mm/memory.c b/mm/memory.c
74562 index f2973b2..fd020a7 100644
74563 --- a/mm/memory.c
74564 +++ b/mm/memory.c
74565 @@ -431,6 +431,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
74566 free_pte_range(tlb, pmd, addr);
74567 } while (pmd++, addr = next, addr != end);
74568
74569 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
74570 start &= PUD_MASK;
74571 if (start < floor)
74572 return;
74573 @@ -445,6 +446,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
74574 pmd = pmd_offset(pud, start);
74575 pud_clear(pud);
74576 pmd_free_tlb(tlb, pmd, start);
74577 +#endif
74578 +
74579 }
74580
74581 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
74582 @@ -464,6 +467,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
74583 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
74584 } while (pud++, addr = next, addr != end);
74585
74586 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
74587 start &= PGDIR_MASK;
74588 if (start < floor)
74589 return;
74590 @@ -478,6 +482,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
74591 pud = pud_offset(pgd, start);
74592 pgd_clear(pgd);
74593 pud_free_tlb(tlb, pud, start);
74594 +#endif
74595 +
74596 }
74597
74598 /*
74599 @@ -1626,12 +1632,6 @@ no_page_table:
74600 return page;
74601 }
74602
74603 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
74604 -{
74605 - return stack_guard_page_start(vma, addr) ||
74606 - stack_guard_page_end(vma, addr+PAGE_SIZE);
74607 -}
74608 -
74609 /**
74610 * __get_user_pages() - pin user pages in memory
74611 * @tsk: task_struct of target task
74612 @@ -1704,10 +1704,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74613 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
74614 i = 0;
74615
74616 - do {
74617 + while (nr_pages) {
74618 struct vm_area_struct *vma;
74619
74620 - vma = find_extend_vma(mm, start);
74621 + vma = find_vma(mm, start);
74622 if (!vma && in_gate_area(mm, start)) {
74623 unsigned long pg = start & PAGE_MASK;
74624 pgd_t *pgd;
74625 @@ -1755,7 +1755,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74626 goto next_page;
74627 }
74628
74629 - if (!vma ||
74630 + if (!vma || start < vma->vm_start ||
74631 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
74632 !(vm_flags & vma->vm_flags))
74633 return i ? : -EFAULT;
74634 @@ -1782,11 +1782,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74635 int ret;
74636 unsigned int fault_flags = 0;
74637
74638 - /* For mlock, just skip the stack guard page. */
74639 - if (foll_flags & FOLL_MLOCK) {
74640 - if (stack_guard_page(vma, start))
74641 - goto next_page;
74642 - }
74643 if (foll_flags & FOLL_WRITE)
74644 fault_flags |= FAULT_FLAG_WRITE;
74645 if (nonblocking)
74646 @@ -1860,7 +1855,7 @@ next_page:
74647 start += PAGE_SIZE;
74648 nr_pages--;
74649 } while (nr_pages && start < vma->vm_end);
74650 - } while (nr_pages);
74651 + }
74652 return i;
74653 }
74654 EXPORT_SYMBOL(__get_user_pages);
74655 @@ -2067,6 +2062,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
74656 page_add_file_rmap(page);
74657 set_pte_at(mm, addr, pte, mk_pte(page, prot));
74658
74659 +#ifdef CONFIG_PAX_SEGMEXEC
74660 + pax_mirror_file_pte(vma, addr, page, ptl);
74661 +#endif
74662 +
74663 retval = 0;
74664 pte_unmap_unlock(pte, ptl);
74665 return retval;
74666 @@ -2111,9 +2110,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
74667 if (!page_count(page))
74668 return -EINVAL;
74669 if (!(vma->vm_flags & VM_MIXEDMAP)) {
74670 +
74671 +#ifdef CONFIG_PAX_SEGMEXEC
74672 + struct vm_area_struct *vma_m;
74673 +#endif
74674 +
74675 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
74676 BUG_ON(vma->vm_flags & VM_PFNMAP);
74677 vma->vm_flags |= VM_MIXEDMAP;
74678 +
74679 +#ifdef CONFIG_PAX_SEGMEXEC
74680 + vma_m = pax_find_mirror_vma(vma);
74681 + if (vma_m)
74682 + vma_m->vm_flags |= VM_MIXEDMAP;
74683 +#endif
74684 +
74685 }
74686 return insert_page(vma, addr, page, vma->vm_page_prot);
74687 }
74688 @@ -2196,6 +2207,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
74689 unsigned long pfn)
74690 {
74691 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
74692 + BUG_ON(vma->vm_mirror);
74693
74694 if (addr < vma->vm_start || addr >= vma->vm_end)
74695 return -EFAULT;
74696 @@ -2396,7 +2408,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
74697
74698 BUG_ON(pud_huge(*pud));
74699
74700 - pmd = pmd_alloc(mm, pud, addr);
74701 + pmd = (mm == &init_mm) ?
74702 + pmd_alloc_kernel(mm, pud, addr) :
74703 + pmd_alloc(mm, pud, addr);
74704 if (!pmd)
74705 return -ENOMEM;
74706 do {
74707 @@ -2416,7 +2430,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
74708 unsigned long next;
74709 int err;
74710
74711 - pud = pud_alloc(mm, pgd, addr);
74712 + pud = (mm == &init_mm) ?
74713 + pud_alloc_kernel(mm, pgd, addr) :
74714 + pud_alloc(mm, pgd, addr);
74715 if (!pud)
74716 return -ENOMEM;
74717 do {
74718 @@ -2504,6 +2520,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
74719 copy_user_highpage(dst, src, va, vma);
74720 }
74721
74722 +#ifdef CONFIG_PAX_SEGMEXEC
74723 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
74724 +{
74725 + struct mm_struct *mm = vma->vm_mm;
74726 + spinlock_t *ptl;
74727 + pte_t *pte, entry;
74728 +
74729 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
74730 + entry = *pte;
74731 + if (!pte_present(entry)) {
74732 + if (!pte_none(entry)) {
74733 + BUG_ON(pte_file(entry));
74734 + free_swap_and_cache(pte_to_swp_entry(entry));
74735 + pte_clear_not_present_full(mm, address, pte, 0);
74736 + }
74737 + } else {
74738 + struct page *page;
74739 +
74740 + flush_cache_page(vma, address, pte_pfn(entry));
74741 + entry = ptep_clear_flush(vma, address, pte);
74742 + BUG_ON(pte_dirty(entry));
74743 + page = vm_normal_page(vma, address, entry);
74744 + if (page) {
74745 + update_hiwater_rss(mm);
74746 + if (PageAnon(page))
74747 + dec_mm_counter_fast(mm, MM_ANONPAGES);
74748 + else
74749 + dec_mm_counter_fast(mm, MM_FILEPAGES);
74750 + page_remove_rmap(page);
74751 + page_cache_release(page);
74752 + }
74753 + }
74754 + pte_unmap_unlock(pte, ptl);
74755 +}
74756 +
74757 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
74758 + *
74759 + * the ptl of the lower mapped page is held on entry and is not released on exit
74760 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
74761 + */
74762 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
74763 +{
74764 + struct mm_struct *mm = vma->vm_mm;
74765 + unsigned long address_m;
74766 + spinlock_t *ptl_m;
74767 + struct vm_area_struct *vma_m;
74768 + pmd_t *pmd_m;
74769 + pte_t *pte_m, entry_m;
74770 +
74771 + BUG_ON(!page_m || !PageAnon(page_m));
74772 +
74773 + vma_m = pax_find_mirror_vma(vma);
74774 + if (!vma_m)
74775 + return;
74776 +
74777 + BUG_ON(!PageLocked(page_m));
74778 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74779 + address_m = address + SEGMEXEC_TASK_SIZE;
74780 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
74781 + pte_m = pte_offset_map(pmd_m, address_m);
74782 + ptl_m = pte_lockptr(mm, pmd_m);
74783 + if (ptl != ptl_m) {
74784 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
74785 + if (!pte_none(*pte_m))
74786 + goto out;
74787 + }
74788 +
74789 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
74790 + page_cache_get(page_m);
74791 + page_add_anon_rmap(page_m, vma_m, address_m);
74792 + inc_mm_counter_fast(mm, MM_ANONPAGES);
74793 + set_pte_at(mm, address_m, pte_m, entry_m);
74794 + update_mmu_cache(vma_m, address_m, entry_m);
74795 +out:
74796 + if (ptl != ptl_m)
74797 + spin_unlock(ptl_m);
74798 + pte_unmap(pte_m);
74799 + unlock_page(page_m);
74800 +}
74801 +
74802 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
74803 +{
74804 + struct mm_struct *mm = vma->vm_mm;
74805 + unsigned long address_m;
74806 + spinlock_t *ptl_m;
74807 + struct vm_area_struct *vma_m;
74808 + pmd_t *pmd_m;
74809 + pte_t *pte_m, entry_m;
74810 +
74811 + BUG_ON(!page_m || PageAnon(page_m));
74812 +
74813 + vma_m = pax_find_mirror_vma(vma);
74814 + if (!vma_m)
74815 + return;
74816 +
74817 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74818 + address_m = address + SEGMEXEC_TASK_SIZE;
74819 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
74820 + pte_m = pte_offset_map(pmd_m, address_m);
74821 + ptl_m = pte_lockptr(mm, pmd_m);
74822 + if (ptl != ptl_m) {
74823 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
74824 + if (!pte_none(*pte_m))
74825 + goto out;
74826 + }
74827 +
74828 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
74829 + page_cache_get(page_m);
74830 + page_add_file_rmap(page_m);
74831 + inc_mm_counter_fast(mm, MM_FILEPAGES);
74832 + set_pte_at(mm, address_m, pte_m, entry_m);
74833 + update_mmu_cache(vma_m, address_m, entry_m);
74834 +out:
74835 + if (ptl != ptl_m)
74836 + spin_unlock(ptl_m);
74837 + pte_unmap(pte_m);
74838 +}
74839 +
74840 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
74841 +{
74842 + struct mm_struct *mm = vma->vm_mm;
74843 + unsigned long address_m;
74844 + spinlock_t *ptl_m;
74845 + struct vm_area_struct *vma_m;
74846 + pmd_t *pmd_m;
74847 + pte_t *pte_m, entry_m;
74848 +
74849 + vma_m = pax_find_mirror_vma(vma);
74850 + if (!vma_m)
74851 + return;
74852 +
74853 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74854 + address_m = address + SEGMEXEC_TASK_SIZE;
74855 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
74856 + pte_m = pte_offset_map(pmd_m, address_m);
74857 + ptl_m = pte_lockptr(mm, pmd_m);
74858 + if (ptl != ptl_m) {
74859 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
74860 + if (!pte_none(*pte_m))
74861 + goto out;
74862 + }
74863 +
74864 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
74865 + set_pte_at(mm, address_m, pte_m, entry_m);
74866 +out:
74867 + if (ptl != ptl_m)
74868 + spin_unlock(ptl_m);
74869 + pte_unmap(pte_m);
74870 +}
74871 +
74872 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
74873 +{
74874 + struct page *page_m;
74875 + pte_t entry;
74876 +
74877 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
74878 + goto out;
74879 +
74880 + entry = *pte;
74881 + page_m = vm_normal_page(vma, address, entry);
74882 + if (!page_m)
74883 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
74884 + else if (PageAnon(page_m)) {
74885 + if (pax_find_mirror_vma(vma)) {
74886 + pte_unmap_unlock(pte, ptl);
74887 + lock_page(page_m);
74888 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
74889 + if (pte_same(entry, *pte))
74890 + pax_mirror_anon_pte(vma, address, page_m, ptl);
74891 + else
74892 + unlock_page(page_m);
74893 + }
74894 + } else
74895 + pax_mirror_file_pte(vma, address, page_m, ptl);
74896 +
74897 +out:
74898 + pte_unmap_unlock(pte, ptl);
74899 +}
74900 +#endif
74901 +
74902 /*
74903 * This routine handles present pages, when users try to write
74904 * to a shared page. It is done by copying the page to a new address
74905 @@ -2720,6 +2916,12 @@ gotten:
74906 */
74907 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
74908 if (likely(pte_same(*page_table, orig_pte))) {
74909 +
74910 +#ifdef CONFIG_PAX_SEGMEXEC
74911 + if (pax_find_mirror_vma(vma))
74912 + BUG_ON(!trylock_page(new_page));
74913 +#endif
74914 +
74915 if (old_page) {
74916 if (!PageAnon(old_page)) {
74917 dec_mm_counter_fast(mm, MM_FILEPAGES);
74918 @@ -2771,6 +2973,10 @@ gotten:
74919 page_remove_rmap(old_page);
74920 }
74921
74922 +#ifdef CONFIG_PAX_SEGMEXEC
74923 + pax_mirror_anon_pte(vma, address, new_page, ptl);
74924 +#endif
74925 +
74926 /* Free the old page.. */
74927 new_page = old_page;
74928 ret |= VM_FAULT_WRITE;
74929 @@ -3051,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
74930 swap_free(entry);
74931 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
74932 try_to_free_swap(page);
74933 +
74934 +#ifdef CONFIG_PAX_SEGMEXEC
74935 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
74936 +#endif
74937 +
74938 unlock_page(page);
74939 if (swapcache) {
74940 /*
74941 @@ -3074,6 +3285,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
74942
74943 /* No need to invalidate - it was non-present before */
74944 update_mmu_cache(vma, address, page_table);
74945 +
74946 +#ifdef CONFIG_PAX_SEGMEXEC
74947 + pax_mirror_anon_pte(vma, address, page, ptl);
74948 +#endif
74949 +
74950 unlock:
74951 pte_unmap_unlock(page_table, ptl);
74952 out:
74953 @@ -3093,40 +3309,6 @@ out_release:
74954 }
74955
74956 /*
74957 - * This is like a special single-page "expand_{down|up}wards()",
74958 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
74959 - * doesn't hit another vma.
74960 - */
74961 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
74962 -{
74963 - address &= PAGE_MASK;
74964 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
74965 - struct vm_area_struct *prev = vma->vm_prev;
74966 -
74967 - /*
74968 - * Is there a mapping abutting this one below?
74969 - *
74970 - * That's only ok if it's the same stack mapping
74971 - * that has gotten split..
74972 - */
74973 - if (prev && prev->vm_end == address)
74974 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
74975 -
74976 - expand_downwards(vma, address - PAGE_SIZE);
74977 - }
74978 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
74979 - struct vm_area_struct *next = vma->vm_next;
74980 -
74981 - /* As VM_GROWSDOWN but s/below/above/ */
74982 - if (next && next->vm_start == address + PAGE_SIZE)
74983 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
74984 -
74985 - expand_upwards(vma, address + PAGE_SIZE);
74986 - }
74987 - return 0;
74988 -}
74989 -
74990 -/*
74991 * We enter with non-exclusive mmap_sem (to exclude vma changes,
74992 * but allow concurrent faults), and pte mapped but not yet locked.
74993 * We return with mmap_sem still held, but pte unmapped and unlocked.
74994 @@ -3135,27 +3317,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
74995 unsigned long address, pte_t *page_table, pmd_t *pmd,
74996 unsigned int flags)
74997 {
74998 - struct page *page;
74999 + struct page *page = NULL;
75000 spinlock_t *ptl;
75001 pte_t entry;
75002
75003 - pte_unmap(page_table);
75004 -
75005 - /* Check if we need to add a guard page to the stack */
75006 - if (check_stack_guard_page(vma, address) < 0)
75007 - return VM_FAULT_SIGBUS;
75008 -
75009 - /* Use the zero-page for reads */
75010 if (!(flags & FAULT_FLAG_WRITE)) {
75011 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
75012 vma->vm_page_prot));
75013 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
75014 + ptl = pte_lockptr(mm, pmd);
75015 + spin_lock(ptl);
75016 if (!pte_none(*page_table))
75017 goto unlock;
75018 goto setpte;
75019 }
75020
75021 /* Allocate our own private page. */
75022 + pte_unmap(page_table);
75023 +
75024 if (unlikely(anon_vma_prepare(vma)))
75025 goto oom;
75026 page = alloc_zeroed_user_highpage_movable(vma, address);
75027 @@ -3174,6 +3352,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
75028 if (!pte_none(*page_table))
75029 goto release;
75030
75031 +#ifdef CONFIG_PAX_SEGMEXEC
75032 + if (pax_find_mirror_vma(vma))
75033 + BUG_ON(!trylock_page(page));
75034 +#endif
75035 +
75036 inc_mm_counter_fast(mm, MM_ANONPAGES);
75037 page_add_new_anon_rmap(page, vma, address);
75038 setpte:
75039 @@ -3181,6 +3364,12 @@ setpte:
75040
75041 /* No need to invalidate - it was non-present before */
75042 update_mmu_cache(vma, address, page_table);
75043 +
75044 +#ifdef CONFIG_PAX_SEGMEXEC
75045 + if (page)
75046 + pax_mirror_anon_pte(vma, address, page, ptl);
75047 +#endif
75048 +
75049 unlock:
75050 pte_unmap_unlock(page_table, ptl);
75051 return 0;
75052 @@ -3324,6 +3513,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75053 */
75054 /* Only go through if we didn't race with anybody else... */
75055 if (likely(pte_same(*page_table, orig_pte))) {
75056 +
75057 +#ifdef CONFIG_PAX_SEGMEXEC
75058 + if (anon && pax_find_mirror_vma(vma))
75059 + BUG_ON(!trylock_page(page));
75060 +#endif
75061 +
75062 flush_icache_page(vma, page);
75063 entry = mk_pte(page, vma->vm_page_prot);
75064 if (flags & FAULT_FLAG_WRITE)
75065 @@ -3343,6 +3538,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75066
75067 /* no need to invalidate: a not-present page won't be cached */
75068 update_mmu_cache(vma, address, page_table);
75069 +
75070 +#ifdef CONFIG_PAX_SEGMEXEC
75071 + if (anon)
75072 + pax_mirror_anon_pte(vma, address, page, ptl);
75073 + else
75074 + pax_mirror_file_pte(vma, address, page, ptl);
75075 +#endif
75076 +
75077 } else {
75078 if (cow_page)
75079 mem_cgroup_uncharge_page(cow_page);
75080 @@ -3497,6 +3700,12 @@ int handle_pte_fault(struct mm_struct *mm,
75081 if (flags & FAULT_FLAG_WRITE)
75082 flush_tlb_fix_spurious_fault(vma, address);
75083 }
75084 +
75085 +#ifdef CONFIG_PAX_SEGMEXEC
75086 + pax_mirror_pte(vma, address, pte, pmd, ptl);
75087 + return 0;
75088 +#endif
75089 +
75090 unlock:
75091 pte_unmap_unlock(pte, ptl);
75092 return 0;
75093 @@ -3513,6 +3722,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75094 pmd_t *pmd;
75095 pte_t *pte;
75096
75097 +#ifdef CONFIG_PAX_SEGMEXEC
75098 + struct vm_area_struct *vma_m;
75099 +#endif
75100 +
75101 __set_current_state(TASK_RUNNING);
75102
75103 count_vm_event(PGFAULT);
75104 @@ -3524,6 +3737,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75105 if (unlikely(is_vm_hugetlb_page(vma)))
75106 return hugetlb_fault(mm, vma, address, flags);
75107
75108 +#ifdef CONFIG_PAX_SEGMEXEC
75109 + vma_m = pax_find_mirror_vma(vma);
75110 + if (vma_m) {
75111 + unsigned long address_m;
75112 + pgd_t *pgd_m;
75113 + pud_t *pud_m;
75114 + pmd_t *pmd_m;
75115 +
75116 + if (vma->vm_start > vma_m->vm_start) {
75117 + address_m = address;
75118 + address -= SEGMEXEC_TASK_SIZE;
75119 + vma = vma_m;
75120 + } else
75121 + address_m = address + SEGMEXEC_TASK_SIZE;
75122 +
75123 + pgd_m = pgd_offset(mm, address_m);
75124 + pud_m = pud_alloc(mm, pgd_m, address_m);
75125 + if (!pud_m)
75126 + return VM_FAULT_OOM;
75127 + pmd_m = pmd_alloc(mm, pud_m, address_m);
75128 + if (!pmd_m)
75129 + return VM_FAULT_OOM;
75130 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
75131 + return VM_FAULT_OOM;
75132 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
75133 + }
75134 +#endif
75135 +
75136 retry:
75137 pgd = pgd_offset(mm, address);
75138 pud = pud_alloc(mm, pgd, address);
75139 @@ -3565,7 +3806,7 @@ retry:
75140 * run pte_offset_map on the pmd, if an huge pmd could
75141 * materialize from under us from a different thread.
75142 */
75143 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
75144 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
75145 return VM_FAULT_OOM;
75146 /* if an huge pmd materialized from under us just retry later */
75147 if (unlikely(pmd_trans_huge(*pmd)))
75148 @@ -3602,6 +3843,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
75149 spin_unlock(&mm->page_table_lock);
75150 return 0;
75151 }
75152 +
75153 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
75154 +{
75155 + pud_t *new = pud_alloc_one(mm, address);
75156 + if (!new)
75157 + return -ENOMEM;
75158 +
75159 + smp_wmb(); /* See comment in __pte_alloc */
75160 +
75161 + spin_lock(&mm->page_table_lock);
75162 + if (pgd_present(*pgd)) /* Another has populated it */
75163 + pud_free(mm, new);
75164 + else
75165 + pgd_populate_kernel(mm, pgd, new);
75166 + spin_unlock(&mm->page_table_lock);
75167 + return 0;
75168 +}
75169 #endif /* __PAGETABLE_PUD_FOLDED */
75170
75171 #ifndef __PAGETABLE_PMD_FOLDED
75172 @@ -3632,6 +3890,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
75173 spin_unlock(&mm->page_table_lock);
75174 return 0;
75175 }
75176 +
75177 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
75178 +{
75179 + pmd_t *new = pmd_alloc_one(mm, address);
75180 + if (!new)
75181 + return -ENOMEM;
75182 +
75183 + smp_wmb(); /* See comment in __pte_alloc */
75184 +
75185 + spin_lock(&mm->page_table_lock);
75186 +#ifndef __ARCH_HAS_4LEVEL_HACK
75187 + if (pud_present(*pud)) /* Another has populated it */
75188 + pmd_free(mm, new);
75189 + else
75190 + pud_populate_kernel(mm, pud, new);
75191 +#else
75192 + if (pgd_present(*pud)) /* Another has populated it */
75193 + pmd_free(mm, new);
75194 + else
75195 + pgd_populate_kernel(mm, pud, new);
75196 +#endif /* __ARCH_HAS_4LEVEL_HACK */
75197 + spin_unlock(&mm->page_table_lock);
75198 + return 0;
75199 +}
75200 #endif /* __PAGETABLE_PMD_FOLDED */
75201
75202 int make_pages_present(unsigned long addr, unsigned long end)
75203 @@ -3669,7 +3951,7 @@ static int __init gate_vma_init(void)
75204 gate_vma.vm_start = FIXADDR_USER_START;
75205 gate_vma.vm_end = FIXADDR_USER_END;
75206 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
75207 - gate_vma.vm_page_prot = __P101;
75208 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
75209
75210 return 0;
75211 }
75212 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
75213 index 002c281..9429765 100644
75214 --- a/mm/mempolicy.c
75215 +++ b/mm/mempolicy.c
75216 @@ -655,6 +655,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
75217 unsigned long vmstart;
75218 unsigned long vmend;
75219
75220 +#ifdef CONFIG_PAX_SEGMEXEC
75221 + struct vm_area_struct *vma_m;
75222 +#endif
75223 +
75224 vma = find_vma(mm, start);
75225 if (!vma || vma->vm_start > start)
75226 return -EFAULT;
75227 @@ -691,9 +695,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
75228 if (err)
75229 goto out;
75230 }
75231 +
75232 err = vma_replace_policy(vma, new_pol);
75233 if (err)
75234 goto out;
75235 +
75236 +#ifdef CONFIG_PAX_SEGMEXEC
75237 + vma_m = pax_find_mirror_vma(vma);
75238 + if (vma_m) {
75239 + err = vma_replace_policy(vma_m, new_pol);
75240 + if (err)
75241 + goto out;
75242 + }
75243 +#endif
75244 +
75245 }
75246
75247 out:
75248 @@ -1150,6 +1165,17 @@ static long do_mbind(unsigned long start, unsigned long len,
75249
75250 if (end < start)
75251 return -EINVAL;
75252 +
75253 +#ifdef CONFIG_PAX_SEGMEXEC
75254 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
75255 + if (end > SEGMEXEC_TASK_SIZE)
75256 + return -EINVAL;
75257 + } else
75258 +#endif
75259 +
75260 + if (end > TASK_SIZE)
75261 + return -EINVAL;
75262 +
75263 if (end == start)
75264 return 0;
75265
75266 @@ -1373,8 +1399,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
75267 */
75268 tcred = __task_cred(task);
75269 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
75270 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
75271 - !capable(CAP_SYS_NICE)) {
75272 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
75273 rcu_read_unlock();
75274 err = -EPERM;
75275 goto out_put;
75276 @@ -1405,6 +1430,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
75277 goto out;
75278 }
75279
75280 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
75281 + if (mm != current->mm &&
75282 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
75283 + mmput(mm);
75284 + err = -EPERM;
75285 + goto out;
75286 + }
75287 +#endif
75288 +
75289 err = do_migrate_pages(mm, old, new,
75290 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
75291
75292 diff --git a/mm/migrate.c b/mm/migrate.c
75293 index 346d32d..d7adff2 100644
75294 --- a/mm/migrate.c
75295 +++ b/mm/migrate.c
75296 @@ -1352,8 +1352,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
75297 */
75298 tcred = __task_cred(task);
75299 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
75300 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
75301 - !capable(CAP_SYS_NICE)) {
75302 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
75303 rcu_read_unlock();
75304 err = -EPERM;
75305 goto out;
75306 diff --git a/mm/mlock.c b/mm/mlock.c
75307 index f0b9ce5..da8d069 100644
75308 --- a/mm/mlock.c
75309 +++ b/mm/mlock.c
75310 @@ -13,6 +13,7 @@
75311 #include <linux/pagemap.h>
75312 #include <linux/mempolicy.h>
75313 #include <linux/syscalls.h>
75314 +#include <linux/security.h>
75315 #include <linux/sched.h>
75316 #include <linux/export.h>
75317 #include <linux/rmap.h>
75318 @@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
75319 {
75320 unsigned long nstart, end, tmp;
75321 struct vm_area_struct * vma, * prev;
75322 - int error;
75323 + int error = 0;
75324
75325 VM_BUG_ON(start & ~PAGE_MASK);
75326 VM_BUG_ON(len != PAGE_ALIGN(len));
75327 @@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
75328 return -EINVAL;
75329 if (end == start)
75330 return 0;
75331 + if (end > TASK_SIZE)
75332 + return -EINVAL;
75333 +
75334 vma = find_vma(current->mm, start);
75335 if (!vma || vma->vm_start > start)
75336 return -ENOMEM;
75337 @@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
75338 for (nstart = start ; ; ) {
75339 vm_flags_t newflags;
75340
75341 +#ifdef CONFIG_PAX_SEGMEXEC
75342 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
75343 + break;
75344 +#endif
75345 +
75346 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
75347
75348 newflags = vma->vm_flags | VM_LOCKED;
75349 @@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
75350 lock_limit >>= PAGE_SHIFT;
75351
75352 /* check against resource limits */
75353 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
75354 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
75355 error = do_mlock(start, len, 1);
75356 up_write(&current->mm->mmap_sem);
75357 @@ -517,17 +527,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
75358 static int do_mlockall(int flags)
75359 {
75360 struct vm_area_struct * vma, * prev = NULL;
75361 - unsigned int def_flags = 0;
75362
75363 if (flags & MCL_FUTURE)
75364 - def_flags = VM_LOCKED;
75365 - current->mm->def_flags = def_flags;
75366 + current->mm->def_flags |= VM_LOCKED;
75367 + else
75368 + current->mm->def_flags &= ~VM_LOCKED;
75369 if (flags == MCL_FUTURE)
75370 goto out;
75371
75372 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
75373 vm_flags_t newflags;
75374
75375 +#ifdef CONFIG_PAX_SEGMEXEC
75376 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
75377 + break;
75378 +#endif
75379 +
75380 + BUG_ON(vma->vm_end > TASK_SIZE);
75381 newflags = vma->vm_flags | VM_LOCKED;
75382 if (!(flags & MCL_CURRENT))
75383 newflags &= ~VM_LOCKED;
75384 @@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
75385 lock_limit >>= PAGE_SHIFT;
75386
75387 ret = -ENOMEM;
75388 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
75389 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
75390 capable(CAP_IPC_LOCK))
75391 ret = do_mlockall(flags);
75392 diff --git a/mm/mmap.c b/mm/mmap.c
75393 index 9a796c4..e2c9724 100644
75394 --- a/mm/mmap.c
75395 +++ b/mm/mmap.c
75396 @@ -31,6 +31,7 @@
75397 #include <linux/audit.h>
75398 #include <linux/khugepaged.h>
75399 #include <linux/uprobes.h>
75400 +#include <linux/random.h>
75401
75402 #include <asm/uaccess.h>
75403 #include <asm/cacheflush.h>
75404 @@ -47,6 +48,16 @@
75405 #define arch_rebalance_pgtables(addr, len) (addr)
75406 #endif
75407
75408 +static inline void verify_mm_writelocked(struct mm_struct *mm)
75409 +{
75410 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
75411 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
75412 + up_read(&mm->mmap_sem);
75413 + BUG();
75414 + }
75415 +#endif
75416 +}
75417 +
75418 static void unmap_region(struct mm_struct *mm,
75419 struct vm_area_struct *vma, struct vm_area_struct *prev,
75420 unsigned long start, unsigned long end);
75421 @@ -66,22 +77,32 @@ static void unmap_region(struct mm_struct *mm,
75422 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
75423 *
75424 */
75425 -pgprot_t protection_map[16] = {
75426 +pgprot_t protection_map[16] __read_only = {
75427 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
75428 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
75429 };
75430
75431 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
75432 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
75433 {
75434 - return __pgprot(pgprot_val(protection_map[vm_flags &
75435 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
75436 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
75437 pgprot_val(arch_vm_get_page_prot(vm_flags)));
75438 +
75439 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75440 + if (!(__supported_pte_mask & _PAGE_NX) &&
75441 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
75442 + (vm_flags & (VM_READ | VM_WRITE)))
75443 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
75444 +#endif
75445 +
75446 + return prot;
75447 }
75448 EXPORT_SYMBOL(vm_get_page_prot);
75449
75450 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
75451 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
75452 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
75453 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
75454 /*
75455 * Make sure vm_committed_as in one cacheline and not cacheline shared with
75456 * other variables. It can be updated by several CPUs frequently.
75457 @@ -223,6 +244,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
75458 struct vm_area_struct *next = vma->vm_next;
75459
75460 might_sleep();
75461 + BUG_ON(vma->vm_mirror);
75462 if (vma->vm_ops && vma->vm_ops->close)
75463 vma->vm_ops->close(vma);
75464 if (vma->vm_file)
75465 @@ -266,6 +288,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
75466 * not page aligned -Ram Gupta
75467 */
75468 rlim = rlimit(RLIMIT_DATA);
75469 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
75470 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
75471 (mm->end_data - mm->start_data) > rlim)
75472 goto out;
75473 @@ -736,6 +759,12 @@ static int
75474 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
75475 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
75476 {
75477 +
75478 +#ifdef CONFIG_PAX_SEGMEXEC
75479 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
75480 + return 0;
75481 +#endif
75482 +
75483 if (is_mergeable_vma(vma, file, vm_flags) &&
75484 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
75485 if (vma->vm_pgoff == vm_pgoff)
75486 @@ -755,6 +784,12 @@ static int
75487 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
75488 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
75489 {
75490 +
75491 +#ifdef CONFIG_PAX_SEGMEXEC
75492 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
75493 + return 0;
75494 +#endif
75495 +
75496 if (is_mergeable_vma(vma, file, vm_flags) &&
75497 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
75498 pgoff_t vm_pglen;
75499 @@ -797,13 +832,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
75500 struct vm_area_struct *vma_merge(struct mm_struct *mm,
75501 struct vm_area_struct *prev, unsigned long addr,
75502 unsigned long end, unsigned long vm_flags,
75503 - struct anon_vma *anon_vma, struct file *file,
75504 + struct anon_vma *anon_vma, struct file *file,
75505 pgoff_t pgoff, struct mempolicy *policy)
75506 {
75507 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
75508 struct vm_area_struct *area, *next;
75509 int err;
75510
75511 +#ifdef CONFIG_PAX_SEGMEXEC
75512 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
75513 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
75514 +
75515 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
75516 +#endif
75517 +
75518 /*
75519 * We later require that vma->vm_flags == vm_flags,
75520 * so this tests vma->vm_flags & VM_SPECIAL, too.
75521 @@ -819,6 +861,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
75522 if (next && next->vm_end == end) /* cases 6, 7, 8 */
75523 next = next->vm_next;
75524
75525 +#ifdef CONFIG_PAX_SEGMEXEC
75526 + if (prev)
75527 + prev_m = pax_find_mirror_vma(prev);
75528 + if (area)
75529 + area_m = pax_find_mirror_vma(area);
75530 + if (next)
75531 + next_m = pax_find_mirror_vma(next);
75532 +#endif
75533 +
75534 /*
75535 * Can it merge with the predecessor?
75536 */
75537 @@ -838,9 +889,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
75538 /* cases 1, 6 */
75539 err = vma_adjust(prev, prev->vm_start,
75540 next->vm_end, prev->vm_pgoff, NULL);
75541 - } else /* cases 2, 5, 7 */
75542 +
75543 +#ifdef CONFIG_PAX_SEGMEXEC
75544 + if (!err && prev_m)
75545 + err = vma_adjust(prev_m, prev_m->vm_start,
75546 + next_m->vm_end, prev_m->vm_pgoff, NULL);
75547 +#endif
75548 +
75549 + } else { /* cases 2, 5, 7 */
75550 err = vma_adjust(prev, prev->vm_start,
75551 end, prev->vm_pgoff, NULL);
75552 +
75553 +#ifdef CONFIG_PAX_SEGMEXEC
75554 + if (!err && prev_m)
75555 + err = vma_adjust(prev_m, prev_m->vm_start,
75556 + end_m, prev_m->vm_pgoff, NULL);
75557 +#endif
75558 +
75559 + }
75560 if (err)
75561 return NULL;
75562 khugepaged_enter_vma_merge(prev);
75563 @@ -854,12 +920,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
75564 mpol_equal(policy, vma_policy(next)) &&
75565 can_vma_merge_before(next, vm_flags,
75566 anon_vma, file, pgoff+pglen)) {
75567 - if (prev && addr < prev->vm_end) /* case 4 */
75568 + if (prev && addr < prev->vm_end) { /* case 4 */
75569 err = vma_adjust(prev, prev->vm_start,
75570 addr, prev->vm_pgoff, NULL);
75571 - else /* cases 3, 8 */
75572 +
75573 +#ifdef CONFIG_PAX_SEGMEXEC
75574 + if (!err && prev_m)
75575 + err = vma_adjust(prev_m, prev_m->vm_start,
75576 + addr_m, prev_m->vm_pgoff, NULL);
75577 +#endif
75578 +
75579 + } else { /* cases 3, 8 */
75580 err = vma_adjust(area, addr, next->vm_end,
75581 next->vm_pgoff - pglen, NULL);
75582 +
75583 +#ifdef CONFIG_PAX_SEGMEXEC
75584 + if (!err && area_m)
75585 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
75586 + next_m->vm_pgoff - pglen, NULL);
75587 +#endif
75588 +
75589 + }
75590 if (err)
75591 return NULL;
75592 khugepaged_enter_vma_merge(area);
75593 @@ -968,16 +1049,13 @@ none:
75594 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
75595 struct file *file, long pages)
75596 {
75597 - const unsigned long stack_flags
75598 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
75599 -
75600 mm->total_vm += pages;
75601
75602 if (file) {
75603 mm->shared_vm += pages;
75604 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
75605 mm->exec_vm += pages;
75606 - } else if (flags & stack_flags)
75607 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
75608 mm->stack_vm += pages;
75609 }
75610 #endif /* CONFIG_PROC_FS */
75611 @@ -1013,7 +1091,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75612 * (the exception is when the underlying filesystem is noexec
75613 * mounted, in which case we dont add PROT_EXEC.)
75614 */
75615 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
75616 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
75617 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
75618 prot |= PROT_EXEC;
75619
75620 @@ -1039,7 +1117,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75621 /* Obtain the address to map to. we verify (or select) it and ensure
75622 * that it represents a valid section of the address space.
75623 */
75624 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
75625 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
75626 if (addr & ~PAGE_MASK)
75627 return addr;
75628
75629 @@ -1050,6 +1128,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75630 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
75631 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
75632
75633 +#ifdef CONFIG_PAX_MPROTECT
75634 + if (mm->pax_flags & MF_PAX_MPROTECT) {
75635 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
75636 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
75637 + gr_log_rwxmmap(file);
75638 +
75639 +#ifdef CONFIG_PAX_EMUPLT
75640 + vm_flags &= ~VM_EXEC;
75641 +#else
75642 + return -EPERM;
75643 +#endif
75644 +
75645 + }
75646 +
75647 + if (!(vm_flags & VM_EXEC))
75648 + vm_flags &= ~VM_MAYEXEC;
75649 +#else
75650 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
75651 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
75652 +#endif
75653 + else
75654 + vm_flags &= ~VM_MAYWRITE;
75655 + }
75656 +#endif
75657 +
75658 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75659 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
75660 + vm_flags &= ~VM_PAGEEXEC;
75661 +#endif
75662 +
75663 if (flags & MAP_LOCKED)
75664 if (!can_do_mlock())
75665 return -EPERM;
75666 @@ -1061,6 +1169,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75667 locked += mm->locked_vm;
75668 lock_limit = rlimit(RLIMIT_MEMLOCK);
75669 lock_limit >>= PAGE_SHIFT;
75670 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
75671 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
75672 return -EAGAIN;
75673 }
75674 @@ -1127,6 +1236,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75675 }
75676 }
75677
75678 + if (!gr_acl_handle_mmap(file, prot))
75679 + return -EACCES;
75680 +
75681 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
75682 }
75683
75684 @@ -1203,7 +1315,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
75685 vm_flags_t vm_flags = vma->vm_flags;
75686
75687 /* If it was private or non-writable, the write bit is already clear */
75688 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
75689 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
75690 return 0;
75691
75692 /* The backer wishes to know when pages are first written to? */
75693 @@ -1252,13 +1364,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
75694 unsigned long charged = 0;
75695 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
75696
75697 +#ifdef CONFIG_PAX_SEGMEXEC
75698 + struct vm_area_struct *vma_m = NULL;
75699 +#endif
75700 +
75701 + /*
75702 + * mm->mmap_sem is required to protect against another thread
75703 + * changing the mappings in case we sleep.
75704 + */
75705 + verify_mm_writelocked(mm);
75706 +
75707 /* Clear old maps */
75708 error = -ENOMEM;
75709 -munmap_back:
75710 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
75711 if (do_munmap(mm, addr, len))
75712 return -ENOMEM;
75713 - goto munmap_back;
75714 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
75715 }
75716
75717 /* Check against address space limit. */
75718 @@ -1307,6 +1428,16 @@ munmap_back:
75719 goto unacct_error;
75720 }
75721
75722 +#ifdef CONFIG_PAX_SEGMEXEC
75723 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
75724 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
75725 + if (!vma_m) {
75726 + error = -ENOMEM;
75727 + goto free_vma;
75728 + }
75729 + }
75730 +#endif
75731 +
75732 vma->vm_mm = mm;
75733 vma->vm_start = addr;
75734 vma->vm_end = addr + len;
75735 @@ -1331,6 +1462,13 @@ munmap_back:
75736 if (error)
75737 goto unmap_and_free_vma;
75738
75739 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75740 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
75741 + vma->vm_flags |= VM_PAGEEXEC;
75742 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
75743 + }
75744 +#endif
75745 +
75746 /* Can addr have changed??
75747 *
75748 * Answer: Yes, several device drivers can do it in their
75749 @@ -1365,6 +1503,11 @@ munmap_back:
75750 vma_link(mm, vma, prev, rb_link, rb_parent);
75751 file = vma->vm_file;
75752
75753 +#ifdef CONFIG_PAX_SEGMEXEC
75754 + if (vma_m)
75755 + BUG_ON(pax_mirror_vma(vma_m, vma));
75756 +#endif
75757 +
75758 /* Once vma denies write, undo our temporary denial count */
75759 if (correct_wcount)
75760 atomic_inc(&inode->i_writecount);
75761 @@ -1372,6 +1515,7 @@ out:
75762 perf_event_mmap(vma);
75763
75764 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
75765 + track_exec_limit(mm, addr, addr + len, vm_flags);
75766 if (vm_flags & VM_LOCKED) {
75767 if (!mlock_vma_pages_range(vma, addr, addr + len))
75768 mm->locked_vm += (len >> PAGE_SHIFT);
75769 @@ -1393,6 +1537,12 @@ unmap_and_free_vma:
75770 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
75771 charged = 0;
75772 free_vma:
75773 +
75774 +#ifdef CONFIG_PAX_SEGMEXEC
75775 + if (vma_m)
75776 + kmem_cache_free(vm_area_cachep, vma_m);
75777 +#endif
75778 +
75779 kmem_cache_free(vm_area_cachep, vma);
75780 unacct_error:
75781 if (charged)
75782 @@ -1400,6 +1550,62 @@ unacct_error:
75783 return error;
75784 }
75785
75786 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
75787 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
75788 +{
75789 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
75790 + return (random32() & 0xFF) << PAGE_SHIFT;
75791 +
75792 + return 0;
75793 +}
75794 +#endif
75795 +
75796 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
75797 +{
75798 + if (!vma) {
75799 +#ifdef CONFIG_STACK_GROWSUP
75800 + if (addr > sysctl_heap_stack_gap)
75801 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
75802 + else
75803 + vma = find_vma(current->mm, 0);
75804 + if (vma && (vma->vm_flags & VM_GROWSUP))
75805 + return false;
75806 +#endif
75807 + return true;
75808 + }
75809 +
75810 + if (addr + len > vma->vm_start)
75811 + return false;
75812 +
75813 + if (vma->vm_flags & VM_GROWSDOWN)
75814 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
75815 +#ifdef CONFIG_STACK_GROWSUP
75816 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
75817 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
75818 +#endif
75819 + else if (offset)
75820 + return offset <= vma->vm_start - addr - len;
75821 +
75822 + return true;
75823 +}
75824 +
75825 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
75826 +{
75827 + if (vma->vm_start < len)
75828 + return -ENOMEM;
75829 +
75830 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
75831 + if (offset <= vma->vm_start - len)
75832 + return vma->vm_start - len - offset;
75833 + else
75834 + return -ENOMEM;
75835 + }
75836 +
75837 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
75838 + return vma->vm_start - len - sysctl_heap_stack_gap;
75839 + return -ENOMEM;
75840 +}
75841 +
75842 /* Get an address range which is currently unmapped.
75843 * For shmat() with addr=0.
75844 *
75845 @@ -1419,6 +1625,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
75846 struct mm_struct *mm = current->mm;
75847 struct vm_area_struct *vma;
75848 unsigned long start_addr;
75849 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
75850
75851 if (len > TASK_SIZE)
75852 return -ENOMEM;
75853 @@ -1426,18 +1633,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
75854 if (flags & MAP_FIXED)
75855 return addr;
75856
75857 +#ifdef CONFIG_PAX_RANDMMAP
75858 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
75859 +#endif
75860 +
75861 if (addr) {
75862 addr = PAGE_ALIGN(addr);
75863 - vma = find_vma(mm, addr);
75864 - if (TASK_SIZE - len >= addr &&
75865 - (!vma || addr + len <= vma->vm_start))
75866 - return addr;
75867 + if (TASK_SIZE - len >= addr) {
75868 + vma = find_vma(mm, addr);
75869 + if (check_heap_stack_gap(vma, addr, len, offset))
75870 + return addr;
75871 + }
75872 }
75873 if (len > mm->cached_hole_size) {
75874 - start_addr = addr = mm->free_area_cache;
75875 + start_addr = addr = mm->free_area_cache;
75876 } else {
75877 - start_addr = addr = TASK_UNMAPPED_BASE;
75878 - mm->cached_hole_size = 0;
75879 + start_addr = addr = mm->mmap_base;
75880 + mm->cached_hole_size = 0;
75881 }
75882
75883 full_search:
75884 @@ -1448,34 +1660,40 @@ full_search:
75885 * Start a new search - just in case we missed
75886 * some holes.
75887 */
75888 - if (start_addr != TASK_UNMAPPED_BASE) {
75889 - addr = TASK_UNMAPPED_BASE;
75890 - start_addr = addr;
75891 + if (start_addr != mm->mmap_base) {
75892 + start_addr = addr = mm->mmap_base;
75893 mm->cached_hole_size = 0;
75894 goto full_search;
75895 }
75896 return -ENOMEM;
75897 }
75898 - if (!vma || addr + len <= vma->vm_start) {
75899 - /*
75900 - * Remember the place where we stopped the search:
75901 - */
75902 - mm->free_area_cache = addr + len;
75903 - return addr;
75904 - }
75905 + if (check_heap_stack_gap(vma, addr, len, offset))
75906 + break;
75907 if (addr + mm->cached_hole_size < vma->vm_start)
75908 mm->cached_hole_size = vma->vm_start - addr;
75909 addr = vma->vm_end;
75910 }
75911 +
75912 + /*
75913 + * Remember the place where we stopped the search:
75914 + */
75915 + mm->free_area_cache = addr + len;
75916 + return addr;
75917 }
75918 #endif
75919
75920 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
75921 {
75922 +
75923 +#ifdef CONFIG_PAX_SEGMEXEC
75924 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
75925 + return;
75926 +#endif
75927 +
75928 /*
75929 * Is this a new hole at the lowest possible address?
75930 */
75931 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
75932 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
75933 mm->free_area_cache = addr;
75934 }
75935
75936 @@ -1491,7 +1709,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
75937 {
75938 struct vm_area_struct *vma;
75939 struct mm_struct *mm = current->mm;
75940 - unsigned long addr = addr0, start_addr;
75941 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
75942 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
75943
75944 /* requested length too big for entire address space */
75945 if (len > TASK_SIZE)
75946 @@ -1500,13 +1719,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
75947 if (flags & MAP_FIXED)
75948 return addr;
75949
75950 +#ifdef CONFIG_PAX_RANDMMAP
75951 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
75952 +#endif
75953 +
75954 /* requesting a specific address */
75955 if (addr) {
75956 addr = PAGE_ALIGN(addr);
75957 - vma = find_vma(mm, addr);
75958 - if (TASK_SIZE - len >= addr &&
75959 - (!vma || addr + len <= vma->vm_start))
75960 - return addr;
75961 + if (TASK_SIZE - len >= addr) {
75962 + vma = find_vma(mm, addr);
75963 + if (check_heap_stack_gap(vma, addr, len, offset))
75964 + return addr;
75965 + }
75966 }
75967
75968 /* check if free_area_cache is useful for us */
75969 @@ -1530,7 +1754,7 @@ try_again:
75970 * return with success:
75971 */
75972 vma = find_vma(mm, addr);
75973 - if (!vma || addr+len <= vma->vm_start)
75974 + if (check_heap_stack_gap(vma, addr, len, offset))
75975 /* remember the address as a hint for next time */
75976 return (mm->free_area_cache = addr);
75977
75978 @@ -1539,8 +1763,8 @@ try_again:
75979 mm->cached_hole_size = vma->vm_start - addr;
75980
75981 /* try just below the current vma->vm_start */
75982 - addr = vma->vm_start-len;
75983 - } while (len < vma->vm_start);
75984 + addr = skip_heap_stack_gap(vma, len, offset);
75985 + } while (!IS_ERR_VALUE(addr));
75986
75987 fail:
75988 /*
75989 @@ -1563,13 +1787,21 @@ fail:
75990 * can happen with large stack limits and large mmap()
75991 * allocations.
75992 */
75993 + mm->mmap_base = TASK_UNMAPPED_BASE;
75994 +
75995 +#ifdef CONFIG_PAX_RANDMMAP
75996 + if (mm->pax_flags & MF_PAX_RANDMMAP)
75997 + mm->mmap_base += mm->delta_mmap;
75998 +#endif
75999 +
76000 + mm->free_area_cache = mm->mmap_base;
76001 mm->cached_hole_size = ~0UL;
76002 - mm->free_area_cache = TASK_UNMAPPED_BASE;
76003 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
76004 /*
76005 * Restore the topdown base:
76006 */
76007 - mm->free_area_cache = mm->mmap_base;
76008 + mm->mmap_base = base;
76009 + mm->free_area_cache = base;
76010 mm->cached_hole_size = ~0UL;
76011
76012 return addr;
76013 @@ -1578,6 +1810,12 @@ fail:
76014
76015 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
76016 {
76017 +
76018 +#ifdef CONFIG_PAX_SEGMEXEC
76019 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
76020 + return;
76021 +#endif
76022 +
76023 /*
76024 * Is this a new hole at the highest possible address?
76025 */
76026 @@ -1585,8 +1823,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
76027 mm->free_area_cache = addr;
76028
76029 /* dont allow allocations above current base */
76030 - if (mm->free_area_cache > mm->mmap_base)
76031 + if (mm->free_area_cache > mm->mmap_base) {
76032 mm->free_area_cache = mm->mmap_base;
76033 + mm->cached_hole_size = ~0UL;
76034 + }
76035 }
76036
76037 unsigned long
76038 @@ -1685,6 +1925,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
76039 return vma;
76040 }
76041
76042 +#ifdef CONFIG_PAX_SEGMEXEC
76043 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
76044 +{
76045 + struct vm_area_struct *vma_m;
76046 +
76047 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
76048 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
76049 + BUG_ON(vma->vm_mirror);
76050 + return NULL;
76051 + }
76052 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
76053 + vma_m = vma->vm_mirror;
76054 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
76055 + BUG_ON(vma->vm_file != vma_m->vm_file);
76056 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
76057 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
76058 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
76059 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
76060 + return vma_m;
76061 +}
76062 +#endif
76063 +
76064 /*
76065 * Verify that the stack growth is acceptable and
76066 * update accounting. This is shared with both the
76067 @@ -1701,6 +1963,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
76068 return -ENOMEM;
76069
76070 /* Stack limit test */
76071 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
76072 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
76073 return -ENOMEM;
76074
76075 @@ -1711,6 +1974,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
76076 locked = mm->locked_vm + grow;
76077 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
76078 limit >>= PAGE_SHIFT;
76079 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
76080 if (locked > limit && !capable(CAP_IPC_LOCK))
76081 return -ENOMEM;
76082 }
76083 @@ -1740,37 +2004,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
76084 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
76085 * vma is the last one with address > vma->vm_end. Have to extend vma.
76086 */
76087 +#ifndef CONFIG_IA64
76088 +static
76089 +#endif
76090 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
76091 {
76092 int error;
76093 + bool locknext;
76094
76095 if (!(vma->vm_flags & VM_GROWSUP))
76096 return -EFAULT;
76097
76098 + /* Also guard against wrapping around to address 0. */
76099 + if (address < PAGE_ALIGN(address+1))
76100 + address = PAGE_ALIGN(address+1);
76101 + else
76102 + return -ENOMEM;
76103 +
76104 /*
76105 * We must make sure the anon_vma is allocated
76106 * so that the anon_vma locking is not a noop.
76107 */
76108 if (unlikely(anon_vma_prepare(vma)))
76109 return -ENOMEM;
76110 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
76111 + if (locknext && anon_vma_prepare(vma->vm_next))
76112 + return -ENOMEM;
76113 vma_lock_anon_vma(vma);
76114 + if (locknext)
76115 + vma_lock_anon_vma(vma->vm_next);
76116
76117 /*
76118 * vma->vm_start/vm_end cannot change under us because the caller
76119 * is required to hold the mmap_sem in read mode. We need the
76120 - * anon_vma lock to serialize against concurrent expand_stacks.
76121 - * Also guard against wrapping around to address 0.
76122 + * anon_vma locks to serialize against concurrent expand_stacks
76123 + * and expand_upwards.
76124 */
76125 - if (address < PAGE_ALIGN(address+4))
76126 - address = PAGE_ALIGN(address+4);
76127 - else {
76128 - vma_unlock_anon_vma(vma);
76129 - return -ENOMEM;
76130 - }
76131 error = 0;
76132
76133 /* Somebody else might have raced and expanded it already */
76134 - if (address > vma->vm_end) {
76135 + 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)
76136 + error = -ENOMEM;
76137 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
76138 unsigned long size, grow;
76139
76140 size = address - vma->vm_start;
76141 @@ -1787,6 +2062,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
76142 }
76143 }
76144 }
76145 + if (locknext)
76146 + vma_unlock_anon_vma(vma->vm_next);
76147 vma_unlock_anon_vma(vma);
76148 khugepaged_enter_vma_merge(vma);
76149 validate_mm(vma->vm_mm);
76150 @@ -1801,6 +2078,8 @@ int expand_downwards(struct vm_area_struct *vma,
76151 unsigned long address)
76152 {
76153 int error;
76154 + bool lockprev = false;
76155 + struct vm_area_struct *prev;
76156
76157 /*
76158 * We must make sure the anon_vma is allocated
76159 @@ -1814,6 +2093,15 @@ int expand_downwards(struct vm_area_struct *vma,
76160 if (error)
76161 return error;
76162
76163 + prev = vma->vm_prev;
76164 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
76165 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
76166 +#endif
76167 + if (lockprev && anon_vma_prepare(prev))
76168 + return -ENOMEM;
76169 + if (lockprev)
76170 + vma_lock_anon_vma(prev);
76171 +
76172 vma_lock_anon_vma(vma);
76173
76174 /*
76175 @@ -1823,9 +2111,17 @@ int expand_downwards(struct vm_area_struct *vma,
76176 */
76177
76178 /* Somebody else might have raced and expanded it already */
76179 - if (address < vma->vm_start) {
76180 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
76181 + error = -ENOMEM;
76182 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
76183 unsigned long size, grow;
76184
76185 +#ifdef CONFIG_PAX_SEGMEXEC
76186 + struct vm_area_struct *vma_m;
76187 +
76188 + vma_m = pax_find_mirror_vma(vma);
76189 +#endif
76190 +
76191 size = vma->vm_end - address;
76192 grow = (vma->vm_start - address) >> PAGE_SHIFT;
76193
76194 @@ -1837,6 +2133,17 @@ int expand_downwards(struct vm_area_struct *vma,
76195 vma->vm_start = address;
76196 vma->vm_pgoff -= grow;
76197 anon_vma_interval_tree_post_update_vma(vma);
76198 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
76199 +
76200 +#ifdef CONFIG_PAX_SEGMEXEC
76201 + if (vma_m) {
76202 + anon_vma_interval_tree_pre_update_vma(vma_m);
76203 + vma_m->vm_start -= grow << PAGE_SHIFT;
76204 + vma_m->vm_pgoff -= grow;
76205 + anon_vma_interval_tree_post_update_vma(vma_m);
76206 + }
76207 +#endif
76208 +
76209 perf_event_mmap(vma);
76210 }
76211 }
76212 @@ -1914,6 +2221,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
76213 do {
76214 long nrpages = vma_pages(vma);
76215
76216 +#ifdef CONFIG_PAX_SEGMEXEC
76217 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
76218 + vma = remove_vma(vma);
76219 + continue;
76220 + }
76221 +#endif
76222 +
76223 if (vma->vm_flags & VM_ACCOUNT)
76224 nr_accounted += nrpages;
76225 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
76226 @@ -1959,6 +2273,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
76227 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
76228 vma->vm_prev = NULL;
76229 do {
76230 +
76231 +#ifdef CONFIG_PAX_SEGMEXEC
76232 + if (vma->vm_mirror) {
76233 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
76234 + vma->vm_mirror->vm_mirror = NULL;
76235 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
76236 + vma->vm_mirror = NULL;
76237 + }
76238 +#endif
76239 +
76240 rb_erase(&vma->vm_rb, &mm->mm_rb);
76241 mm->map_count--;
76242 tail_vma = vma;
76243 @@ -1987,14 +2311,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76244 struct vm_area_struct *new;
76245 int err = -ENOMEM;
76246
76247 +#ifdef CONFIG_PAX_SEGMEXEC
76248 + struct vm_area_struct *vma_m, *new_m = NULL;
76249 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
76250 +#endif
76251 +
76252 if (is_vm_hugetlb_page(vma) && (addr &
76253 ~(huge_page_mask(hstate_vma(vma)))))
76254 return -EINVAL;
76255
76256 +#ifdef CONFIG_PAX_SEGMEXEC
76257 + vma_m = pax_find_mirror_vma(vma);
76258 +#endif
76259 +
76260 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
76261 if (!new)
76262 goto out_err;
76263
76264 +#ifdef CONFIG_PAX_SEGMEXEC
76265 + if (vma_m) {
76266 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
76267 + if (!new_m) {
76268 + kmem_cache_free(vm_area_cachep, new);
76269 + goto out_err;
76270 + }
76271 + }
76272 +#endif
76273 +
76274 /* most fields are the same, copy all, and then fixup */
76275 *new = *vma;
76276
76277 @@ -2007,6 +2350,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76278 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
76279 }
76280
76281 +#ifdef CONFIG_PAX_SEGMEXEC
76282 + if (vma_m) {
76283 + *new_m = *vma_m;
76284 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
76285 + new_m->vm_mirror = new;
76286 + new->vm_mirror = new_m;
76287 +
76288 + if (new_below)
76289 + new_m->vm_end = addr_m;
76290 + else {
76291 + new_m->vm_start = addr_m;
76292 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
76293 + }
76294 + }
76295 +#endif
76296 +
76297 pol = mpol_dup(vma_policy(vma));
76298 if (IS_ERR(pol)) {
76299 err = PTR_ERR(pol);
76300 @@ -2029,6 +2388,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76301 else
76302 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
76303
76304 +#ifdef CONFIG_PAX_SEGMEXEC
76305 + if (!err && vma_m) {
76306 + if (anon_vma_clone(new_m, vma_m))
76307 + goto out_free_mpol;
76308 +
76309 + mpol_get(pol);
76310 + vma_set_policy(new_m, pol);
76311 +
76312 + if (new_m->vm_file)
76313 + get_file(new_m->vm_file);
76314 +
76315 + if (new_m->vm_ops && new_m->vm_ops->open)
76316 + new_m->vm_ops->open(new_m);
76317 +
76318 + if (new_below)
76319 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
76320 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
76321 + else
76322 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
76323 +
76324 + if (err) {
76325 + if (new_m->vm_ops && new_m->vm_ops->close)
76326 + new_m->vm_ops->close(new_m);
76327 + if (new_m->vm_file)
76328 + fput(new_m->vm_file);
76329 + mpol_put(pol);
76330 + }
76331 + }
76332 +#endif
76333 +
76334 /* Success. */
76335 if (!err)
76336 return 0;
76337 @@ -2038,10 +2427,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76338 new->vm_ops->close(new);
76339 if (new->vm_file)
76340 fput(new->vm_file);
76341 - unlink_anon_vmas(new);
76342 out_free_mpol:
76343 mpol_put(pol);
76344 out_free_vma:
76345 +
76346 +#ifdef CONFIG_PAX_SEGMEXEC
76347 + if (new_m) {
76348 + unlink_anon_vmas(new_m);
76349 + kmem_cache_free(vm_area_cachep, new_m);
76350 + }
76351 +#endif
76352 +
76353 + unlink_anon_vmas(new);
76354 kmem_cache_free(vm_area_cachep, new);
76355 out_err:
76356 return err;
76357 @@ -2054,6 +2451,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76358 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
76359 unsigned long addr, int new_below)
76360 {
76361 +
76362 +#ifdef CONFIG_PAX_SEGMEXEC
76363 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
76364 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
76365 + if (mm->map_count >= sysctl_max_map_count-1)
76366 + return -ENOMEM;
76367 + } else
76368 +#endif
76369 +
76370 if (mm->map_count >= sysctl_max_map_count)
76371 return -ENOMEM;
76372
76373 @@ -2065,11 +2471,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
76374 * work. This now handles partial unmappings.
76375 * Jeremy Fitzhardinge <jeremy@goop.org>
76376 */
76377 +#ifdef CONFIG_PAX_SEGMEXEC
76378 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
76379 {
76380 + int ret = __do_munmap(mm, start, len);
76381 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
76382 + return ret;
76383 +
76384 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
76385 +}
76386 +
76387 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
76388 +#else
76389 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
76390 +#endif
76391 +{
76392 unsigned long end;
76393 struct vm_area_struct *vma, *prev, *last;
76394
76395 + /*
76396 + * mm->mmap_sem is required to protect against another thread
76397 + * changing the mappings in case we sleep.
76398 + */
76399 + verify_mm_writelocked(mm);
76400 +
76401 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
76402 return -EINVAL;
76403
76404 @@ -2144,6 +2569,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
76405 /* Fix up all other VM information */
76406 remove_vma_list(mm, vma);
76407
76408 + track_exec_limit(mm, start, end, 0UL);
76409 +
76410 return 0;
76411 }
76412
76413 @@ -2152,6 +2579,13 @@ int vm_munmap(unsigned long start, size_t len)
76414 int ret;
76415 struct mm_struct *mm = current->mm;
76416
76417 +
76418 +#ifdef CONFIG_PAX_SEGMEXEC
76419 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
76420 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
76421 + return -EINVAL;
76422 +#endif
76423 +
76424 down_write(&mm->mmap_sem);
76425 ret = do_munmap(mm, start, len);
76426 up_write(&mm->mmap_sem);
76427 @@ -2165,16 +2599,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
76428 return vm_munmap(addr, len);
76429 }
76430
76431 -static inline void verify_mm_writelocked(struct mm_struct *mm)
76432 -{
76433 -#ifdef CONFIG_DEBUG_VM
76434 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
76435 - WARN_ON(1);
76436 - up_read(&mm->mmap_sem);
76437 - }
76438 -#endif
76439 -}
76440 -
76441 /*
76442 * this is really a simplified "do_mmap". it only handles
76443 * anonymous maps. eventually we may be able to do some
76444 @@ -2188,6 +2612,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76445 struct rb_node ** rb_link, * rb_parent;
76446 pgoff_t pgoff = addr >> PAGE_SHIFT;
76447 int error;
76448 + unsigned long charged;
76449
76450 len = PAGE_ALIGN(len);
76451 if (!len)
76452 @@ -2195,16 +2620,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76453
76454 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
76455
76456 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
76457 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
76458 + flags &= ~VM_EXEC;
76459 +
76460 +#ifdef CONFIG_PAX_MPROTECT
76461 + if (mm->pax_flags & MF_PAX_MPROTECT)
76462 + flags &= ~VM_MAYEXEC;
76463 +#endif
76464 +
76465 + }
76466 +#endif
76467 +
76468 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
76469 if (error & ~PAGE_MASK)
76470 return error;
76471
76472 + charged = len >> PAGE_SHIFT;
76473 +
76474 /*
76475 * mlock MCL_FUTURE?
76476 */
76477 if (mm->def_flags & VM_LOCKED) {
76478 unsigned long locked, lock_limit;
76479 - locked = len >> PAGE_SHIFT;
76480 + locked = charged;
76481 locked += mm->locked_vm;
76482 lock_limit = rlimit(RLIMIT_MEMLOCK);
76483 lock_limit >>= PAGE_SHIFT;
76484 @@ -2221,21 +2660,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76485 /*
76486 * Clear old maps. this also does some error checking for us
76487 */
76488 - munmap_back:
76489 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
76490 if (do_munmap(mm, addr, len))
76491 return -ENOMEM;
76492 - goto munmap_back;
76493 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
76494 }
76495
76496 /* Check against address space limits *after* clearing old maps... */
76497 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
76498 + if (!may_expand_vm(mm, charged))
76499 return -ENOMEM;
76500
76501 if (mm->map_count > sysctl_max_map_count)
76502 return -ENOMEM;
76503
76504 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
76505 + if (security_vm_enough_memory_mm(mm, charged))
76506 return -ENOMEM;
76507
76508 /* Can we just expand an old private anonymous mapping? */
76509 @@ -2249,7 +2687,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76510 */
76511 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76512 if (!vma) {
76513 - vm_unacct_memory(len >> PAGE_SHIFT);
76514 + vm_unacct_memory(charged);
76515 return -ENOMEM;
76516 }
76517
76518 @@ -2263,11 +2701,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76519 vma_link(mm, vma, prev, rb_link, rb_parent);
76520 out:
76521 perf_event_mmap(vma);
76522 - mm->total_vm += len >> PAGE_SHIFT;
76523 + mm->total_vm += charged;
76524 if (flags & VM_LOCKED) {
76525 if (!mlock_vma_pages_range(vma, addr, addr + len))
76526 - mm->locked_vm += (len >> PAGE_SHIFT);
76527 + mm->locked_vm += charged;
76528 }
76529 + track_exec_limit(mm, addr, addr + len, flags);
76530 return addr;
76531 }
76532
76533 @@ -2325,6 +2764,7 @@ void exit_mmap(struct mm_struct *mm)
76534 while (vma) {
76535 if (vma->vm_flags & VM_ACCOUNT)
76536 nr_accounted += vma_pages(vma);
76537 + vma->vm_mirror = NULL;
76538 vma = remove_vma(vma);
76539 }
76540 vm_unacct_memory(nr_accounted);
76541 @@ -2341,6 +2781,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
76542 struct vm_area_struct *prev;
76543 struct rb_node **rb_link, *rb_parent;
76544
76545 +#ifdef CONFIG_PAX_SEGMEXEC
76546 + struct vm_area_struct *vma_m = NULL;
76547 +#endif
76548 +
76549 + if (security_mmap_addr(vma->vm_start))
76550 + return -EPERM;
76551 +
76552 /*
76553 * The vm_pgoff of a purely anonymous vma should be irrelevant
76554 * until its first write fault, when page's anon_vma and index
76555 @@ -2364,7 +2811,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
76556 security_vm_enough_memory_mm(mm, vma_pages(vma)))
76557 return -ENOMEM;
76558
76559 +#ifdef CONFIG_PAX_SEGMEXEC
76560 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
76561 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76562 + if (!vma_m)
76563 + return -ENOMEM;
76564 + }
76565 +#endif
76566 +
76567 vma_link(mm, vma, prev, rb_link, rb_parent);
76568 +
76569 +#ifdef CONFIG_PAX_SEGMEXEC
76570 + if (vma_m)
76571 + BUG_ON(pax_mirror_vma(vma_m, vma));
76572 +#endif
76573 +
76574 return 0;
76575 }
76576
76577 @@ -2384,6 +2845,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
76578 struct mempolicy *pol;
76579 bool faulted_in_anon_vma = true;
76580
76581 + BUG_ON(vma->vm_mirror);
76582 +
76583 /*
76584 * If anonymous vma has not yet been faulted, update new pgoff
76585 * to match new location, to increase its chance of merging.
76586 @@ -2450,6 +2913,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
76587 return NULL;
76588 }
76589
76590 +#ifdef CONFIG_PAX_SEGMEXEC
76591 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
76592 +{
76593 + struct vm_area_struct *prev_m;
76594 + struct rb_node **rb_link_m, *rb_parent_m;
76595 + struct mempolicy *pol_m;
76596 +
76597 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
76598 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
76599 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
76600 + *vma_m = *vma;
76601 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
76602 + if (anon_vma_clone(vma_m, vma))
76603 + return -ENOMEM;
76604 + pol_m = vma_policy(vma_m);
76605 + mpol_get(pol_m);
76606 + vma_set_policy(vma_m, pol_m);
76607 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
76608 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
76609 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
76610 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
76611 + if (vma_m->vm_file)
76612 + get_file(vma_m->vm_file);
76613 + if (vma_m->vm_ops && vma_m->vm_ops->open)
76614 + vma_m->vm_ops->open(vma_m);
76615 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
76616 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
76617 + vma_m->vm_mirror = vma;
76618 + vma->vm_mirror = vma_m;
76619 + return 0;
76620 +}
76621 +#endif
76622 +
76623 /*
76624 * Return true if the calling process may expand its vm space by the passed
76625 * number of pages
76626 @@ -2461,6 +2957,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
76627
76628 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
76629
76630 +#ifdef CONFIG_PAX_RANDMMAP
76631 + if (mm->pax_flags & MF_PAX_RANDMMAP)
76632 + cur -= mm->brk_gap;
76633 +#endif
76634 +
76635 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
76636 if (cur + npages > lim)
76637 return 0;
76638 return 1;
76639 @@ -2531,6 +3033,22 @@ int install_special_mapping(struct mm_struct *mm,
76640 vma->vm_start = addr;
76641 vma->vm_end = addr + len;
76642
76643 +#ifdef CONFIG_PAX_MPROTECT
76644 + if (mm->pax_flags & MF_PAX_MPROTECT) {
76645 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
76646 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
76647 + return -EPERM;
76648 + if (!(vm_flags & VM_EXEC))
76649 + vm_flags &= ~VM_MAYEXEC;
76650 +#else
76651 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
76652 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
76653 +#endif
76654 + else
76655 + vm_flags &= ~VM_MAYWRITE;
76656 + }
76657 +#endif
76658 +
76659 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
76660 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
76661
76662 diff --git a/mm/mprotect.c b/mm/mprotect.c
76663 index a409926..8b32e6d 100644
76664 --- a/mm/mprotect.c
76665 +++ b/mm/mprotect.c
76666 @@ -23,10 +23,17 @@
76667 #include <linux/mmu_notifier.h>
76668 #include <linux/migrate.h>
76669 #include <linux/perf_event.h>
76670 +
76671 +#ifdef CONFIG_PAX_MPROTECT
76672 +#include <linux/elf.h>
76673 +#include <linux/binfmts.h>
76674 +#endif
76675 +
76676 #include <asm/uaccess.h>
76677 #include <asm/pgtable.h>
76678 #include <asm/cacheflush.h>
76679 #include <asm/tlbflush.h>
76680 +#include <asm/mmu_context.h>
76681
76682 #ifndef pgprot_modify
76683 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
76684 @@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
76685 flush_tlb_range(vma, start, end);
76686 }
76687
76688 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
76689 +/* called while holding the mmap semaphor for writing except stack expansion */
76690 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
76691 +{
76692 + unsigned long oldlimit, newlimit = 0UL;
76693 +
76694 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
76695 + return;
76696 +
76697 + spin_lock(&mm->page_table_lock);
76698 + oldlimit = mm->context.user_cs_limit;
76699 + if ((prot & VM_EXEC) && oldlimit < end)
76700 + /* USER_CS limit moved up */
76701 + newlimit = end;
76702 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
76703 + /* USER_CS limit moved down */
76704 + newlimit = start;
76705 +
76706 + if (newlimit) {
76707 + mm->context.user_cs_limit = newlimit;
76708 +
76709 +#ifdef CONFIG_SMP
76710 + wmb();
76711 + cpus_clear(mm->context.cpu_user_cs_mask);
76712 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
76713 +#endif
76714 +
76715 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
76716 + }
76717 + spin_unlock(&mm->page_table_lock);
76718 + if (newlimit == end) {
76719 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
76720 +
76721 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
76722 + if (is_vm_hugetlb_page(vma))
76723 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
76724 + else
76725 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
76726 + }
76727 +}
76728 +#endif
76729 +
76730 int
76731 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
76732 unsigned long start, unsigned long end, unsigned long newflags)
76733 @@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
76734 int error;
76735 int dirty_accountable = 0;
76736
76737 +#ifdef CONFIG_PAX_SEGMEXEC
76738 + struct vm_area_struct *vma_m = NULL;
76739 + unsigned long start_m, end_m;
76740 +
76741 + start_m = start + SEGMEXEC_TASK_SIZE;
76742 + end_m = end + SEGMEXEC_TASK_SIZE;
76743 +#endif
76744 +
76745 if (newflags == oldflags) {
76746 *pprev = vma;
76747 return 0;
76748 }
76749
76750 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
76751 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
76752 +
76753 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
76754 + return -ENOMEM;
76755 +
76756 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
76757 + return -ENOMEM;
76758 + }
76759 +
76760 /*
76761 * If we make a private mapping writable we increase our commit;
76762 * but (without finer accounting) cannot reduce our commit if we
76763 @@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
76764 }
76765 }
76766
76767 +#ifdef CONFIG_PAX_SEGMEXEC
76768 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
76769 + if (start != vma->vm_start) {
76770 + error = split_vma(mm, vma, start, 1);
76771 + if (error)
76772 + goto fail;
76773 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
76774 + *pprev = (*pprev)->vm_next;
76775 + }
76776 +
76777 + if (end != vma->vm_end) {
76778 + error = split_vma(mm, vma, end, 0);
76779 + if (error)
76780 + goto fail;
76781 + }
76782 +
76783 + if (pax_find_mirror_vma(vma)) {
76784 + error = __do_munmap(mm, start_m, end_m - start_m);
76785 + if (error)
76786 + goto fail;
76787 + } else {
76788 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76789 + if (!vma_m) {
76790 + error = -ENOMEM;
76791 + goto fail;
76792 + }
76793 + vma->vm_flags = newflags;
76794 + error = pax_mirror_vma(vma_m, vma);
76795 + if (error) {
76796 + vma->vm_flags = oldflags;
76797 + goto fail;
76798 + }
76799 + }
76800 + }
76801 +#endif
76802 +
76803 /*
76804 * First try to merge with previous and/or next vma.
76805 */
76806 @@ -204,9 +307,21 @@ success:
76807 * vm_flags and vm_page_prot are protected by the mmap_sem
76808 * held in write mode.
76809 */
76810 +
76811 +#ifdef CONFIG_PAX_SEGMEXEC
76812 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
76813 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
76814 +#endif
76815 +
76816 vma->vm_flags = newflags;
76817 +
76818 +#ifdef CONFIG_PAX_MPROTECT
76819 + if (mm->binfmt && mm->binfmt->handle_mprotect)
76820 + mm->binfmt->handle_mprotect(vma, newflags);
76821 +#endif
76822 +
76823 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
76824 - vm_get_page_prot(newflags));
76825 + vm_get_page_prot(vma->vm_flags));
76826
76827 if (vma_wants_writenotify(vma)) {
76828 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
76829 @@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76830 end = start + len;
76831 if (end <= start)
76832 return -ENOMEM;
76833 +
76834 +#ifdef CONFIG_PAX_SEGMEXEC
76835 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
76836 + if (end > SEGMEXEC_TASK_SIZE)
76837 + return -EINVAL;
76838 + } else
76839 +#endif
76840 +
76841 + if (end > TASK_SIZE)
76842 + return -EINVAL;
76843 +
76844 if (!arch_validate_prot(prot))
76845 return -EINVAL;
76846
76847 @@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76848 /*
76849 * Does the application expect PROT_READ to imply PROT_EXEC:
76850 */
76851 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
76852 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
76853 prot |= PROT_EXEC;
76854
76855 vm_flags = calc_vm_prot_bits(prot);
76856 @@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76857 if (start > vma->vm_start)
76858 prev = vma;
76859
76860 +#ifdef CONFIG_PAX_MPROTECT
76861 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
76862 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
76863 +#endif
76864 +
76865 for (nstart = start ; ; ) {
76866 unsigned long newflags;
76867
76868 @@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76869
76870 /* newflags >> 4 shift VM_MAY% in place of VM_% */
76871 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
76872 + if (prot & (PROT_WRITE | PROT_EXEC))
76873 + gr_log_rwxmprotect(vma->vm_file);
76874 +
76875 + error = -EACCES;
76876 + goto out;
76877 + }
76878 +
76879 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
76880 error = -EACCES;
76881 goto out;
76882 }
76883 @@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76884 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
76885 if (error)
76886 goto out;
76887 +
76888 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
76889 +
76890 nstart = tmp;
76891
76892 if (nstart < prev->vm_end)
76893 diff --git a/mm/mremap.c b/mm/mremap.c
76894 index 1b61c2d..1cc0e3c 100644
76895 --- a/mm/mremap.c
76896 +++ b/mm/mremap.c
76897 @@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
76898 continue;
76899 pte = ptep_get_and_clear(mm, old_addr, old_pte);
76900 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
76901 +
76902 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
76903 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
76904 + pte = pte_exprotect(pte);
76905 +#endif
76906 +
76907 set_pte_at(mm, new_addr, new_pte, pte);
76908 }
76909
76910 @@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
76911 if (is_vm_hugetlb_page(vma))
76912 goto Einval;
76913
76914 +#ifdef CONFIG_PAX_SEGMEXEC
76915 + if (pax_find_mirror_vma(vma))
76916 + goto Einval;
76917 +#endif
76918 +
76919 /* We can't remap across vm area boundaries */
76920 if (old_len > vma->vm_end - addr)
76921 goto Efault;
76922 @@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
76923 unsigned long ret = -EINVAL;
76924 unsigned long charged = 0;
76925 unsigned long map_flags;
76926 + unsigned long pax_task_size = TASK_SIZE;
76927
76928 if (new_addr & ~PAGE_MASK)
76929 goto out;
76930
76931 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
76932 +#ifdef CONFIG_PAX_SEGMEXEC
76933 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
76934 + pax_task_size = SEGMEXEC_TASK_SIZE;
76935 +#endif
76936 +
76937 + pax_task_size -= PAGE_SIZE;
76938 +
76939 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
76940 goto out;
76941
76942 /* Check if the location we're moving into overlaps the
76943 * old location at all, and fail if it does.
76944 */
76945 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
76946 - goto out;
76947 -
76948 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
76949 + if (addr + old_len > new_addr && new_addr + new_len > addr)
76950 goto out;
76951
76952 ret = do_munmap(mm, new_addr, new_len);
76953 @@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76954 struct vm_area_struct *vma;
76955 unsigned long ret = -EINVAL;
76956 unsigned long charged = 0;
76957 + unsigned long pax_task_size = TASK_SIZE;
76958
76959 down_write(&current->mm->mmap_sem);
76960
76961 @@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76962 if (!new_len)
76963 goto out;
76964
76965 +#ifdef CONFIG_PAX_SEGMEXEC
76966 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
76967 + pax_task_size = SEGMEXEC_TASK_SIZE;
76968 +#endif
76969 +
76970 + pax_task_size -= PAGE_SIZE;
76971 +
76972 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
76973 + old_len > pax_task_size || addr > pax_task_size-old_len)
76974 + goto out;
76975 +
76976 if (flags & MREMAP_FIXED) {
76977 if (flags & MREMAP_MAYMOVE)
76978 ret = mremap_to(addr, old_len, new_addr, new_len);
76979 @@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76980 addr + new_len);
76981 }
76982 ret = addr;
76983 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
76984 goto out;
76985 }
76986 }
76987 @@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76988 goto out;
76989 }
76990
76991 + map_flags = vma->vm_flags;
76992 ret = move_vma(vma, addr, old_len, new_len, new_addr);
76993 + if (!(ret & ~PAGE_MASK)) {
76994 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
76995 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
76996 + }
76997 }
76998 out:
76999 if (ret & ~PAGE_MASK)
77000 diff --git a/mm/nommu.c b/mm/nommu.c
77001 index 45131b4..c521665 100644
77002 --- a/mm/nommu.c
77003 +++ b/mm/nommu.c
77004 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
77005 int sysctl_overcommit_ratio = 50; /* default is 50% */
77006 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
77007 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
77008 -int heap_stack_gap = 0;
77009
77010 atomic_long_t mmap_pages_allocated;
77011
77012 @@ -824,15 +823,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
77013 EXPORT_SYMBOL(find_vma);
77014
77015 /*
77016 - * find a VMA
77017 - * - we don't extend stack VMAs under NOMMU conditions
77018 - */
77019 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
77020 -{
77021 - return find_vma(mm, addr);
77022 -}
77023 -
77024 -/*
77025 * expand a stack to a given address
77026 * - not supported under NOMMU conditions
77027 */
77028 @@ -1540,6 +1530,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
77029
77030 /* most fields are the same, copy all, and then fixup */
77031 *new = *vma;
77032 + INIT_LIST_HEAD(&new->anon_vma_chain);
77033 *region = *vma->vm_region;
77034 new->vm_region = region;
77035
77036 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
77037 index ceb4168..d7774f2 100644
77038 --- a/mm/page_alloc.c
77039 +++ b/mm/page_alloc.c
77040 @@ -340,7 +340,7 @@ out:
77041 * This usage means that zero-order pages may not be compound.
77042 */
77043
77044 -static void free_compound_page(struct page *page)
77045 +void free_compound_page(struct page *page)
77046 {
77047 __free_pages_ok(page, compound_order(page));
77048 }
77049 @@ -693,6 +693,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
77050 int i;
77051 int bad = 0;
77052
77053 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
77054 + unsigned long index = 1UL << order;
77055 +#endif
77056 +
77057 trace_mm_page_free(page, order);
77058 kmemcheck_free_shadow(page, order);
77059
77060 @@ -708,6 +712,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
77061 debug_check_no_obj_freed(page_address(page),
77062 PAGE_SIZE << order);
77063 }
77064 +
77065 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
77066 + for (; index; --index)
77067 + sanitize_highpage(page + index - 1);
77068 +#endif
77069 +
77070 arch_free_page(page, order);
77071 kernel_map_pages(page, 1 << order, 0);
77072
77073 @@ -849,8 +859,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
77074 arch_alloc_page(page, order);
77075 kernel_map_pages(page, 1 << order, 1);
77076
77077 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
77078 if (gfp_flags & __GFP_ZERO)
77079 prep_zero_page(page, order, gfp_flags);
77080 +#endif
77081
77082 if (order && (gfp_flags & __GFP_COMP))
77083 prep_compound_page(page, order);
77084 @@ -3684,7 +3696,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
77085 unsigned long pfn;
77086
77087 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
77088 +#ifdef CONFIG_X86_32
77089 + /* boot failures in VMware 8 on 32bit vanilla since
77090 + this change */
77091 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
77092 +#else
77093 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
77094 +#endif
77095 return 1;
77096 }
77097 return 0;
77098 diff --git a/mm/percpu.c b/mm/percpu.c
77099 index ddc5efb..f632d2c 100644
77100 --- a/mm/percpu.c
77101 +++ b/mm/percpu.c
77102 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
77103 static unsigned int pcpu_high_unit_cpu __read_mostly;
77104
77105 /* the address of the first chunk which starts with the kernel static area */
77106 -void *pcpu_base_addr __read_mostly;
77107 +void *pcpu_base_addr __read_only;
77108 EXPORT_SYMBOL_GPL(pcpu_base_addr);
77109
77110 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
77111 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
77112 index 926b466..b23df53 100644
77113 --- a/mm/process_vm_access.c
77114 +++ b/mm/process_vm_access.c
77115 @@ -13,6 +13,7 @@
77116 #include <linux/uio.h>
77117 #include <linux/sched.h>
77118 #include <linux/highmem.h>
77119 +#include <linux/security.h>
77120 #include <linux/ptrace.h>
77121 #include <linux/slab.h>
77122 #include <linux/syscalls.h>
77123 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
77124 size_t iov_l_curr_offset = 0;
77125 ssize_t iov_len;
77126
77127 + return -ENOSYS; // PaX: until properly audited
77128 +
77129 /*
77130 * Work out how many pages of struct pages we're going to need
77131 * when eventually calling get_user_pages
77132 */
77133 for (i = 0; i < riovcnt; i++) {
77134 iov_len = rvec[i].iov_len;
77135 - if (iov_len > 0) {
77136 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
77137 - + iov_len)
77138 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
77139 - / PAGE_SIZE + 1;
77140 - nr_pages = max(nr_pages, nr_pages_iov);
77141 - }
77142 + if (iov_len <= 0)
77143 + continue;
77144 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
77145 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
77146 + nr_pages = max(nr_pages, nr_pages_iov);
77147 }
77148
77149 if (nr_pages == 0)
77150 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
77151 goto free_proc_pages;
77152 }
77153
77154 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
77155 + rc = -EPERM;
77156 + goto put_task_struct;
77157 + }
77158 +
77159 mm = mm_access(task, PTRACE_MODE_ATTACH);
77160 if (!mm || IS_ERR(mm)) {
77161 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
77162 diff --git a/mm/rmap.c b/mm/rmap.c
77163 index 2ee1ef0..2e175ba 100644
77164 --- a/mm/rmap.c
77165 +++ b/mm/rmap.c
77166 @@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
77167 struct anon_vma *anon_vma = vma->anon_vma;
77168 struct anon_vma_chain *avc;
77169
77170 +#ifdef CONFIG_PAX_SEGMEXEC
77171 + struct anon_vma_chain *avc_m = NULL;
77172 +#endif
77173 +
77174 might_sleep();
77175 if (unlikely(!anon_vma)) {
77176 struct mm_struct *mm = vma->vm_mm;
77177 @@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
77178 if (!avc)
77179 goto out_enomem;
77180
77181 +#ifdef CONFIG_PAX_SEGMEXEC
77182 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
77183 + if (!avc_m)
77184 + goto out_enomem_free_avc;
77185 +#endif
77186 +
77187 anon_vma = find_mergeable_anon_vma(vma);
77188 allocated = NULL;
77189 if (!anon_vma) {
77190 @@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
77191 /* page_table_lock to protect against threads */
77192 spin_lock(&mm->page_table_lock);
77193 if (likely(!vma->anon_vma)) {
77194 +
77195 +#ifdef CONFIG_PAX_SEGMEXEC
77196 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
77197 +
77198 + if (vma_m) {
77199 + BUG_ON(vma_m->anon_vma);
77200 + vma_m->anon_vma = anon_vma;
77201 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
77202 + avc_m = NULL;
77203 + }
77204 +#endif
77205 +
77206 vma->anon_vma = anon_vma;
77207 anon_vma_chain_link(vma, avc, anon_vma);
77208 allocated = NULL;
77209 @@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
77210
77211 if (unlikely(allocated))
77212 put_anon_vma(allocated);
77213 +
77214 +#ifdef CONFIG_PAX_SEGMEXEC
77215 + if (unlikely(avc_m))
77216 + anon_vma_chain_free(avc_m);
77217 +#endif
77218 +
77219 if (unlikely(avc))
77220 anon_vma_chain_free(avc);
77221 }
77222 return 0;
77223
77224 out_enomem_free_avc:
77225 +
77226 +#ifdef CONFIG_PAX_SEGMEXEC
77227 + if (avc_m)
77228 + anon_vma_chain_free(avc_m);
77229 +#endif
77230 +
77231 anon_vma_chain_free(avc);
77232 out_enomem:
77233 return -ENOMEM;
77234 @@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
77235 * Attach the anon_vmas from src to dst.
77236 * Returns 0 on success, -ENOMEM on failure.
77237 */
77238 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
77239 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
77240 {
77241 struct anon_vma_chain *avc, *pavc;
77242 struct anon_vma *root = NULL;
77243 @@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
77244 * the corresponding VMA in the parent process is attached to.
77245 * Returns 0 on success, non-zero on failure.
77246 */
77247 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
77248 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
77249 {
77250 struct anon_vma_chain *avc;
77251 struct anon_vma *anon_vma;
77252 diff --git a/mm/shmem.c b/mm/shmem.c
77253 index 50c5b8f..0bc87f7 100644
77254 --- a/mm/shmem.c
77255 +++ b/mm/shmem.c
77256 @@ -31,7 +31,7 @@
77257 #include <linux/export.h>
77258 #include <linux/swap.h>
77259
77260 -static struct vfsmount *shm_mnt;
77261 +struct vfsmount *shm_mnt;
77262
77263 #ifdef CONFIG_SHMEM
77264 /*
77265 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
77266 #define BOGO_DIRENT_SIZE 20
77267
77268 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
77269 -#define SHORT_SYMLINK_LEN 128
77270 +#define SHORT_SYMLINK_LEN 64
77271
77272 /*
77273 * shmem_fallocate and shmem_writepage communicate via inode->i_private
77274 @@ -2112,6 +2112,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
77275 static int shmem_xattr_validate(const char *name)
77276 {
77277 struct { const char *prefix; size_t len; } arr[] = {
77278 +
77279 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
77280 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
77281 +#endif
77282 +
77283 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
77284 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
77285 };
77286 @@ -2167,6 +2172,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
77287 if (err)
77288 return err;
77289
77290 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
77291 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
77292 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
77293 + return -EOPNOTSUPP;
77294 + if (size > 8)
77295 + return -EINVAL;
77296 + }
77297 +#endif
77298 +
77299 return simple_xattr_set(&info->xattrs, name, value, size, flags);
77300 }
77301
77302 @@ -2466,8 +2480,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
77303 int err = -ENOMEM;
77304
77305 /* Round up to L1_CACHE_BYTES to resist false sharing */
77306 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
77307 - L1_CACHE_BYTES), GFP_KERNEL);
77308 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
77309 if (!sbinfo)
77310 return -ENOMEM;
77311
77312 diff --git a/mm/slab.c b/mm/slab.c
77313 index 33d3363..3851c61 100644
77314 --- a/mm/slab.c
77315 +++ b/mm/slab.c
77316 @@ -164,7 +164,7 @@ static bool pfmemalloc_active __read_mostly;
77317
77318 /* Legal flag mask for kmem_cache_create(). */
77319 #if DEBUG
77320 -# define CREATE_MASK (SLAB_RED_ZONE | \
77321 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
77322 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
77323 SLAB_CACHE_DMA | \
77324 SLAB_STORE_USER | \
77325 @@ -172,7 +172,7 @@ static bool pfmemalloc_active __read_mostly;
77326 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
77327 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
77328 #else
77329 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
77330 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
77331 SLAB_CACHE_DMA | \
77332 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
77333 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
77334 @@ -322,7 +322,7 @@ struct kmem_list3 {
77335 * Need this for bootstrapping a per node allocator.
77336 */
77337 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
77338 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
77339 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
77340 #define CACHE_CACHE 0
77341 #define SIZE_AC MAX_NUMNODES
77342 #define SIZE_L3 (2 * MAX_NUMNODES)
77343 @@ -423,10 +423,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
77344 if ((x)->max_freeable < i) \
77345 (x)->max_freeable = i; \
77346 } while (0)
77347 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
77348 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
77349 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
77350 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
77351 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
77352 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
77353 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
77354 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
77355 #else
77356 #define STATS_INC_ACTIVE(x) do { } while (0)
77357 #define STATS_DEC_ACTIVE(x) do { } while (0)
77358 @@ -534,7 +534,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
77359 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
77360 */
77361 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
77362 - const struct slab *slab, void *obj)
77363 + const struct slab *slab, const void *obj)
77364 {
77365 u32 offset = (obj - slab->s_mem);
77366 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
77367 @@ -555,12 +555,13 @@ EXPORT_SYMBOL(malloc_sizes);
77368 struct cache_names {
77369 char *name;
77370 char *name_dma;
77371 + char *name_usercopy;
77372 };
77373
77374 static struct cache_names __initdata cache_names[] = {
77375 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
77376 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
77377 #include <linux/kmalloc_sizes.h>
77378 - {NULL,}
77379 + {NULL}
77380 #undef CACHE
77381 };
77382
77383 @@ -721,6 +722,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
77384 if (unlikely(gfpflags & GFP_DMA))
77385 return csizep->cs_dmacachep;
77386 #endif
77387 +
77388 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77389 + if (unlikely(gfpflags & GFP_USERCOPY))
77390 + return csizep->cs_usercopycachep;
77391 +#endif
77392 +
77393 return csizep->cs_cachep;
77394 }
77395
77396 @@ -1676,7 +1683,7 @@ void __init kmem_cache_init(void)
77397 sizes[INDEX_AC].cs_cachep->size = sizes[INDEX_AC].cs_size;
77398 sizes[INDEX_AC].cs_cachep->object_size = sizes[INDEX_AC].cs_size;
77399 sizes[INDEX_AC].cs_cachep->align = ARCH_KMALLOC_MINALIGN;
77400 - __kmem_cache_create(sizes[INDEX_AC].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
77401 + __kmem_cache_create(sizes[INDEX_AC].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
77402 list_add(&sizes[INDEX_AC].cs_cachep->list, &slab_caches);
77403
77404 if (INDEX_AC != INDEX_L3) {
77405 @@ -1685,7 +1692,7 @@ void __init kmem_cache_init(void)
77406 sizes[INDEX_L3].cs_cachep->size = sizes[INDEX_L3].cs_size;
77407 sizes[INDEX_L3].cs_cachep->object_size = sizes[INDEX_L3].cs_size;
77408 sizes[INDEX_L3].cs_cachep->align = ARCH_KMALLOC_MINALIGN;
77409 - __kmem_cache_create(sizes[INDEX_L3].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
77410 + __kmem_cache_create(sizes[INDEX_L3].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
77411 list_add(&sizes[INDEX_L3].cs_cachep->list, &slab_caches);
77412 }
77413
77414 @@ -1705,7 +1712,7 @@ void __init kmem_cache_init(void)
77415 sizes->cs_cachep->size = sizes->cs_size;
77416 sizes->cs_cachep->object_size = sizes->cs_size;
77417 sizes->cs_cachep->align = ARCH_KMALLOC_MINALIGN;
77418 - __kmem_cache_create(sizes->cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
77419 + __kmem_cache_create(sizes->cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
77420 list_add(&sizes->cs_cachep->list, &slab_caches);
77421 }
77422 #ifdef CONFIG_ZONE_DMA
77423 @@ -1718,6 +1725,17 @@ void __init kmem_cache_init(void)
77424 ARCH_KMALLOC_FLAGS|SLAB_CACHE_DMA| SLAB_PANIC);
77425 list_add(&sizes->cs_dmacachep->list, &slab_caches);
77426 #endif
77427 +
77428 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77429 + sizes->cs_usercopycachep = kmem_cache_zalloc(kmem_cache, GFP_NOWAIT);
77430 + sizes->cs_usercopycachep->name = names->name_usercopy;
77431 + sizes->cs_usercopycachep->size = sizes->cs_size;
77432 + sizes->cs_usercopycachep->object_size = sizes->cs_size;
77433 + sizes->cs_usercopycachep->align = ARCH_KMALLOC_MINALIGN;
77434 + __kmem_cache_create(sizes->cs_usercopycachep, ARCH_KMALLOC_FLAGS| SLAB_PANIC|SLAB_USERCOPY);
77435 + list_add(&sizes->cs_usercopycachep->list, &slab_caches);
77436 +#endif
77437 +
77438 sizes++;
77439 names++;
77440 }
77441 @@ -4405,10 +4423,10 @@ static int s_show(struct seq_file *m, void *p)
77442 }
77443 /* cpu stats */
77444 {
77445 - unsigned long allochit = atomic_read(&cachep->allochit);
77446 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
77447 - unsigned long freehit = atomic_read(&cachep->freehit);
77448 - unsigned long freemiss = atomic_read(&cachep->freemiss);
77449 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
77450 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
77451 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
77452 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
77453
77454 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
77455 allochit, allocmiss, freehit, freemiss);
77456 @@ -4667,13 +4685,71 @@ static int __init slab_proc_init(void)
77457 {
77458 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
77459 #ifdef CONFIG_DEBUG_SLAB_LEAK
77460 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
77461 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
77462 #endif
77463 return 0;
77464 }
77465 module_init(slab_proc_init);
77466 #endif
77467
77468 +bool is_usercopy_object(const void *ptr)
77469 +{
77470 + struct page *page;
77471 + struct kmem_cache *cachep;
77472 +
77473 + if (ZERO_OR_NULL_PTR(ptr))
77474 + return false;
77475 +
77476 + if (!slab_is_available())
77477 + return false;
77478 +
77479 + if (!virt_addr_valid(ptr))
77480 + return false;
77481 +
77482 + page = virt_to_head_page(ptr);
77483 +
77484 + if (!PageSlab(page))
77485 + return false;
77486 +
77487 + cachep = page->slab_cache;
77488 + return cachep->flags & SLAB_USERCOPY;
77489 +}
77490 +
77491 +#ifdef CONFIG_PAX_USERCOPY
77492 +const char *check_heap_object(const void *ptr, unsigned long n)
77493 +{
77494 + struct page *page;
77495 + struct kmem_cache *cachep;
77496 + struct slab *slabp;
77497 + unsigned int objnr;
77498 + unsigned long offset;
77499 +
77500 + if (ZERO_OR_NULL_PTR(ptr))
77501 + return "<null>";
77502 +
77503 + if (!virt_addr_valid(ptr))
77504 + return NULL;
77505 +
77506 + page = virt_to_head_page(ptr);
77507 +
77508 + if (!PageSlab(page))
77509 + return NULL;
77510 +
77511 + cachep = page->slab_cache;
77512 + if (!(cachep->flags & SLAB_USERCOPY))
77513 + return cachep->name;
77514 +
77515 + slabp = page->slab_page;
77516 + objnr = obj_to_index(cachep, slabp, ptr);
77517 + BUG_ON(objnr >= cachep->num);
77518 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
77519 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
77520 + return NULL;
77521 +
77522 + return cachep->name;
77523 +}
77524 +#endif
77525 +
77526 /**
77527 * ksize - get the actual amount of memory allocated for a given object
77528 * @objp: Pointer to the object
77529 diff --git a/mm/slab_common.c b/mm/slab_common.c
77530 index 069a24e6..226a310 100644
77531 --- a/mm/slab_common.c
77532 +++ b/mm/slab_common.c
77533 @@ -127,7 +127,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size, size_t align
77534 err = __kmem_cache_create(s, flags);
77535 if (!err) {
77536
77537 - s->refcount = 1;
77538 + atomic_set(&s->refcount, 1);
77539 list_add(&s->list, &slab_caches);
77540
77541 } else {
77542 @@ -163,8 +163,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
77543 {
77544 get_online_cpus();
77545 mutex_lock(&slab_mutex);
77546 - s->refcount--;
77547 - if (!s->refcount) {
77548 + if (atomic_dec_and_test(&s->refcount)) {
77549 list_del(&s->list);
77550
77551 if (!__kmem_cache_shutdown(s)) {
77552 diff --git a/mm/slob.c b/mm/slob.c
77553 index 1e921c5..1ce12c2 100644
77554 --- a/mm/slob.c
77555 +++ b/mm/slob.c
77556 @@ -159,7 +159,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
77557 /*
77558 * Return the size of a slob block.
77559 */
77560 -static slobidx_t slob_units(slob_t *s)
77561 +static slobidx_t slob_units(const slob_t *s)
77562 {
77563 if (s->units > 0)
77564 return s->units;
77565 @@ -169,7 +169,7 @@ static slobidx_t slob_units(slob_t *s)
77566 /*
77567 * Return the next free slob block pointer after this one.
77568 */
77569 -static slob_t *slob_next(slob_t *s)
77570 +static slob_t *slob_next(const slob_t *s)
77571 {
77572 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
77573 slobidx_t next;
77574 @@ -184,14 +184,14 @@ static slob_t *slob_next(slob_t *s)
77575 /*
77576 * Returns true if s is the last free block in its page.
77577 */
77578 -static int slob_last(slob_t *s)
77579 +static int slob_last(const slob_t *s)
77580 {
77581 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
77582 }
77583
77584 -static void *slob_new_pages(gfp_t gfp, int order, int node)
77585 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
77586 {
77587 - void *page;
77588 + struct page *page;
77589
77590 #ifdef CONFIG_NUMA
77591 if (node != NUMA_NO_NODE)
77592 @@ -203,14 +203,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
77593 if (!page)
77594 return NULL;
77595
77596 - return page_address(page);
77597 + __SetPageSlab(page);
77598 + return page;
77599 }
77600
77601 -static void slob_free_pages(void *b, int order)
77602 +static void slob_free_pages(struct page *sp, int order)
77603 {
77604 if (current->reclaim_state)
77605 current->reclaim_state->reclaimed_slab += 1 << order;
77606 - free_pages((unsigned long)b, order);
77607 + __ClearPageSlab(sp);
77608 + reset_page_mapcount(sp);
77609 + sp->private = 0;
77610 + __free_pages(sp, order);
77611 }
77612
77613 /*
77614 @@ -315,15 +319,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
77615
77616 /* Not enough space: must allocate a new page */
77617 if (!b) {
77618 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
77619 - if (!b)
77620 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
77621 + if (!sp)
77622 return NULL;
77623 - sp = virt_to_page(b);
77624 - __SetPageSlab(sp);
77625 + b = page_address(sp);
77626
77627 spin_lock_irqsave(&slob_lock, flags);
77628 sp->units = SLOB_UNITS(PAGE_SIZE);
77629 sp->freelist = b;
77630 + sp->private = 0;
77631 INIT_LIST_HEAD(&sp->list);
77632 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
77633 set_slob_page_free(sp, slob_list);
77634 @@ -361,9 +365,7 @@ static void slob_free(void *block, int size)
77635 if (slob_page_free(sp))
77636 clear_slob_page_free(sp);
77637 spin_unlock_irqrestore(&slob_lock, flags);
77638 - __ClearPageSlab(sp);
77639 - reset_page_mapcount(sp);
77640 - slob_free_pages(b, 0);
77641 + slob_free_pages(sp, 0);
77642 return;
77643 }
77644
77645 @@ -426,11 +428,10 @@ out:
77646 */
77647
77648 static __always_inline void *
77649 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77650 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
77651 {
77652 - unsigned int *m;
77653 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77654 - void *ret;
77655 + slob_t *m;
77656 + void *ret = NULL;
77657
77658 gfp &= gfp_allowed_mask;
77659
77660 @@ -444,20 +445,23 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77661
77662 if (!m)
77663 return NULL;
77664 - *m = size;
77665 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
77666 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
77667 + m[0].units = size;
77668 + m[1].units = align;
77669 ret = (void *)m + align;
77670
77671 trace_kmalloc_node(caller, ret,
77672 size, size + align, gfp, node);
77673 } else {
77674 unsigned int order = get_order(size);
77675 + struct page *page;
77676
77677 if (likely(order))
77678 gfp |= __GFP_COMP;
77679 - ret = slob_new_pages(gfp, order, node);
77680 - if (ret) {
77681 - struct page *page;
77682 - page = virt_to_page(ret);
77683 + page = slob_new_pages(gfp, order, node);
77684 + if (page) {
77685 + ret = page_address(page);
77686 page->private = size;
77687 }
77688
77689 @@ -465,7 +469,17 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77690 size, PAGE_SIZE << order, gfp, node);
77691 }
77692
77693 - kmemleak_alloc(ret, size, 1, gfp);
77694 + return ret;
77695 +}
77696 +
77697 +static __always_inline void *
77698 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77699 +{
77700 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77701 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
77702 +
77703 + if (!ZERO_OR_NULL_PTR(ret))
77704 + kmemleak_alloc(ret, size, 1, gfp);
77705 return ret;
77706 }
77707
77708 @@ -501,15 +515,91 @@ void kfree(const void *block)
77709 kmemleak_free(block);
77710
77711 sp = virt_to_page(block);
77712 - if (PageSlab(sp)) {
77713 + VM_BUG_ON(!PageSlab(sp));
77714 + if (!sp->private) {
77715 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77716 - unsigned int *m = (unsigned int *)(block - align);
77717 - slob_free(m, *m + align);
77718 - } else
77719 + slob_t *m = (slob_t *)(block - align);
77720 + slob_free(m, m[0].units + align);
77721 + } else {
77722 + __ClearPageSlab(sp);
77723 + reset_page_mapcount(sp);
77724 + sp->private = 0;
77725 put_page(sp);
77726 + }
77727 }
77728 EXPORT_SYMBOL(kfree);
77729
77730 +bool is_usercopy_object(const void *ptr)
77731 +{
77732 + if (!slab_is_available())
77733 + return false;
77734 +
77735 + // PAX: TODO
77736 +
77737 + return false;
77738 +}
77739 +
77740 +#ifdef CONFIG_PAX_USERCOPY
77741 +const char *check_heap_object(const void *ptr, unsigned long n)
77742 +{
77743 + struct page *page;
77744 + const slob_t *free;
77745 + const void *base;
77746 + unsigned long flags;
77747 +
77748 + if (ZERO_OR_NULL_PTR(ptr))
77749 + return "<null>";
77750 +
77751 + if (!virt_addr_valid(ptr))
77752 + return NULL;
77753 +
77754 + page = virt_to_head_page(ptr);
77755 + if (!PageSlab(page))
77756 + return NULL;
77757 +
77758 + if (page->private) {
77759 + base = page;
77760 + if (base <= ptr && n <= page->private - (ptr - base))
77761 + return NULL;
77762 + return "<slob>";
77763 + }
77764 +
77765 + /* some tricky double walking to find the chunk */
77766 + spin_lock_irqsave(&slob_lock, flags);
77767 + base = (void *)((unsigned long)ptr & PAGE_MASK);
77768 + free = page->freelist;
77769 +
77770 + while (!slob_last(free) && (void *)free <= ptr) {
77771 + base = free + slob_units(free);
77772 + free = slob_next(free);
77773 + }
77774 +
77775 + while (base < (void *)free) {
77776 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
77777 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
77778 + int offset;
77779 +
77780 + if (ptr < base + align)
77781 + break;
77782 +
77783 + offset = ptr - base - align;
77784 + if (offset >= m) {
77785 + base += size;
77786 + continue;
77787 + }
77788 +
77789 + if (n > m - offset)
77790 + break;
77791 +
77792 + spin_unlock_irqrestore(&slob_lock, flags);
77793 + return NULL;
77794 + }
77795 +
77796 + spin_unlock_irqrestore(&slob_lock, flags);
77797 + return "<slob>";
77798 +}
77799 +#endif
77800 +
77801 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
77802 size_t ksize(const void *block)
77803 {
77804 @@ -520,10 +610,11 @@ size_t ksize(const void *block)
77805 return 0;
77806
77807 sp = virt_to_page(block);
77808 - if (PageSlab(sp)) {
77809 + VM_BUG_ON(!PageSlab(sp));
77810 + if (!sp->private) {
77811 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77812 - unsigned int *m = (unsigned int *)(block - align);
77813 - return SLOB_UNITS(*m) * SLOB_UNIT;
77814 + slob_t *m = (slob_t *)(block - align);
77815 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
77816 } else
77817 return sp->private;
77818 }
77819 @@ -550,23 +641,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
77820
77821 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
77822 {
77823 - void *b;
77824 + void *b = NULL;
77825
77826 flags &= gfp_allowed_mask;
77827
77828 lockdep_trace_alloc(flags);
77829
77830 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77831 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
77832 +#else
77833 if (c->size < PAGE_SIZE) {
77834 b = slob_alloc(c->size, flags, c->align, node);
77835 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
77836 SLOB_UNITS(c->size) * SLOB_UNIT,
77837 flags, node);
77838 } else {
77839 - b = slob_new_pages(flags, get_order(c->size), node);
77840 + struct page *sp;
77841 +
77842 + sp = slob_new_pages(flags, get_order(c->size), node);
77843 + if (sp) {
77844 + b = page_address(sp);
77845 + sp->private = c->size;
77846 + }
77847 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
77848 PAGE_SIZE << get_order(c->size),
77849 flags, node);
77850 }
77851 +#endif
77852
77853 if (c->ctor)
77854 c->ctor(b);
77855 @@ -578,10 +679,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
77856
77857 static void __kmem_cache_free(void *b, int size)
77858 {
77859 - if (size < PAGE_SIZE)
77860 + struct page *sp;
77861 +
77862 + sp = virt_to_page(b);
77863 + BUG_ON(!PageSlab(sp));
77864 + if (!sp->private)
77865 slob_free(b, size);
77866 else
77867 - slob_free_pages(b, get_order(size));
77868 + slob_free_pages(sp, get_order(size));
77869 }
77870
77871 static void kmem_rcu_free(struct rcu_head *head)
77872 @@ -594,17 +699,31 @@ static void kmem_rcu_free(struct rcu_head *head)
77873
77874 void kmem_cache_free(struct kmem_cache *c, void *b)
77875 {
77876 + int size = c->size;
77877 +
77878 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77879 + if (size + c->align < PAGE_SIZE) {
77880 + size += c->align;
77881 + b -= c->align;
77882 + }
77883 +#endif
77884 +
77885 kmemleak_free_recursive(b, c->flags);
77886 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
77887 struct slob_rcu *slob_rcu;
77888 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
77889 - slob_rcu->size = c->size;
77890 + slob_rcu = b + (size - sizeof(struct slob_rcu));
77891 + slob_rcu->size = size;
77892 call_rcu(&slob_rcu->head, kmem_rcu_free);
77893 } else {
77894 - __kmem_cache_free(b, c->size);
77895 + __kmem_cache_free(b, size);
77896 }
77897
77898 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77899 + trace_kfree(_RET_IP_, b);
77900 +#else
77901 trace_kmem_cache_free(_RET_IP_, b);
77902 +#endif
77903 +
77904 }
77905 EXPORT_SYMBOL(kmem_cache_free);
77906
77907 diff --git a/mm/slub.c b/mm/slub.c
77908 index 321afab..9595170 100644
77909 --- a/mm/slub.c
77910 +++ b/mm/slub.c
77911 @@ -201,7 +201,7 @@ struct track {
77912
77913 enum track_item { TRACK_ALLOC, TRACK_FREE };
77914
77915 -#ifdef CONFIG_SYSFS
77916 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77917 static int sysfs_slab_add(struct kmem_cache *);
77918 static int sysfs_slab_alias(struct kmem_cache *, const char *);
77919 static void sysfs_slab_remove(struct kmem_cache *);
77920 @@ -521,7 +521,7 @@ static void print_track(const char *s, struct track *t)
77921 if (!t->addr)
77922 return;
77923
77924 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
77925 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
77926 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
77927 #ifdef CONFIG_STACKTRACE
77928 {
77929 @@ -2623,6 +2623,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
77930
77931 page = virt_to_head_page(x);
77932
77933 + BUG_ON(!PageSlab(page));
77934 +
77935 if (kmem_cache_debug(s) && page->slab != s) {
77936 pr_err("kmem_cache_free: Wrong slab cache. %s but object"
77937 " is from %s\n", page->slab->name, s->name);
77938 @@ -2663,7 +2665,7 @@ static int slub_min_objects;
77939 * Merge control. If this is set then no merging of slab caches will occur.
77940 * (Could be removed. This was introduced to pacify the merge skeptics.)
77941 */
77942 -static int slub_nomerge;
77943 +static int slub_nomerge = 1;
77944
77945 /*
77946 * Calculate the order of allocation given an slab object size.
77947 @@ -3225,6 +3227,10 @@ EXPORT_SYMBOL(kmalloc_caches);
77948 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
77949 #endif
77950
77951 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77952 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
77953 +#endif
77954 +
77955 static int __init setup_slub_min_order(char *str)
77956 {
77957 get_option(&str, &slub_min_order);
77958 @@ -3279,7 +3285,7 @@ static struct kmem_cache *__init create_kmalloc_cache(const char *name,
77959 if (kmem_cache_open(s, flags))
77960 goto panic;
77961
77962 - s->refcount = 1;
77963 + atomic_set(&s->refcount, 1);
77964 list_add(&s->list, &slab_caches);
77965 return s;
77966
77967 @@ -3343,6 +3349,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
77968 return kmalloc_dma_caches[index];
77969
77970 #endif
77971 +
77972 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77973 + if (flags & SLAB_USERCOPY)
77974 + return kmalloc_usercopy_caches[index];
77975 +
77976 +#endif
77977 +
77978 return kmalloc_caches[index];
77979 }
77980
77981 @@ -3411,6 +3424,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
77982 EXPORT_SYMBOL(__kmalloc_node);
77983 #endif
77984
77985 +bool is_usercopy_object(const void *ptr)
77986 +{
77987 + struct page *page;
77988 + struct kmem_cache *s;
77989 +
77990 + if (ZERO_OR_NULL_PTR(ptr))
77991 + return false;
77992 +
77993 + if (!slab_is_available())
77994 + return false;
77995 +
77996 + if (!virt_addr_valid(ptr))
77997 + return false;
77998 +
77999 + page = virt_to_head_page(ptr);
78000 +
78001 + if (!PageSlab(page))
78002 + return false;
78003 +
78004 + s = page->slab;
78005 + return s->flags & SLAB_USERCOPY;
78006 +}
78007 +
78008 +#ifdef CONFIG_PAX_USERCOPY
78009 +const char *check_heap_object(const void *ptr, unsigned long n)
78010 +{
78011 + struct page *page;
78012 + struct kmem_cache *s;
78013 + unsigned long offset;
78014 +
78015 + if (ZERO_OR_NULL_PTR(ptr))
78016 + return "<null>";
78017 +
78018 + if (!virt_addr_valid(ptr))
78019 + return NULL;
78020 +
78021 + page = virt_to_head_page(ptr);
78022 +
78023 + if (!PageSlab(page))
78024 + return NULL;
78025 +
78026 + s = page->slab;
78027 + if (!(s->flags & SLAB_USERCOPY))
78028 + return s->name;
78029 +
78030 + offset = (ptr - page_address(page)) % s->size;
78031 + if (offset <= s->object_size && n <= s->object_size - offset)
78032 + return NULL;
78033 +
78034 + return s->name;
78035 +}
78036 +#endif
78037 +
78038 size_t ksize(const void *object)
78039 {
78040 struct page *page;
78041 @@ -3685,7 +3751,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
78042 int node;
78043
78044 list_add(&s->list, &slab_caches);
78045 - s->refcount = -1;
78046 + atomic_set(&s->refcount, -1);
78047
78048 for_each_node_state(node, N_NORMAL_MEMORY) {
78049 struct kmem_cache_node *n = get_node(s, node);
78050 @@ -3808,17 +3874,17 @@ void __init kmem_cache_init(void)
78051
78052 /* Caches that are not of the two-to-the-power-of size */
78053 if (KMALLOC_MIN_SIZE <= 32) {
78054 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
78055 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
78056 caches++;
78057 }
78058
78059 if (KMALLOC_MIN_SIZE <= 64) {
78060 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
78061 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
78062 caches++;
78063 }
78064
78065 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
78066 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
78067 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
78068 caches++;
78069 }
78070
78071 @@ -3860,6 +3926,22 @@ void __init kmem_cache_init(void)
78072 }
78073 }
78074 #endif
78075 +
78076 +#ifdef CONFIG_PAX_USERCOPY_SLABS
78077 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
78078 + struct kmem_cache *s = kmalloc_caches[i];
78079 +
78080 + if (s && s->size) {
78081 + char *name = kasprintf(GFP_NOWAIT,
78082 + "usercopy-kmalloc-%d", s->object_size);
78083 +
78084 + BUG_ON(!name);
78085 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
78086 + s->object_size, SLAB_USERCOPY);
78087 + }
78088 + }
78089 +#endif
78090 +
78091 printk(KERN_INFO
78092 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
78093 " CPUs=%d, Nodes=%d\n",
78094 @@ -3886,7 +3968,7 @@ static int slab_unmergeable(struct kmem_cache *s)
78095 /*
78096 * We may have set a slab to be unmergeable during bootstrap.
78097 */
78098 - if (s->refcount < 0)
78099 + if (atomic_read(&s->refcount) < 0)
78100 return 1;
78101
78102 return 0;
78103 @@ -3940,7 +4022,7 @@ struct kmem_cache *__kmem_cache_alias(const char *name, size_t size,
78104
78105 s = find_mergeable(size, align, flags, name, ctor);
78106 if (s) {
78107 - s->refcount++;
78108 + atomic_inc(&s->refcount);
78109 /*
78110 * Adjust the object sizes so that we clear
78111 * the complete object on kzalloc.
78112 @@ -3949,7 +4031,7 @@ struct kmem_cache *__kmem_cache_alias(const char *name, size_t size,
78113 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
78114
78115 if (sysfs_slab_alias(s, name)) {
78116 - s->refcount--;
78117 + atomic_dec(&s->refcount);
78118 s = NULL;
78119 }
78120 }
78121 @@ -4064,7 +4146,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
78122 }
78123 #endif
78124
78125 -#ifdef CONFIG_SYSFS
78126 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78127 static int count_inuse(struct page *page)
78128 {
78129 return page->inuse;
78130 @@ -4451,12 +4533,12 @@ static void resiliency_test(void)
78131 validate_slab_cache(kmalloc_caches[9]);
78132 }
78133 #else
78134 -#ifdef CONFIG_SYSFS
78135 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78136 static void resiliency_test(void) {};
78137 #endif
78138 #endif
78139
78140 -#ifdef CONFIG_SYSFS
78141 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78142 enum slab_stat_type {
78143 SL_ALL, /* All slabs */
78144 SL_PARTIAL, /* Only partially allocated slabs */
78145 @@ -4700,7 +4782,7 @@ SLAB_ATTR_RO(ctor);
78146
78147 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
78148 {
78149 - return sprintf(buf, "%d\n", s->refcount - 1);
78150 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
78151 }
78152 SLAB_ATTR_RO(aliases);
78153
78154 @@ -5262,6 +5344,7 @@ static char *create_unique_id(struct kmem_cache *s)
78155 return name;
78156 }
78157
78158 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78159 static int sysfs_slab_add(struct kmem_cache *s)
78160 {
78161 int err;
78162 @@ -5324,6 +5407,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
78163 kobject_del(&s->kobj);
78164 kobject_put(&s->kobj);
78165 }
78166 +#endif
78167
78168 /*
78169 * Need to buffer aliases during bootup until sysfs becomes
78170 @@ -5337,6 +5421,7 @@ struct saved_alias {
78171
78172 static struct saved_alias *alias_list;
78173
78174 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78175 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
78176 {
78177 struct saved_alias *al;
78178 @@ -5359,6 +5444,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
78179 alias_list = al;
78180 return 0;
78181 }
78182 +#endif
78183
78184 static int __init slab_sysfs_init(void)
78185 {
78186 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
78187 index 1b7e22a..3fcd4f3 100644
78188 --- a/mm/sparse-vmemmap.c
78189 +++ b/mm/sparse-vmemmap.c
78190 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
78191 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
78192 if (!p)
78193 return NULL;
78194 - pud_populate(&init_mm, pud, p);
78195 + pud_populate_kernel(&init_mm, pud, p);
78196 }
78197 return pud;
78198 }
78199 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
78200 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
78201 if (!p)
78202 return NULL;
78203 - pgd_populate(&init_mm, pgd, p);
78204 + pgd_populate_kernel(&init_mm, pgd, p);
78205 }
78206 return pgd;
78207 }
78208 diff --git a/mm/swap.c b/mm/swap.c
78209 index 6310dc2..3662b3f 100644
78210 --- a/mm/swap.c
78211 +++ b/mm/swap.c
78212 @@ -30,6 +30,7 @@
78213 #include <linux/backing-dev.h>
78214 #include <linux/memcontrol.h>
78215 #include <linux/gfp.h>
78216 +#include <linux/hugetlb.h>
78217
78218 #include "internal.h"
78219
78220 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
78221
78222 __page_cache_release(page);
78223 dtor = get_compound_page_dtor(page);
78224 + if (!PageHuge(page))
78225 + BUG_ON(dtor != free_compound_page);
78226 (*dtor)(page);
78227 }
78228
78229 diff --git a/mm/swapfile.c b/mm/swapfile.c
78230 index f91a255..9dcac21 100644
78231 --- a/mm/swapfile.c
78232 +++ b/mm/swapfile.c
78233 @@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
78234
78235 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
78236 /* Activity counter to indicate that a swapon or swapoff has occurred */
78237 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
78238 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
78239
78240 static inline unsigned char swap_count(unsigned char ent)
78241 {
78242 @@ -1601,7 +1601,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
78243 }
78244 filp_close(swap_file, NULL);
78245 err = 0;
78246 - atomic_inc(&proc_poll_event);
78247 + atomic_inc_unchecked(&proc_poll_event);
78248 wake_up_interruptible(&proc_poll_wait);
78249
78250 out_dput:
78251 @@ -1618,8 +1618,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
78252
78253 poll_wait(file, &proc_poll_wait, wait);
78254
78255 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
78256 - seq->poll_event = atomic_read(&proc_poll_event);
78257 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
78258 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
78259 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
78260 }
78261
78262 @@ -1717,7 +1717,7 @@ static int swaps_open(struct inode *inode, struct file *file)
78263 return ret;
78264
78265 seq = file->private_data;
78266 - seq->poll_event = atomic_read(&proc_poll_event);
78267 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
78268 return 0;
78269 }
78270
78271 @@ -2059,7 +2059,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
78272 (frontswap_map) ? "FS" : "");
78273
78274 mutex_unlock(&swapon_mutex);
78275 - atomic_inc(&proc_poll_event);
78276 + atomic_inc_unchecked(&proc_poll_event);
78277 wake_up_interruptible(&proc_poll_wait);
78278
78279 if (S_ISREG(inode->i_mode))
78280 diff --git a/mm/util.c b/mm/util.c
78281 index dc3036c..b6c7c9d 100644
78282 --- a/mm/util.c
78283 +++ b/mm/util.c
78284 @@ -292,6 +292,12 @@ done:
78285 void arch_pick_mmap_layout(struct mm_struct *mm)
78286 {
78287 mm->mmap_base = TASK_UNMAPPED_BASE;
78288 +
78289 +#ifdef CONFIG_PAX_RANDMMAP
78290 + if (mm->pax_flags & MF_PAX_RANDMMAP)
78291 + mm->mmap_base += mm->delta_mmap;
78292 +#endif
78293 +
78294 mm->get_unmapped_area = arch_get_unmapped_area;
78295 mm->unmap_area = arch_unmap_area;
78296 }
78297 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
78298 index 78e0830..bc6bbd8 100644
78299 --- a/mm/vmalloc.c
78300 +++ b/mm/vmalloc.c
78301 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
78302
78303 pte = pte_offset_kernel(pmd, addr);
78304 do {
78305 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
78306 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
78307 +
78308 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
78309 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
78310 + BUG_ON(!pte_exec(*pte));
78311 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
78312 + continue;
78313 + }
78314 +#endif
78315 +
78316 + {
78317 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
78318 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
78319 + }
78320 } while (pte++, addr += PAGE_SIZE, addr != end);
78321 }
78322
78323 @@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
78324 pte = pte_alloc_kernel(pmd, addr);
78325 if (!pte)
78326 return -ENOMEM;
78327 +
78328 + pax_open_kernel();
78329 do {
78330 struct page *page = pages[*nr];
78331
78332 - if (WARN_ON(!pte_none(*pte)))
78333 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
78334 + if (pgprot_val(prot) & _PAGE_NX)
78335 +#endif
78336 +
78337 + if (!pte_none(*pte)) {
78338 + pax_close_kernel();
78339 + WARN_ON(1);
78340 return -EBUSY;
78341 - if (WARN_ON(!page))
78342 + }
78343 + if (!page) {
78344 + pax_close_kernel();
78345 + WARN_ON(1);
78346 return -ENOMEM;
78347 + }
78348 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
78349 (*nr)++;
78350 } while (pte++, addr += PAGE_SIZE, addr != end);
78351 + pax_close_kernel();
78352 return 0;
78353 }
78354
78355 @@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
78356 pmd_t *pmd;
78357 unsigned long next;
78358
78359 - pmd = pmd_alloc(&init_mm, pud, addr);
78360 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
78361 if (!pmd)
78362 return -ENOMEM;
78363 do {
78364 @@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
78365 pud_t *pud;
78366 unsigned long next;
78367
78368 - pud = pud_alloc(&init_mm, pgd, addr);
78369 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
78370 if (!pud)
78371 return -ENOMEM;
78372 do {
78373 @@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
78374 * and fall back on vmalloc() if that fails. Others
78375 * just put it in the vmalloc space.
78376 */
78377 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
78378 +#ifdef CONFIG_MODULES
78379 +#ifdef MODULES_VADDR
78380 unsigned long addr = (unsigned long)x;
78381 if (addr >= MODULES_VADDR && addr < MODULES_END)
78382 return 1;
78383 #endif
78384 +
78385 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
78386 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
78387 + return 1;
78388 +#endif
78389 +
78390 +#endif
78391 +
78392 return is_vmalloc_addr(x);
78393 }
78394
78395 @@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
78396
78397 if (!pgd_none(*pgd)) {
78398 pud_t *pud = pud_offset(pgd, addr);
78399 +#ifdef CONFIG_X86
78400 + if (!pud_large(*pud))
78401 +#endif
78402 if (!pud_none(*pud)) {
78403 pmd_t *pmd = pmd_offset(pud, addr);
78404 +#ifdef CONFIG_X86
78405 + if (!pmd_large(*pmd))
78406 +#endif
78407 if (!pmd_none(*pmd)) {
78408 pte_t *ptep, pte;
78409
78410 @@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
78411 * Allocate a region of KVA of the specified size and alignment, within the
78412 * vstart and vend.
78413 */
78414 -static struct vmap_area *alloc_vmap_area(unsigned long size,
78415 +static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
78416 unsigned long align,
78417 unsigned long vstart, unsigned long vend,
78418 int node, gfp_t gfp_mask)
78419 @@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
78420 struct vm_struct *area;
78421
78422 BUG_ON(in_interrupt());
78423 +
78424 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
78425 + if (flags & VM_KERNEXEC) {
78426 + if (start != VMALLOC_START || end != VMALLOC_END)
78427 + return NULL;
78428 + start = (unsigned long)MODULES_EXEC_VADDR;
78429 + end = (unsigned long)MODULES_EXEC_END;
78430 + }
78431 +#endif
78432 +
78433 if (flags & VM_IOREMAP) {
78434 int bit = fls(size);
78435
78436 @@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
78437 if (count > totalram_pages)
78438 return NULL;
78439
78440 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
78441 + if (!(pgprot_val(prot) & _PAGE_NX))
78442 + flags |= VM_KERNEXEC;
78443 +#endif
78444 +
78445 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
78446 __builtin_return_address(0));
78447 if (!area)
78448 @@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
78449 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
78450 goto fail;
78451
78452 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
78453 + if (!(pgprot_val(prot) & _PAGE_NX))
78454 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
78455 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
78456 + else
78457 +#endif
78458 +
78459 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
78460 start, end, node, gfp_mask, caller);
78461 if (!area)
78462 @@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
78463 * For tight control over page level allocator and protection flags
78464 * use __vmalloc() instead.
78465 */
78466 -
78467 void *vmalloc_exec(unsigned long size)
78468 {
78469 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
78470 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
78471 -1, __builtin_return_address(0));
78472 }
78473
78474 @@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
78475 unsigned long uaddr = vma->vm_start;
78476 unsigned long usize = vma->vm_end - vma->vm_start;
78477
78478 + BUG_ON(vma->vm_mirror);
78479 +
78480 if ((PAGE_SIZE-1) & (unsigned long)addr)
78481 return -EINVAL;
78482
78483 @@ -2575,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
78484 v->addr, v->addr + v->size, v->size);
78485
78486 if (v->caller)
78487 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78488 + seq_printf(m, " %pK", v->caller);
78489 +#else
78490 seq_printf(m, " %pS", v->caller);
78491 +#endif
78492
78493 if (v->nr_pages)
78494 seq_printf(m, " pages=%d", v->nr_pages);
78495 diff --git a/mm/vmstat.c b/mm/vmstat.c
78496 index c737057..a49753a 100644
78497 --- a/mm/vmstat.c
78498 +++ b/mm/vmstat.c
78499 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
78500 *
78501 * vm_stat contains the global counters
78502 */
78503 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
78504 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
78505 EXPORT_SYMBOL(vm_stat);
78506
78507 #ifdef CONFIG_SMP
78508 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
78509 v = p->vm_stat_diff[i];
78510 p->vm_stat_diff[i] = 0;
78511 local_irq_restore(flags);
78512 - atomic_long_add(v, &zone->vm_stat[i]);
78513 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
78514 global_diff[i] += v;
78515 #ifdef CONFIG_NUMA
78516 /* 3 seconds idle till flush */
78517 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
78518
78519 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
78520 if (global_diff[i])
78521 - atomic_long_add(global_diff[i], &vm_stat[i]);
78522 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
78523 }
78524
78525 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
78526 @@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
78527 if (pset->vm_stat_diff[i]) {
78528 int v = pset->vm_stat_diff[i];
78529 pset->vm_stat_diff[i] = 0;
78530 - atomic_long_add(v, &zone->vm_stat[i]);
78531 - atomic_long_add(v, &vm_stat[i]);
78532 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
78533 + atomic_long_add_unchecked(v, &vm_stat[i]);
78534 }
78535 }
78536 #endif
78537 @@ -1224,10 +1224,20 @@ static int __init setup_vmstat(void)
78538 start_cpu_timer(cpu);
78539 #endif
78540 #ifdef CONFIG_PROC_FS
78541 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
78542 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
78543 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
78544 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
78545 + {
78546 + mode_t gr_mode = S_IRUGO;
78547 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
78548 + gr_mode = S_IRUSR;
78549 +#endif
78550 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
78551 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
78552 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
78553 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
78554 +#else
78555 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
78556 +#endif
78557 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
78558 + }
78559 #endif
78560 return 0;
78561 }
78562 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
78563 index ee07072..593e3fd 100644
78564 --- a/net/8021q/vlan.c
78565 +++ b/net/8021q/vlan.c
78566 @@ -484,7 +484,7 @@ out:
78567 return NOTIFY_DONE;
78568 }
78569
78570 -static struct notifier_block vlan_notifier_block __read_mostly = {
78571 +static struct notifier_block vlan_notifier_block = {
78572 .notifier_call = vlan_device_event,
78573 };
78574
78575 @@ -559,8 +559,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
78576 err = -EPERM;
78577 if (!capable(CAP_NET_ADMIN))
78578 break;
78579 - if ((args.u.name_type >= 0) &&
78580 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
78581 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
78582 struct vlan_net *vn;
78583
78584 vn = net_generic(net, vlan_net_id);
78585 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
78586 index 02efb25..41541a9 100644
78587 --- a/net/9p/trans_fd.c
78588 +++ b/net/9p/trans_fd.c
78589 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
78590 oldfs = get_fs();
78591 set_fs(get_ds());
78592 /* The cast to a user pointer is valid due to the set_fs() */
78593 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
78594 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
78595 set_fs(oldfs);
78596
78597 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
78598 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
78599 index 876fbe8..8bbea9f 100644
78600 --- a/net/atm/atm_misc.c
78601 +++ b/net/atm/atm_misc.c
78602 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
78603 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
78604 return 1;
78605 atm_return(vcc, truesize);
78606 - atomic_inc(&vcc->stats->rx_drop);
78607 + atomic_inc_unchecked(&vcc->stats->rx_drop);
78608 return 0;
78609 }
78610 EXPORT_SYMBOL(atm_charge);
78611 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
78612 }
78613 }
78614 atm_return(vcc, guess);
78615 - atomic_inc(&vcc->stats->rx_drop);
78616 + atomic_inc_unchecked(&vcc->stats->rx_drop);
78617 return NULL;
78618 }
78619 EXPORT_SYMBOL(atm_alloc_charge);
78620 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
78621
78622 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
78623 {
78624 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
78625 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
78626 __SONET_ITEMS
78627 #undef __HANDLE_ITEM
78628 }
78629 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
78630
78631 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
78632 {
78633 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
78634 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
78635 __SONET_ITEMS
78636 #undef __HANDLE_ITEM
78637 }
78638 diff --git a/net/atm/lec.h b/net/atm/lec.h
78639 index a86aff9..3a0d6f6 100644
78640 --- a/net/atm/lec.h
78641 +++ b/net/atm/lec.h
78642 @@ -48,7 +48,7 @@ struct lane2_ops {
78643 const u8 *tlvs, u32 sizeoftlvs);
78644 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
78645 const u8 *tlvs, u32 sizeoftlvs);
78646 -};
78647 +} __no_const;
78648
78649 /*
78650 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
78651 diff --git a/net/atm/proc.c b/net/atm/proc.c
78652 index 0d020de..011c7bb 100644
78653 --- a/net/atm/proc.c
78654 +++ b/net/atm/proc.c
78655 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
78656 const struct k_atm_aal_stats *stats)
78657 {
78658 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
78659 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
78660 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
78661 - atomic_read(&stats->rx_drop));
78662 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
78663 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
78664 + atomic_read_unchecked(&stats->rx_drop));
78665 }
78666
78667 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
78668 diff --git a/net/atm/resources.c b/net/atm/resources.c
78669 index 0447d5d..3cf4728 100644
78670 --- a/net/atm/resources.c
78671 +++ b/net/atm/resources.c
78672 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
78673 static void copy_aal_stats(struct k_atm_aal_stats *from,
78674 struct atm_aal_stats *to)
78675 {
78676 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
78677 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
78678 __AAL_STAT_ITEMS
78679 #undef __HANDLE_ITEM
78680 }
78681 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
78682 static void subtract_aal_stats(struct k_atm_aal_stats *from,
78683 struct atm_aal_stats *to)
78684 {
78685 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
78686 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
78687 __AAL_STAT_ITEMS
78688 #undef __HANDLE_ITEM
78689 }
78690 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
78691 index c6fcc76..1270d14 100644
78692 --- a/net/batman-adv/bat_iv_ogm.c
78693 +++ b/net/batman-adv/bat_iv_ogm.c
78694 @@ -62,7 +62,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
78695
78696 /* randomize initial seqno to avoid collision */
78697 get_random_bytes(&random_seqno, sizeof(random_seqno));
78698 - atomic_set(&hard_iface->seqno, random_seqno);
78699 + atomic_set_unchecked(&hard_iface->seqno, random_seqno);
78700
78701 hard_iface->packet_len = BATADV_OGM_HLEN;
78702 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
78703 @@ -608,9 +608,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
78704 batadv_ogm_packet = (struct batadv_ogm_packet *)hard_iface->packet_buff;
78705
78706 /* change sequence number to network order */
78707 - seqno = (uint32_t)atomic_read(&hard_iface->seqno);
78708 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->seqno);
78709 batadv_ogm_packet->seqno = htonl(seqno);
78710 - atomic_inc(&hard_iface->seqno);
78711 + atomic_inc_unchecked(&hard_iface->seqno);
78712
78713 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
78714 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
78715 @@ -1015,7 +1015,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
78716 return;
78717
78718 /* could be changed by schedule_own_packet() */
78719 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
78720 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
78721
78722 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
78723 has_directlink_flag = 1;
78724 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
78725 index d112fd6..686a447 100644
78726 --- a/net/batman-adv/hard-interface.c
78727 +++ b/net/batman-adv/hard-interface.c
78728 @@ -327,7 +327,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
78729 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
78730 dev_add_pack(&hard_iface->batman_adv_ptype);
78731
78732 - atomic_set(&hard_iface->frag_seqno, 1);
78733 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
78734 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
78735 hard_iface->net_dev->name);
78736
78737 @@ -450,7 +450,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
78738 /* This can't be called via a bat_priv callback because
78739 * we have no bat_priv yet.
78740 */
78741 - atomic_set(&hard_iface->seqno, 1);
78742 + atomic_set_unchecked(&hard_iface->seqno, 1);
78743 hard_iface->packet_buff = NULL;
78744
78745 return hard_iface;
78746 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
78747 index ce0684a..4a0cbf1 100644
78748 --- a/net/batman-adv/soft-interface.c
78749 +++ b/net/batman-adv/soft-interface.c
78750 @@ -234,7 +234,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
78751 primary_if->net_dev->dev_addr, ETH_ALEN);
78752
78753 /* set broadcast sequence number */
78754 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
78755 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
78756 bcast_packet->seqno = htonl(seqno);
78757
78758 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
78759 @@ -427,7 +427,7 @@ struct net_device *batadv_softif_create(const char *name)
78760 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
78761
78762 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
78763 - atomic_set(&bat_priv->bcast_seqno, 1);
78764 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
78765 atomic_set(&bat_priv->tt.vn, 0);
78766 atomic_set(&bat_priv->tt.local_changes, 0);
78767 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
78768 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
78769 index ac1e07a..4c846e2 100644
78770 --- a/net/batman-adv/types.h
78771 +++ b/net/batman-adv/types.h
78772 @@ -33,8 +33,8 @@ struct batadv_hard_iface {
78773 int16_t if_num;
78774 char if_status;
78775 struct net_device *net_dev;
78776 - atomic_t seqno;
78777 - atomic_t frag_seqno;
78778 + atomic_unchecked_t seqno;
78779 + atomic_unchecked_t frag_seqno;
78780 unsigned char *packet_buff;
78781 int packet_len;
78782 struct kobject *hardif_obj;
78783 @@ -244,7 +244,7 @@ struct batadv_priv {
78784 atomic_t orig_interval; /* uint */
78785 atomic_t hop_penalty; /* uint */
78786 atomic_t log_level; /* uint */
78787 - atomic_t bcast_seqno;
78788 + atomic_unchecked_t bcast_seqno;
78789 atomic_t bcast_queue_left;
78790 atomic_t batman_queue_left;
78791 char num_ifaces;
78792 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
78793 index f397232..3206a33 100644
78794 --- a/net/batman-adv/unicast.c
78795 +++ b/net/batman-adv/unicast.c
78796 @@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
78797 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
78798 frag2->flags = large_tail;
78799
78800 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
78801 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
78802 frag1->seqno = htons(seqno - 1);
78803 frag2->seqno = htons(seqno);
78804
78805 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
78806 index 07f0739..3c42e34 100644
78807 --- a/net/bluetooth/hci_sock.c
78808 +++ b/net/bluetooth/hci_sock.c
78809 @@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
78810 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
78811 }
78812
78813 - len = min_t(unsigned int, len, sizeof(uf));
78814 + len = min((size_t)len, sizeof(uf));
78815 if (copy_from_user(&uf, optval, len)) {
78816 err = -EFAULT;
78817 break;
78818 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
78819 index a91239d..d7ed533 100644
78820 --- a/net/bluetooth/l2cap_core.c
78821 +++ b/net/bluetooth/l2cap_core.c
78822 @@ -3183,8 +3183,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
78823 break;
78824
78825 case L2CAP_CONF_RFC:
78826 - if (olen == sizeof(rfc))
78827 - memcpy(&rfc, (void *)val, olen);
78828 + if (olen != sizeof(rfc))
78829 + break;
78830 +
78831 + memcpy(&rfc, (void *)val, olen);
78832
78833 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
78834 rfc.mode != chan->mode)
78835 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
78836 index 083f2bf..799f9448 100644
78837 --- a/net/bluetooth/l2cap_sock.c
78838 +++ b/net/bluetooth/l2cap_sock.c
78839 @@ -471,7 +471,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
78840 struct sock *sk = sock->sk;
78841 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
78842 struct l2cap_options opts;
78843 - int len, err = 0;
78844 + int err = 0;
78845 + size_t len = optlen;
78846 u32 opt;
78847
78848 BT_DBG("sk %p", sk);
78849 @@ -493,7 +494,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
78850 opts.max_tx = chan->max_tx;
78851 opts.txwin_size = chan->tx_win;
78852
78853 - len = min_t(unsigned int, sizeof(opts), optlen);
78854 + len = min(sizeof(opts), len);
78855 if (copy_from_user((char *) &opts, optval, len)) {
78856 err = -EFAULT;
78857 break;
78858 @@ -571,7 +572,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
78859 struct bt_security sec;
78860 struct bt_power pwr;
78861 struct l2cap_conn *conn;
78862 - int len, err = 0;
78863 + int err = 0;
78864 + size_t len = optlen;
78865 u32 opt;
78866
78867 BT_DBG("sk %p", sk);
78868 @@ -594,7 +596,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
78869
78870 sec.level = BT_SECURITY_LOW;
78871
78872 - len = min_t(unsigned int, sizeof(sec), optlen);
78873 + len = min(sizeof(sec), len);
78874 if (copy_from_user((char *) &sec, optval, len)) {
78875 err = -EFAULT;
78876 break;
78877 @@ -691,7 +693,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
78878
78879 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
78880
78881 - len = min_t(unsigned int, sizeof(pwr), optlen);
78882 + len = min(sizeof(pwr), len);
78883 if (copy_from_user((char *) &pwr, optval, len)) {
78884 err = -EFAULT;
78885 break;
78886 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
78887 index 868a909..d044bc3 100644
78888 --- a/net/bluetooth/rfcomm/sock.c
78889 +++ b/net/bluetooth/rfcomm/sock.c
78890 @@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
78891 struct sock *sk = sock->sk;
78892 struct bt_security sec;
78893 int err = 0;
78894 - size_t len;
78895 + size_t len = optlen;
78896 u32 opt;
78897
78898 BT_DBG("sk %p", sk);
78899 @@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
78900
78901 sec.level = BT_SECURITY_LOW;
78902
78903 - len = min_t(unsigned int, sizeof(sec), optlen);
78904 + len = min(sizeof(sec), len);
78905 if (copy_from_user((char *) &sec, optval, len)) {
78906 err = -EFAULT;
78907 break;
78908 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
78909 index ccc2487..921073d 100644
78910 --- a/net/bluetooth/rfcomm/tty.c
78911 +++ b/net/bluetooth/rfcomm/tty.c
78912 @@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
78913 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
78914
78915 spin_lock_irqsave(&dev->port.lock, flags);
78916 - if (dev->port.count > 0) {
78917 + if (atomic_read(&dev->port.count) > 0) {
78918 spin_unlock_irqrestore(&dev->port.lock, flags);
78919 return;
78920 }
78921 @@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
78922 return -ENODEV;
78923
78924 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
78925 - dev->channel, dev->port.count);
78926 + dev->channel, atomic_read(&dev->port.count));
78927
78928 spin_lock_irqsave(&dev->port.lock, flags);
78929 - if (++dev->port.count > 1) {
78930 + if (atomic_inc_return(&dev->port.count) > 1) {
78931 spin_unlock_irqrestore(&dev->port.lock, flags);
78932 return 0;
78933 }
78934 @@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
78935 return;
78936
78937 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
78938 - dev->port.count);
78939 + atomic_read(&dev->port.count));
78940
78941 spin_lock_irqsave(&dev->port.lock, flags);
78942 - if (!--dev->port.count) {
78943 + if (!atomic_dec_return(&dev->port.count)) {
78944 spin_unlock_irqrestore(&dev->port.lock, flags);
78945 if (dev->tty_dev->parent)
78946 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
78947 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
78948 index 5fe2ff3..121d696 100644
78949 --- a/net/bridge/netfilter/ebtables.c
78950 +++ b/net/bridge/netfilter/ebtables.c
78951 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
78952 tmp.valid_hooks = t->table->valid_hooks;
78953 }
78954 mutex_unlock(&ebt_mutex);
78955 - if (copy_to_user(user, &tmp, *len) != 0){
78956 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
78957 BUGPRINT("c2u Didn't work\n");
78958 ret = -EFAULT;
78959 break;
78960 @@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
78961 goto out;
78962 tmp.valid_hooks = t->valid_hooks;
78963
78964 - if (copy_to_user(user, &tmp, *len) != 0) {
78965 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
78966 ret = -EFAULT;
78967 break;
78968 }
78969 @@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
78970 tmp.entries_size = t->table->entries_size;
78971 tmp.valid_hooks = t->table->valid_hooks;
78972
78973 - if (copy_to_user(user, &tmp, *len) != 0) {
78974 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
78975 ret = -EFAULT;
78976 break;
78977 }
78978 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
78979 index 44f270f..1f5602d 100644
78980 --- a/net/caif/cfctrl.c
78981 +++ b/net/caif/cfctrl.c
78982 @@ -10,6 +10,7 @@
78983 #include <linux/spinlock.h>
78984 #include <linux/slab.h>
78985 #include <linux/pkt_sched.h>
78986 +#include <linux/sched.h>
78987 #include <net/caif/caif_layer.h>
78988 #include <net/caif/cfpkt.h>
78989 #include <net/caif/cfctrl.h>
78990 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
78991 memset(&dev_info, 0, sizeof(dev_info));
78992 dev_info.id = 0xff;
78993 cfsrvl_init(&this->serv, 0, &dev_info, false);
78994 - atomic_set(&this->req_seq_no, 1);
78995 - atomic_set(&this->rsp_seq_no, 1);
78996 + atomic_set_unchecked(&this->req_seq_no, 1);
78997 + atomic_set_unchecked(&this->rsp_seq_no, 1);
78998 this->serv.layer.receive = cfctrl_recv;
78999 sprintf(this->serv.layer.name, "ctrl");
79000 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
79001 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
79002 struct cfctrl_request_info *req)
79003 {
79004 spin_lock_bh(&ctrl->info_list_lock);
79005 - atomic_inc(&ctrl->req_seq_no);
79006 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
79007 + atomic_inc_unchecked(&ctrl->req_seq_no);
79008 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
79009 list_add_tail(&req->list, &ctrl->list);
79010 spin_unlock_bh(&ctrl->info_list_lock);
79011 }
79012 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
79013 if (p != first)
79014 pr_warn("Requests are not received in order\n");
79015
79016 - atomic_set(&ctrl->rsp_seq_no,
79017 + atomic_set_unchecked(&ctrl->rsp_seq_no,
79018 p->sequence_no);
79019 list_del(&p->list);
79020 goto out;
79021 diff --git a/net/can/af_can.c b/net/can/af_can.c
79022 index ddac1ee..3ee0a78 100644
79023 --- a/net/can/af_can.c
79024 +++ b/net/can/af_can.c
79025 @@ -872,7 +872,7 @@ static const struct net_proto_family can_family_ops = {
79026 };
79027
79028 /* notifier block for netdevice event */
79029 -static struct notifier_block can_netdev_notifier __read_mostly = {
79030 +static struct notifier_block can_netdev_notifier = {
79031 .notifier_call = can_notifier,
79032 };
79033
79034 diff --git a/net/can/gw.c b/net/can/gw.c
79035 index 1f5c978..ef714c7 100644
79036 --- a/net/can/gw.c
79037 +++ b/net/can/gw.c
79038 @@ -67,7 +67,6 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
79039 MODULE_ALIAS("can-gw");
79040
79041 static HLIST_HEAD(cgw_list);
79042 -static struct notifier_block notifier;
79043
79044 static struct kmem_cache *cgw_cache __read_mostly;
79045
79046 @@ -887,6 +886,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
79047 return err;
79048 }
79049
79050 +static struct notifier_block notifier = {
79051 + .notifier_call = cgw_notifier
79052 +};
79053 +
79054 static __init int cgw_module_init(void)
79055 {
79056 printk(banner);
79057 @@ -898,7 +901,6 @@ static __init int cgw_module_init(void)
79058 return -ENOMEM;
79059
79060 /* set notifier */
79061 - notifier.notifier_call = cgw_notifier;
79062 register_netdevice_notifier(&notifier);
79063
79064 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
79065 diff --git a/net/compat.c b/net/compat.c
79066 index 79ae884..17c5c09 100644
79067 --- a/net/compat.c
79068 +++ b/net/compat.c
79069 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
79070 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
79071 __get_user(kmsg->msg_flags, &umsg->msg_flags))
79072 return -EFAULT;
79073 - kmsg->msg_name = compat_ptr(tmp1);
79074 - kmsg->msg_iov = compat_ptr(tmp2);
79075 - kmsg->msg_control = compat_ptr(tmp3);
79076 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
79077 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
79078 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
79079 return 0;
79080 }
79081
79082 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
79083
79084 if (kern_msg->msg_namelen) {
79085 if (mode == VERIFY_READ) {
79086 - int err = move_addr_to_kernel(kern_msg->msg_name,
79087 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
79088 kern_msg->msg_namelen,
79089 kern_address);
79090 if (err < 0)
79091 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
79092 kern_msg->msg_name = NULL;
79093
79094 tot_len = iov_from_user_compat_to_kern(kern_iov,
79095 - (struct compat_iovec __user *)kern_msg->msg_iov,
79096 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
79097 kern_msg->msg_iovlen);
79098 if (tot_len >= 0)
79099 kern_msg->msg_iov = kern_iov;
79100 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
79101
79102 #define CMSG_COMPAT_FIRSTHDR(msg) \
79103 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
79104 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
79105 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
79106 (struct compat_cmsghdr __user *)NULL)
79107
79108 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
79109 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
79110 (ucmlen) <= (unsigned long) \
79111 ((mhdr)->msg_controllen - \
79112 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
79113 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
79114
79115 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
79116 struct compat_cmsghdr __user *cmsg, int cmsg_len)
79117 {
79118 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
79119 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
79120 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
79121 msg->msg_controllen)
79122 return NULL;
79123 return (struct compat_cmsghdr __user *)ptr;
79124 @@ -219,7 +219,7 @@ Efault:
79125
79126 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
79127 {
79128 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
79129 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
79130 struct compat_cmsghdr cmhdr;
79131 struct compat_timeval ctv;
79132 struct compat_timespec cts[3];
79133 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
79134
79135 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
79136 {
79137 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
79138 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
79139 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
79140 int fdnum = scm->fp->count;
79141 struct file **fp = scm->fp->fp;
79142 @@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
79143 return -EFAULT;
79144 old_fs = get_fs();
79145 set_fs(KERNEL_DS);
79146 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
79147 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
79148 set_fs(old_fs);
79149
79150 return err;
79151 @@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
79152 len = sizeof(ktime);
79153 old_fs = get_fs();
79154 set_fs(KERNEL_DS);
79155 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
79156 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
79157 set_fs(old_fs);
79158
79159 if (!err) {
79160 @@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
79161 case MCAST_JOIN_GROUP:
79162 case MCAST_LEAVE_GROUP:
79163 {
79164 - struct compat_group_req __user *gr32 = (void *)optval;
79165 + struct compat_group_req __user *gr32 = (void __user *)optval;
79166 struct group_req __user *kgr =
79167 compat_alloc_user_space(sizeof(struct group_req));
79168 u32 interface;
79169 @@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
79170 case MCAST_BLOCK_SOURCE:
79171 case MCAST_UNBLOCK_SOURCE:
79172 {
79173 - struct compat_group_source_req __user *gsr32 = (void *)optval;
79174 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
79175 struct group_source_req __user *kgsr = compat_alloc_user_space(
79176 sizeof(struct group_source_req));
79177 u32 interface;
79178 @@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
79179 }
79180 case MCAST_MSFILTER:
79181 {
79182 - struct compat_group_filter __user *gf32 = (void *)optval;
79183 + struct compat_group_filter __user *gf32 = (void __user *)optval;
79184 struct group_filter __user *kgf;
79185 u32 interface, fmode, numsrc;
79186
79187 @@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
79188 char __user *optval, int __user *optlen,
79189 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
79190 {
79191 - struct compat_group_filter __user *gf32 = (void *)optval;
79192 + struct compat_group_filter __user *gf32 = (void __user *)optval;
79193 struct group_filter __user *kgf;
79194 int __user *koptlen;
79195 u32 interface, fmode, numsrc;
79196 @@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
79197
79198 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
79199 return -EINVAL;
79200 - if (copy_from_user(a, args, nas[call]))
79201 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
79202 return -EFAULT;
79203 a0 = a[0];
79204 a1 = a[1];
79205 diff --git a/net/core/datagram.c b/net/core/datagram.c
79206 index 0337e2b..47914a0 100644
79207 --- a/net/core/datagram.c
79208 +++ b/net/core/datagram.c
79209 @@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
79210 }
79211
79212 kfree_skb(skb);
79213 - atomic_inc(&sk->sk_drops);
79214 + atomic_inc_unchecked(&sk->sk_drops);
79215 sk_mem_reclaim_partial(sk);
79216
79217 return err;
79218 diff --git a/net/core/dev.c b/net/core/dev.c
79219 index e5942bf..25998c3 100644
79220 --- a/net/core/dev.c
79221 +++ b/net/core/dev.c
79222 @@ -1162,9 +1162,13 @@ void dev_load(struct net *net, const char *name)
79223 if (no_module && capable(CAP_NET_ADMIN))
79224 no_module = request_module("netdev-%s", name);
79225 if (no_module && capable(CAP_SYS_MODULE)) {
79226 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
79227 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
79228 +#else
79229 if (!request_module("%s", name))
79230 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
79231 name);
79232 +#endif
79233 }
79234 }
79235 EXPORT_SYMBOL(dev_load);
79236 @@ -1627,7 +1631,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
79237 {
79238 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
79239 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
79240 - atomic_long_inc(&dev->rx_dropped);
79241 + atomic_long_inc_unchecked(&dev->rx_dropped);
79242 kfree_skb(skb);
79243 return NET_RX_DROP;
79244 }
79245 @@ -1637,7 +1641,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
79246 nf_reset(skb);
79247
79248 if (unlikely(!is_skb_forwardable(dev, skb))) {
79249 - atomic_long_inc(&dev->rx_dropped);
79250 + atomic_long_inc_unchecked(&dev->rx_dropped);
79251 kfree_skb(skb);
79252 return NET_RX_DROP;
79253 }
79254 @@ -2093,7 +2097,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
79255
79256 struct dev_gso_cb {
79257 void (*destructor)(struct sk_buff *skb);
79258 -};
79259 +} __no_const;
79260
79261 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
79262
79263 @@ -2955,7 +2959,7 @@ enqueue:
79264
79265 local_irq_restore(flags);
79266
79267 - atomic_long_inc(&skb->dev->rx_dropped);
79268 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
79269 kfree_skb(skb);
79270 return NET_RX_DROP;
79271 }
79272 @@ -3027,7 +3031,7 @@ int netif_rx_ni(struct sk_buff *skb)
79273 }
79274 EXPORT_SYMBOL(netif_rx_ni);
79275
79276 -static void net_tx_action(struct softirq_action *h)
79277 +static void net_tx_action(void)
79278 {
79279 struct softnet_data *sd = &__get_cpu_var(softnet_data);
79280
79281 @@ -3358,7 +3362,7 @@ ncls:
79282 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
79283 } else {
79284 drop:
79285 - atomic_long_inc(&skb->dev->rx_dropped);
79286 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
79287 kfree_skb(skb);
79288 /* Jamal, now you will not able to escape explaining
79289 * me how you were going to use this. :-)
79290 @@ -3944,7 +3948,7 @@ void netif_napi_del(struct napi_struct *napi)
79291 }
79292 EXPORT_SYMBOL(netif_napi_del);
79293
79294 -static void net_rx_action(struct softirq_action *h)
79295 +static void net_rx_action(void)
79296 {
79297 struct softnet_data *sd = &__get_cpu_var(softnet_data);
79298 unsigned long time_limit = jiffies + 2;
79299 @@ -4423,8 +4427,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
79300 else
79301 seq_printf(seq, "%04x", ntohs(pt->type));
79302
79303 +#ifdef CONFIG_GRKERNSEC_HIDESYM
79304 + seq_printf(seq, " %-8s %p\n",
79305 + pt->dev ? pt->dev->name : "", NULL);
79306 +#else
79307 seq_printf(seq, " %-8s %pF\n",
79308 pt->dev ? pt->dev->name : "", pt->func);
79309 +#endif
79310 }
79311
79312 return 0;
79313 @@ -5987,7 +5996,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
79314 } else {
79315 netdev_stats_to_stats64(storage, &dev->stats);
79316 }
79317 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
79318 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
79319 return storage;
79320 }
79321 EXPORT_SYMBOL(dev_get_stats);
79322 diff --git a/net/core/flow.c b/net/core/flow.c
79323 index e318c7e..168b1d0 100644
79324 --- a/net/core/flow.c
79325 +++ b/net/core/flow.c
79326 @@ -61,7 +61,7 @@ struct flow_cache {
79327 struct timer_list rnd_timer;
79328 };
79329
79330 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
79331 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
79332 EXPORT_SYMBOL(flow_cache_genid);
79333 static struct flow_cache flow_cache_global;
79334 static struct kmem_cache *flow_cachep __read_mostly;
79335 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
79336
79337 static int flow_entry_valid(struct flow_cache_entry *fle)
79338 {
79339 - if (atomic_read(&flow_cache_genid) != fle->genid)
79340 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
79341 return 0;
79342 if (fle->object && !fle->object->ops->check(fle->object))
79343 return 0;
79344 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
79345 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
79346 fcp->hash_count++;
79347 }
79348 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
79349 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
79350 flo = fle->object;
79351 if (!flo)
79352 goto ret_object;
79353 @@ -280,7 +280,7 @@ nocache:
79354 }
79355 flo = resolver(net, key, family, dir, flo, ctx);
79356 if (fle) {
79357 - fle->genid = atomic_read(&flow_cache_genid);
79358 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
79359 if (!IS_ERR(flo))
79360 fle->object = flo;
79361 else
79362 diff --git a/net/core/iovec.c b/net/core/iovec.c
79363 index 7e7aeb0..2a998cb 100644
79364 --- a/net/core/iovec.c
79365 +++ b/net/core/iovec.c
79366 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
79367 if (m->msg_namelen) {
79368 if (mode == VERIFY_READ) {
79369 void __user *namep;
79370 - namep = (void __user __force *) m->msg_name;
79371 + namep = (void __force_user *) m->msg_name;
79372 err = move_addr_to_kernel(namep, m->msg_namelen,
79373 address);
79374 if (err < 0)
79375 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
79376 }
79377
79378 size = m->msg_iovlen * sizeof(struct iovec);
79379 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
79380 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
79381 return -EFAULT;
79382
79383 m->msg_iov = iov;
79384 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
79385 index fad649a..f2fdac4 100644
79386 --- a/net/core/rtnetlink.c
79387 +++ b/net/core/rtnetlink.c
79388 @@ -198,14 +198,16 @@ int __rtnl_register(int protocol, int msgtype,
79389 rtnl_msg_handlers[protocol] = tab;
79390 }
79391
79392 + pax_open_kernel();
79393 if (doit)
79394 - tab[msgindex].doit = doit;
79395 + *(void **)&tab[msgindex].doit = doit;
79396
79397 if (dumpit)
79398 - tab[msgindex].dumpit = dumpit;
79399 + *(void **)&tab[msgindex].dumpit = dumpit;
79400
79401 if (calcit)
79402 - tab[msgindex].calcit = calcit;
79403 + *(void **)&tab[msgindex].calcit = calcit;
79404 + pax_close_kernel();
79405
79406 return 0;
79407 }
79408 @@ -248,8 +250,10 @@ int rtnl_unregister(int protocol, int msgtype)
79409 if (rtnl_msg_handlers[protocol] == NULL)
79410 return -ENOENT;
79411
79412 - rtnl_msg_handlers[protocol][msgindex].doit = NULL;
79413 - rtnl_msg_handlers[protocol][msgindex].dumpit = NULL;
79414 + pax_open_kernel();
79415 + *(void **)&rtnl_msg_handlers[protocol][msgindex].doit = NULL;
79416 + *(void **)&rtnl_msg_handlers[protocol][msgindex].dumpit = NULL;
79417 + pax_close_kernel();
79418
79419 return 0;
79420 }
79421 diff --git a/net/core/scm.c b/net/core/scm.c
79422 index ab57084..0190c8f 100644
79423 --- a/net/core/scm.c
79424 +++ b/net/core/scm.c
79425 @@ -223,7 +223,7 @@ EXPORT_SYMBOL(__scm_send);
79426 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
79427 {
79428 struct cmsghdr __user *cm
79429 - = (__force struct cmsghdr __user *)msg->msg_control;
79430 + = (struct cmsghdr __force_user *)msg->msg_control;
79431 struct cmsghdr cmhdr;
79432 int cmlen = CMSG_LEN(len);
79433 int err;
79434 @@ -246,7 +246,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
79435 err = -EFAULT;
79436 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
79437 goto out;
79438 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
79439 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
79440 goto out;
79441 cmlen = CMSG_SPACE(len);
79442 if (msg->msg_controllen < cmlen)
79443 @@ -262,7 +262,7 @@ EXPORT_SYMBOL(put_cmsg);
79444 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
79445 {
79446 struct cmsghdr __user *cm
79447 - = (__force struct cmsghdr __user*)msg->msg_control;
79448 + = (struct cmsghdr __force_user *)msg->msg_control;
79449
79450 int fdmax = 0;
79451 int fdnum = scm->fp->count;
79452 @@ -282,7 +282,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
79453 if (fdnum < fdmax)
79454 fdmax = fdnum;
79455
79456 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
79457 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
79458 i++, cmfptr++)
79459 {
79460 struct socket *sock;
79461 diff --git a/net/core/sock.c b/net/core/sock.c
79462 index 8a146cf..ee08914d 100644
79463 --- a/net/core/sock.c
79464 +++ b/net/core/sock.c
79465 @@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79466 struct sk_buff_head *list = &sk->sk_receive_queue;
79467
79468 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
79469 - atomic_inc(&sk->sk_drops);
79470 + atomic_inc_unchecked(&sk->sk_drops);
79471 trace_sock_rcvqueue_full(sk, skb);
79472 return -ENOMEM;
79473 }
79474 @@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79475 return err;
79476
79477 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
79478 - atomic_inc(&sk->sk_drops);
79479 + atomic_inc_unchecked(&sk->sk_drops);
79480 return -ENOBUFS;
79481 }
79482
79483 @@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79484 skb_dst_force(skb);
79485
79486 spin_lock_irqsave(&list->lock, flags);
79487 - skb->dropcount = atomic_read(&sk->sk_drops);
79488 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
79489 __skb_queue_tail(list, skb);
79490 spin_unlock_irqrestore(&list->lock, flags);
79491
79492 @@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
79493 skb->dev = NULL;
79494
79495 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
79496 - atomic_inc(&sk->sk_drops);
79497 + atomic_inc_unchecked(&sk->sk_drops);
79498 goto discard_and_relse;
79499 }
79500 if (nested)
79501 @@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
79502 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
79503 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
79504 bh_unlock_sock(sk);
79505 - atomic_inc(&sk->sk_drops);
79506 + atomic_inc_unchecked(&sk->sk_drops);
79507 goto discard_and_relse;
79508 }
79509
79510 @@ -875,12 +875,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
79511 struct timeval tm;
79512 } v;
79513
79514 - int lv = sizeof(int);
79515 - int len;
79516 + unsigned int lv = sizeof(int);
79517 + unsigned int len;
79518
79519 if (get_user(len, optlen))
79520 return -EFAULT;
79521 - if (len < 0)
79522 + if (len > INT_MAX)
79523 return -EINVAL;
79524
79525 memset(&v, 0, sizeof(v));
79526 @@ -1028,11 +1028,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
79527
79528 case SO_PEERNAME:
79529 {
79530 - char address[128];
79531 + char address[_K_SS_MAXSIZE];
79532
79533 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
79534 return -ENOTCONN;
79535 - if (lv < len)
79536 + if (lv < len || sizeof address < len)
79537 return -EINVAL;
79538 if (copy_to_user(optval, address, len))
79539 return -EFAULT;
79540 @@ -1080,7 +1080,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
79541
79542 if (len > lv)
79543 len = lv;
79544 - if (copy_to_user(optval, &v, len))
79545 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
79546 return -EFAULT;
79547 lenout:
79548 if (put_user(len, optlen))
79549 @@ -2212,7 +2212,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
79550 */
79551 smp_wmb();
79552 atomic_set(&sk->sk_refcnt, 1);
79553 - atomic_set(&sk->sk_drops, 0);
79554 + atomic_set_unchecked(&sk->sk_drops, 0);
79555 }
79556 EXPORT_SYMBOL(sock_init_data);
79557
79558 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
79559 index 602cd63..05c6c60 100644
79560 --- a/net/core/sock_diag.c
79561 +++ b/net/core/sock_diag.c
79562 @@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
79563
79564 int sock_diag_check_cookie(void *sk, __u32 *cookie)
79565 {
79566 +#ifndef CONFIG_GRKERNSEC_HIDESYM
79567 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
79568 cookie[1] != INET_DIAG_NOCOOKIE) &&
79569 ((u32)(unsigned long)sk != cookie[0] ||
79570 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
79571 return -ESTALE;
79572 else
79573 +#endif
79574 return 0;
79575 }
79576 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
79577
79578 void sock_diag_save_cookie(void *sk, __u32 *cookie)
79579 {
79580 +#ifdef CONFIG_GRKERNSEC_HIDESYM
79581 + cookie[0] = 0;
79582 + cookie[1] = 0;
79583 +#else
79584 cookie[0] = (u32)(unsigned long)sk;
79585 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
79586 +#endif
79587 }
79588 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
79589
79590 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
79591 index a55eecc..dd8428c 100644
79592 --- a/net/decnet/sysctl_net_decnet.c
79593 +++ b/net/decnet/sysctl_net_decnet.c
79594 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
79595
79596 if (len > *lenp) len = *lenp;
79597
79598 - if (copy_to_user(buffer, addr, len))
79599 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
79600 return -EFAULT;
79601
79602 *lenp = len;
79603 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
79604
79605 if (len > *lenp) len = *lenp;
79606
79607 - if (copy_to_user(buffer, devname, len))
79608 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
79609 return -EFAULT;
79610
79611 *lenp = len;
79612 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
79613 index 2a6abc1..c379ba7 100644
79614 --- a/net/ipv4/devinet.c
79615 +++ b/net/ipv4/devinet.c
79616 @@ -822,9 +822,9 @@ int devinet_ioctl(struct net *net, unsigned int cmd, void __user *arg)
79617 if (!ifa) {
79618 ret = -ENOBUFS;
79619 ifa = inet_alloc_ifa();
79620 + if (!ifa)
79621 + break;
79622 INIT_HLIST_NODE(&ifa->hash);
79623 - if (!ifa)
79624 - break;
79625 if (colon)
79626 memcpy(ifa->ifa_label, ifr.ifr_name, IFNAMSIZ);
79627 else
79628 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
79629 index 825c608..750ff29 100644
79630 --- a/net/ipv4/fib_frontend.c
79631 +++ b/net/ipv4/fib_frontend.c
79632 @@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
79633 #ifdef CONFIG_IP_ROUTE_MULTIPATH
79634 fib_sync_up(dev);
79635 #endif
79636 - atomic_inc(&net->ipv4.dev_addr_genid);
79637 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
79638 rt_cache_flush(dev_net(dev));
79639 break;
79640 case NETDEV_DOWN:
79641 fib_del_ifaddr(ifa, NULL);
79642 - atomic_inc(&net->ipv4.dev_addr_genid);
79643 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
79644 if (ifa->ifa_dev->ifa_list == NULL) {
79645 /* Last address was deleted from this interface.
79646 * Disable IP.
79647 @@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
79648 #ifdef CONFIG_IP_ROUTE_MULTIPATH
79649 fib_sync_up(dev);
79650 #endif
79651 - atomic_inc(&net->ipv4.dev_addr_genid);
79652 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
79653 rt_cache_flush(net);
79654 break;
79655 case NETDEV_DOWN:
79656 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
79657 index 71b125c..f4c70b0 100644
79658 --- a/net/ipv4/fib_semantics.c
79659 +++ b/net/ipv4/fib_semantics.c
79660 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
79661 nh->nh_saddr = inet_select_addr(nh->nh_dev,
79662 nh->nh_gw,
79663 nh->nh_parent->fib_scope);
79664 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
79665 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
79666
79667 return nh->nh_saddr;
79668 }
79669 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
79670 index 7880af9..70f92a3 100644
79671 --- a/net/ipv4/inet_hashtables.c
79672 +++ b/net/ipv4/inet_hashtables.c
79673 @@ -18,12 +18,15 @@
79674 #include <linux/sched.h>
79675 #include <linux/slab.h>
79676 #include <linux/wait.h>
79677 +#include <linux/security.h>
79678
79679 #include <net/inet_connection_sock.h>
79680 #include <net/inet_hashtables.h>
79681 #include <net/secure_seq.h>
79682 #include <net/ip.h>
79683
79684 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
79685 +
79686 /*
79687 * Allocate and initialize a new local port bind bucket.
79688 * The bindhash mutex for snum's hash chain must be held here.
79689 @@ -530,6 +533,8 @@ ok:
79690 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
79691 spin_unlock(&head->lock);
79692
79693 + gr_update_task_in_ip_table(current, inet_sk(sk));
79694 +
79695 if (tw) {
79696 inet_twsk_deschedule(tw, death_row);
79697 while (twrefcnt) {
79698 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
79699 index 000e3d2..5472da3 100644
79700 --- a/net/ipv4/inetpeer.c
79701 +++ b/net/ipv4/inetpeer.c
79702 @@ -503,8 +503,8 @@ relookup:
79703 if (p) {
79704 p->daddr = *daddr;
79705 atomic_set(&p->refcnt, 1);
79706 - atomic_set(&p->rid, 0);
79707 - atomic_set(&p->ip_id_count,
79708 + atomic_set_unchecked(&p->rid, 0);
79709 + atomic_set_unchecked(&p->ip_id_count,
79710 (daddr->family == AF_INET) ?
79711 secure_ip_id(daddr->addr.a4) :
79712 secure_ipv6_id(daddr->addr.a6));
79713 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
79714 index 8d5cc75..821fd11 100644
79715 --- a/net/ipv4/ip_fragment.c
79716 +++ b/net/ipv4/ip_fragment.c
79717 @@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
79718 return 0;
79719
79720 start = qp->rid;
79721 - end = atomic_inc_return(&peer->rid);
79722 + end = atomic_inc_return_unchecked(&peer->rid);
79723 qp->rid = end;
79724
79725 rc = qp->q.fragments && (end - start) > max;
79726 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
79727 index 14bbfcf..644f472 100644
79728 --- a/net/ipv4/ip_sockglue.c
79729 +++ b/net/ipv4/ip_sockglue.c
79730 @@ -1151,7 +1151,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
79731 len = min_t(unsigned int, len, opt->optlen);
79732 if (put_user(len, optlen))
79733 return -EFAULT;
79734 - if (copy_to_user(optval, opt->__data, len))
79735 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
79736 + copy_to_user(optval, opt->__data, len))
79737 return -EFAULT;
79738 return 0;
79739 }
79740 @@ -1282,7 +1283,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
79741 if (sk->sk_type != SOCK_STREAM)
79742 return -ENOPROTOOPT;
79743
79744 - msg.msg_control = optval;
79745 + msg.msg_control = (void __force_kernel *)optval;
79746 msg.msg_controllen = len;
79747 msg.msg_flags = flags;
79748
79749 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
79750 index 798358b..73570b7 100644
79751 --- a/net/ipv4/ipconfig.c
79752 +++ b/net/ipv4/ipconfig.c
79753 @@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
79754
79755 mm_segment_t oldfs = get_fs();
79756 set_fs(get_ds());
79757 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
79758 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
79759 set_fs(oldfs);
79760 return res;
79761 }
79762 @@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
79763
79764 mm_segment_t oldfs = get_fs();
79765 set_fs(get_ds());
79766 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
79767 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
79768 set_fs(oldfs);
79769 return res;
79770 }
79771 @@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
79772
79773 mm_segment_t oldfs = get_fs();
79774 set_fs(get_ds());
79775 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
79776 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
79777 set_fs(oldfs);
79778 return res;
79779 }
79780 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
79781 index 97e61ea..cac1bbb 100644
79782 --- a/net/ipv4/netfilter/arp_tables.c
79783 +++ b/net/ipv4/netfilter/arp_tables.c
79784 @@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
79785 #endif
79786
79787 static int get_info(struct net *net, void __user *user,
79788 - const int *len, int compat)
79789 + int len, int compat)
79790 {
79791 char name[XT_TABLE_MAXNAMELEN];
79792 struct xt_table *t;
79793 int ret;
79794
79795 - if (*len != sizeof(struct arpt_getinfo)) {
79796 - duprintf("length %u != %Zu\n", *len,
79797 + if (len != sizeof(struct arpt_getinfo)) {
79798 + duprintf("length %u != %Zu\n", len,
79799 sizeof(struct arpt_getinfo));
79800 return -EINVAL;
79801 }
79802 @@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
79803 info.size = private->size;
79804 strcpy(info.name, name);
79805
79806 - if (copy_to_user(user, &info, *len) != 0)
79807 + if (copy_to_user(user, &info, len) != 0)
79808 ret = -EFAULT;
79809 else
79810 ret = 0;
79811 @@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
79812
79813 switch (cmd) {
79814 case ARPT_SO_GET_INFO:
79815 - ret = get_info(sock_net(sk), user, len, 1);
79816 + ret = get_info(sock_net(sk), user, *len, 1);
79817 break;
79818 case ARPT_SO_GET_ENTRIES:
79819 ret = compat_get_entries(sock_net(sk), user, len);
79820 @@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
79821
79822 switch (cmd) {
79823 case ARPT_SO_GET_INFO:
79824 - ret = get_info(sock_net(sk), user, len, 0);
79825 + ret = get_info(sock_net(sk), user, *len, 0);
79826 break;
79827
79828 case ARPT_SO_GET_ENTRIES:
79829 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
79830 index 170b1fd..6105b91 100644
79831 --- a/net/ipv4/netfilter/ip_tables.c
79832 +++ b/net/ipv4/netfilter/ip_tables.c
79833 @@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
79834 #endif
79835
79836 static int get_info(struct net *net, void __user *user,
79837 - const int *len, int compat)
79838 + int len, int compat)
79839 {
79840 char name[XT_TABLE_MAXNAMELEN];
79841 struct xt_table *t;
79842 int ret;
79843
79844 - if (*len != sizeof(struct ipt_getinfo)) {
79845 - duprintf("length %u != %zu\n", *len,
79846 + if (len != sizeof(struct ipt_getinfo)) {
79847 + duprintf("length %u != %zu\n", len,
79848 sizeof(struct ipt_getinfo));
79849 return -EINVAL;
79850 }
79851 @@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
79852 info.size = private->size;
79853 strcpy(info.name, name);
79854
79855 - if (copy_to_user(user, &info, *len) != 0)
79856 + if (copy_to_user(user, &info, len) != 0)
79857 ret = -EFAULT;
79858 else
79859 ret = 0;
79860 @@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
79861
79862 switch (cmd) {
79863 case IPT_SO_GET_INFO:
79864 - ret = get_info(sock_net(sk), user, len, 1);
79865 + ret = get_info(sock_net(sk), user, *len, 1);
79866 break;
79867 case IPT_SO_GET_ENTRIES:
79868 ret = compat_get_entries(sock_net(sk), user, len);
79869 @@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
79870
79871 switch (cmd) {
79872 case IPT_SO_GET_INFO:
79873 - ret = get_info(sock_net(sk), user, len, 0);
79874 + ret = get_info(sock_net(sk), user, *len, 0);
79875 break;
79876
79877 case IPT_SO_GET_ENTRIES:
79878 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
79879 index 8f3d054..c58d05d 100644
79880 --- a/net/ipv4/ping.c
79881 +++ b/net/ipv4/ping.c
79882 @@ -843,7 +843,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
79883 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
79884 0, sock_i_ino(sp),
79885 atomic_read(&sp->sk_refcnt), sp,
79886 - atomic_read(&sp->sk_drops), len);
79887 + atomic_read_unchecked(&sp->sk_drops), len);
79888 }
79889
79890 static int ping_seq_show(struct seq_file *seq, void *v)
79891 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
79892 index 73d1e4d..3af0e8f 100644
79893 --- a/net/ipv4/raw.c
79894 +++ b/net/ipv4/raw.c
79895 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
79896 int raw_rcv(struct sock *sk, struct sk_buff *skb)
79897 {
79898 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
79899 - atomic_inc(&sk->sk_drops);
79900 + atomic_inc_unchecked(&sk->sk_drops);
79901 kfree_skb(skb);
79902 return NET_RX_DROP;
79903 }
79904 @@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
79905
79906 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
79907 {
79908 + struct icmp_filter filter;
79909 +
79910 if (optlen > sizeof(struct icmp_filter))
79911 optlen = sizeof(struct icmp_filter);
79912 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
79913 + if (copy_from_user(&filter, optval, optlen))
79914 return -EFAULT;
79915 + raw_sk(sk)->filter = filter;
79916 return 0;
79917 }
79918
79919 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
79920 {
79921 int len, ret = -EFAULT;
79922 + struct icmp_filter filter;
79923
79924 if (get_user(len, optlen))
79925 goto out;
79926 @@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
79927 if (len > sizeof(struct icmp_filter))
79928 len = sizeof(struct icmp_filter);
79929 ret = -EFAULT;
79930 - if (put_user(len, optlen) ||
79931 - copy_to_user(optval, &raw_sk(sk)->filter, len))
79932 + filter = raw_sk(sk)->filter;
79933 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
79934 goto out;
79935 ret = 0;
79936 out: return ret;
79937 @@ -997,7 +1001,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
79938 0, 0L, 0,
79939 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
79940 0, sock_i_ino(sp),
79941 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
79942 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
79943 }
79944
79945 static int raw_seq_show(struct seq_file *seq, void *v)
79946 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
79947 index df25142..e92a82a 100644
79948 --- a/net/ipv4/route.c
79949 +++ b/net/ipv4/route.c
79950 @@ -2529,7 +2529,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
79951
79952 static __net_init int rt_genid_init(struct net *net)
79953 {
79954 - atomic_set(&net->rt_genid, 0);
79955 + atomic_set_unchecked(&net->rt_genid, 0);
79956 get_random_bytes(&net->ipv4.dev_addr_genid,
79957 sizeof(net->ipv4.dev_addr_genid));
79958 return 0;
79959 diff --git a/net/ipv4/tcp_cong.c b/net/ipv4/tcp_cong.c
79960 index 1432cdb..fc582a7 100644
79961 --- a/net/ipv4/tcp_cong.c
79962 +++ b/net/ipv4/tcp_cong.c
79963 @@ -309,6 +309,12 @@ void tcp_slow_start(struct tcp_sock *tp)
79964 {
79965 int cnt; /* increase in packets */
79966 unsigned int delta = 0;
79967 + u32 snd_cwnd = tp->snd_cwnd;
79968 +
79969 + if (unlikely(!snd_cwnd)) {
79970 + pr_err_once("snd_cwnd is nul, please report this bug.\n");
79971 + snd_cwnd = 1U;
79972 + }
79973
79974 /* RFC3465: ABC Slow start
79975 * Increase only after a full MSS of bytes is acked
79976 @@ -323,7 +329,7 @@ void tcp_slow_start(struct tcp_sock *tp)
79977 if (sysctl_tcp_max_ssthresh > 0 && tp->snd_cwnd > sysctl_tcp_max_ssthresh)
79978 cnt = sysctl_tcp_max_ssthresh >> 1; /* limited slow start */
79979 else
79980 - cnt = tp->snd_cwnd; /* exponential increase */
79981 + cnt = snd_cwnd; /* exponential increase */
79982
79983 /* RFC3465: ABC
79984 * We MAY increase by 2 if discovered delayed ack
79985 @@ -333,11 +339,11 @@ void tcp_slow_start(struct tcp_sock *tp)
79986 tp->bytes_acked = 0;
79987
79988 tp->snd_cwnd_cnt += cnt;
79989 - while (tp->snd_cwnd_cnt >= tp->snd_cwnd) {
79990 - tp->snd_cwnd_cnt -= tp->snd_cwnd;
79991 + while (tp->snd_cwnd_cnt >= snd_cwnd) {
79992 + tp->snd_cwnd_cnt -= snd_cwnd;
79993 delta++;
79994 }
79995 - tp->snd_cwnd = min(tp->snd_cwnd + delta, tp->snd_cwnd_clamp);
79996 + tp->snd_cwnd = min(snd_cwnd + delta, tp->snd_cwnd_clamp);
79997 }
79998 EXPORT_SYMBOL_GPL(tcp_slow_start);
79999
80000 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
80001 index 181fc82..cc95f8c 100644
80002 --- a/net/ipv4/tcp_input.c
80003 +++ b/net/ipv4/tcp_input.c
80004 @@ -4704,7 +4704,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
80005 * simplifies code)
80006 */
80007 static void
80008 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
80009 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
80010 struct sk_buff *head, struct sk_buff *tail,
80011 u32 start, u32 end)
80012 {
80013 @@ -5536,6 +5536,9 @@ slow_path:
80014 if (len < (th->doff << 2) || tcp_checksum_complete_user(sk, skb))
80015 goto csum_error;
80016
80017 + if (!th->ack)
80018 + goto discard;
80019 +
80020 /*
80021 * Standard slow path.
80022 */
80023 @@ -5544,7 +5547,7 @@ slow_path:
80024 return 0;
80025
80026 step5:
80027 - if (th->ack && tcp_ack(sk, skb, FLAG_SLOWPATH) < 0)
80028 + if (tcp_ack(sk, skb, FLAG_SLOWPATH) < 0)
80029 goto discard;
80030
80031 /* ts_recent update must be made after we are sure that the packet
80032 @@ -5836,6 +5839,7 @@ discard:
80033 tcp_paws_reject(&tp->rx_opt, 0))
80034 goto discard_and_undo;
80035
80036 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
80037 if (th->syn) {
80038 /* We see SYN without ACK. It is attempt of
80039 * simultaneous connect with crossed SYNs.
80040 @@ -5886,6 +5890,7 @@ discard:
80041 goto discard;
80042 #endif
80043 }
80044 +#endif
80045 /* "fifth, if neither of the SYN or RST bits is set then
80046 * drop the segment and return."
80047 */
80048 @@ -5930,7 +5935,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
80049 goto discard;
80050
80051 if (th->syn) {
80052 - if (th->fin)
80053 + if (th->fin || th->urg || th->psh)
80054 goto discard;
80055 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
80056 return 1;
80057 @@ -5977,11 +5982,15 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
80058 if (tcp_check_req(sk, skb, req, NULL, true) == NULL)
80059 goto discard;
80060 }
80061 +
80062 + if (!th->ack)
80063 + goto discard;
80064 +
80065 if (!tcp_validate_incoming(sk, skb, th, 0))
80066 return 0;
80067
80068 /* step 5: check the ACK field */
80069 - if (th->ack) {
80070 + if (true) {
80071 int acceptable = tcp_ack(sk, skb, FLAG_SLOWPATH) > 0;
80072
80073 switch (sk->sk_state) {
80074 @@ -6131,8 +6140,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
80075 }
80076 break;
80077 }
80078 - } else
80079 - goto discard;
80080 + }
80081
80082 /* ts_recent update must be made after we are sure that the packet
80083 * is in window.
80084 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
80085 index bc3cb46..815ccd6 100644
80086 --- a/net/ipv4/tcp_ipv4.c
80087 +++ b/net/ipv4/tcp_ipv4.c
80088 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
80089 EXPORT_SYMBOL(sysctl_tcp_low_latency);
80090
80091
80092 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80093 +extern int grsec_enable_blackhole;
80094 +#endif
80095 +
80096 #ifdef CONFIG_TCP_MD5SIG
80097 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
80098 __be32 daddr, __be32 saddr, const struct tcphdr *th);
80099 @@ -1899,6 +1903,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
80100 return 0;
80101
80102 reset:
80103 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80104 + if (!grsec_enable_blackhole)
80105 +#endif
80106 tcp_v4_send_reset(rsk, skb);
80107 discard:
80108 kfree_skb(skb);
80109 @@ -1999,12 +2006,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
80110 TCP_SKB_CB(skb)->sacked = 0;
80111
80112 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
80113 - if (!sk)
80114 + if (!sk) {
80115 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80116 + ret = 1;
80117 +#endif
80118 goto no_tcp_socket;
80119 -
80120 + }
80121 process:
80122 - if (sk->sk_state == TCP_TIME_WAIT)
80123 + if (sk->sk_state == TCP_TIME_WAIT) {
80124 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80125 + ret = 2;
80126 +#endif
80127 goto do_time_wait;
80128 + }
80129
80130 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
80131 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
80132 @@ -2055,6 +2069,10 @@ no_tcp_socket:
80133 bad_packet:
80134 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
80135 } else {
80136 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80137 + if (!grsec_enable_blackhole || (ret == 1 &&
80138 + (skb->dev->flags & IFF_LOOPBACK)))
80139 +#endif
80140 tcp_v4_send_reset(NULL, skb);
80141 }
80142
80143 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
80144 index a7302d9..e3ec754 100644
80145 --- a/net/ipv4/tcp_minisocks.c
80146 +++ b/net/ipv4/tcp_minisocks.c
80147 @@ -27,6 +27,10 @@
80148 #include <net/inet_common.h>
80149 #include <net/xfrm.h>
80150
80151 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80152 +extern int grsec_enable_blackhole;
80153 +#endif
80154 +
80155 int sysctl_tcp_syncookies __read_mostly = 1;
80156 EXPORT_SYMBOL(sysctl_tcp_syncookies);
80157
80158 @@ -742,7 +746,10 @@ embryonic_reset:
80159 * avoid becoming vulnerable to outside attack aiming at
80160 * resetting legit local connections.
80161 */
80162 - req->rsk_ops->send_reset(sk, skb);
80163 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80164 + if (!grsec_enable_blackhole)
80165 +#endif
80166 + req->rsk_ops->send_reset(sk, skb);
80167 } else if (fastopen) { /* received a valid RST pkt */
80168 reqsk_fastopen_remove(sk, req, true);
80169 tcp_reset(sk);
80170 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
80171 index 4526fe6..1a34e43 100644
80172 --- a/net/ipv4/tcp_probe.c
80173 +++ b/net/ipv4/tcp_probe.c
80174 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
80175 if (cnt + width >= len)
80176 break;
80177
80178 - if (copy_to_user(buf + cnt, tbuf, width))
80179 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
80180 return -EFAULT;
80181 cnt += width;
80182 }
80183 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
80184 index d47c1b4..b0584de 100644
80185 --- a/net/ipv4/tcp_timer.c
80186 +++ b/net/ipv4/tcp_timer.c
80187 @@ -22,6 +22,10 @@
80188 #include <linux/gfp.h>
80189 #include <net/tcp.h>
80190
80191 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80192 +extern int grsec_lastack_retries;
80193 +#endif
80194 +
80195 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
80196 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
80197 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
80198 @@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
80199 }
80200 }
80201
80202 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80203 + if ((sk->sk_state == TCP_LAST_ACK) &&
80204 + (grsec_lastack_retries > 0) &&
80205 + (grsec_lastack_retries < retry_until))
80206 + retry_until = grsec_lastack_retries;
80207 +#endif
80208 +
80209 if (retransmits_timed_out(sk, retry_until,
80210 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
80211 /* Has it gone just too far? */
80212 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
80213 index 79c8dbe..aceb1b6 100644
80214 --- a/net/ipv4/udp.c
80215 +++ b/net/ipv4/udp.c
80216 @@ -87,6 +87,7 @@
80217 #include <linux/types.h>
80218 #include <linux/fcntl.h>
80219 #include <linux/module.h>
80220 +#include <linux/security.h>
80221 #include <linux/socket.h>
80222 #include <linux/sockios.h>
80223 #include <linux/igmp.h>
80224 @@ -111,6 +112,10 @@
80225 #include <trace/events/skb.h>
80226 #include "udp_impl.h"
80227
80228 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80229 +extern int grsec_enable_blackhole;
80230 +#endif
80231 +
80232 struct udp_table udp_table __read_mostly;
80233 EXPORT_SYMBOL(udp_table);
80234
80235 @@ -569,6 +574,9 @@ found:
80236 return s;
80237 }
80238
80239 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
80240 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
80241 +
80242 /*
80243 * This routine is called by the ICMP module when it gets some
80244 * sort of error condition. If err < 0 then the socket should
80245 @@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
80246 dport = usin->sin_port;
80247 if (dport == 0)
80248 return -EINVAL;
80249 +
80250 + err = gr_search_udp_sendmsg(sk, usin);
80251 + if (err)
80252 + return err;
80253 } else {
80254 if (sk->sk_state != TCP_ESTABLISHED)
80255 return -EDESTADDRREQ;
80256 +
80257 + err = gr_search_udp_sendmsg(sk, NULL);
80258 + if (err)
80259 + return err;
80260 +
80261 daddr = inet->inet_daddr;
80262 dport = inet->inet_dport;
80263 /* Open fast path for connected socket.
80264 @@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
80265 udp_lib_checksum_complete(skb)) {
80266 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
80267 IS_UDPLITE(sk));
80268 - atomic_inc(&sk->sk_drops);
80269 + atomic_inc_unchecked(&sk->sk_drops);
80270 __skb_unlink(skb, rcvq);
80271 __skb_queue_tail(&list_kill, skb);
80272 }
80273 @@ -1194,6 +1211,10 @@ try_again:
80274 if (!skb)
80275 goto out;
80276
80277 + err = gr_search_udp_recvmsg(sk, skb);
80278 + if (err)
80279 + goto out_free;
80280 +
80281 ulen = skb->len - sizeof(struct udphdr);
80282 copied = len;
80283 if (copied > ulen)
80284 @@ -1227,7 +1248,7 @@ try_again:
80285 if (unlikely(err)) {
80286 trace_kfree_skb(skb, udp_recvmsg);
80287 if (!peeked) {
80288 - atomic_inc(&sk->sk_drops);
80289 + atomic_inc_unchecked(&sk->sk_drops);
80290 UDP_INC_STATS_USER(sock_net(sk),
80291 UDP_MIB_INERRORS, is_udplite);
80292 }
80293 @@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80294
80295 drop:
80296 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
80297 - atomic_inc(&sk->sk_drops);
80298 + atomic_inc_unchecked(&sk->sk_drops);
80299 kfree_skb(skb);
80300 return -1;
80301 }
80302 @@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
80303 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
80304
80305 if (!skb1) {
80306 - atomic_inc(&sk->sk_drops);
80307 + atomic_inc_unchecked(&sk->sk_drops);
80308 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
80309 IS_UDPLITE(sk));
80310 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
80311 @@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
80312 goto csum_error;
80313
80314 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
80315 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80316 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
80317 +#endif
80318 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
80319
80320 /*
80321 @@ -2119,7 +2143,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
80322 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
80323 0, sock_i_ino(sp),
80324 atomic_read(&sp->sk_refcnt), sp,
80325 - atomic_read(&sp->sk_drops), len);
80326 + atomic_read_unchecked(&sp->sk_drops), len);
80327 }
80328
80329 int udp4_seq_show(struct seq_file *seq, void *v)
80330 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
80331 index 0424e4e..308dd43 100644
80332 --- a/net/ipv6/addrconf.c
80333 +++ b/net/ipv6/addrconf.c
80334 @@ -2121,7 +2121,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
80335 p.iph.ihl = 5;
80336 p.iph.protocol = IPPROTO_IPV6;
80337 p.iph.ttl = 64;
80338 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
80339 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
80340
80341 if (ops->ndo_do_ioctl) {
80342 mm_segment_t oldfs = get_fs();
80343 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
80344 index d5cb3c4..b3e38d0 100644
80345 --- a/net/ipv6/ip6_gre.c
80346 +++ b/net/ipv6/ip6_gre.c
80347 @@ -1353,7 +1353,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
80348 }
80349
80350
80351 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
80352 +static struct inet6_protocol ip6gre_protocol = {
80353 .handler = ip6gre_rcv,
80354 .err_handler = ip6gre_err,
80355 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
80356 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
80357 index e02faed..9780f28 100644
80358 --- a/net/ipv6/ipv6_sockglue.c
80359 +++ b/net/ipv6/ipv6_sockglue.c
80360 @@ -990,7 +990,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
80361 if (sk->sk_type != SOCK_STREAM)
80362 return -ENOPROTOOPT;
80363
80364 - msg.msg_control = optval;
80365 + msg.msg_control = (void __force_kernel *)optval;
80366 msg.msg_controllen = len;
80367 msg.msg_flags = flags;
80368
80369 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
80370 index d7cb045..8c0ded6 100644
80371 --- a/net/ipv6/netfilter/ip6_tables.c
80372 +++ b/net/ipv6/netfilter/ip6_tables.c
80373 @@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
80374 #endif
80375
80376 static int get_info(struct net *net, void __user *user,
80377 - const int *len, int compat)
80378 + int len, int compat)
80379 {
80380 char name[XT_TABLE_MAXNAMELEN];
80381 struct xt_table *t;
80382 int ret;
80383
80384 - if (*len != sizeof(struct ip6t_getinfo)) {
80385 - duprintf("length %u != %zu\n", *len,
80386 + if (len != sizeof(struct ip6t_getinfo)) {
80387 + duprintf("length %u != %zu\n", len,
80388 sizeof(struct ip6t_getinfo));
80389 return -EINVAL;
80390 }
80391 @@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
80392 info.size = private->size;
80393 strcpy(info.name, name);
80394
80395 - if (copy_to_user(user, &info, *len) != 0)
80396 + if (copy_to_user(user, &info, len) != 0)
80397 ret = -EFAULT;
80398 else
80399 ret = 0;
80400 @@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
80401
80402 switch (cmd) {
80403 case IP6T_SO_GET_INFO:
80404 - ret = get_info(sock_net(sk), user, len, 1);
80405 + ret = get_info(sock_net(sk), user, *len, 1);
80406 break;
80407 case IP6T_SO_GET_ENTRIES:
80408 ret = compat_get_entries(sock_net(sk), user, len);
80409 @@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
80410
80411 switch (cmd) {
80412 case IP6T_SO_GET_INFO:
80413 - ret = get_info(sock_net(sk), user, len, 0);
80414 + ret = get_info(sock_net(sk), user, *len, 0);
80415 break;
80416
80417 case IP6T_SO_GET_ENTRIES:
80418 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
80419 index d8e95c7..81422bc 100644
80420 --- a/net/ipv6/raw.c
80421 +++ b/net/ipv6/raw.c
80422 @@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
80423 {
80424 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
80425 skb_checksum_complete(skb)) {
80426 - atomic_inc(&sk->sk_drops);
80427 + atomic_inc_unchecked(&sk->sk_drops);
80428 kfree_skb(skb);
80429 return NET_RX_DROP;
80430 }
80431 @@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
80432 struct raw6_sock *rp = raw6_sk(sk);
80433
80434 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
80435 - atomic_inc(&sk->sk_drops);
80436 + atomic_inc_unchecked(&sk->sk_drops);
80437 kfree_skb(skb);
80438 return NET_RX_DROP;
80439 }
80440 @@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
80441
80442 if (inet->hdrincl) {
80443 if (skb_checksum_complete(skb)) {
80444 - atomic_inc(&sk->sk_drops);
80445 + atomic_inc_unchecked(&sk->sk_drops);
80446 kfree_skb(skb);
80447 return NET_RX_DROP;
80448 }
80449 @@ -604,7 +604,7 @@ out:
80450 return err;
80451 }
80452
80453 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
80454 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
80455 struct flowi6 *fl6, struct dst_entry **dstp,
80456 unsigned int flags)
80457 {
80458 @@ -916,12 +916,15 @@ do_confirm:
80459 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
80460 char __user *optval, int optlen)
80461 {
80462 + struct icmp6_filter filter;
80463 +
80464 switch (optname) {
80465 case ICMPV6_FILTER:
80466 if (optlen > sizeof(struct icmp6_filter))
80467 optlen = sizeof(struct icmp6_filter);
80468 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
80469 + if (copy_from_user(&filter, optval, optlen))
80470 return -EFAULT;
80471 + raw6_sk(sk)->filter = filter;
80472 return 0;
80473 default:
80474 return -ENOPROTOOPT;
80475 @@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
80476 char __user *optval, int __user *optlen)
80477 {
80478 int len;
80479 + struct icmp6_filter filter;
80480
80481 switch (optname) {
80482 case ICMPV6_FILTER:
80483 @@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
80484 len = sizeof(struct icmp6_filter);
80485 if (put_user(len, optlen))
80486 return -EFAULT;
80487 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
80488 + filter = raw6_sk(sk)->filter;
80489 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
80490 return -EFAULT;
80491 return 0;
80492 default:
80493 @@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
80494 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
80495 0,
80496 sock_i_ino(sp),
80497 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
80498 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
80499 }
80500
80501 static int raw6_seq_show(struct seq_file *seq, void *v)
80502 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
80503 index b1e6cf0..b140ef2 100644
80504 --- a/net/ipv6/route.c
80505 +++ b/net/ipv6/route.c
80506 @@ -872,7 +872,7 @@ restart:
80507 dst_hold(&rt->dst);
80508 read_unlock_bh(&table->tb6_lock);
80509
80510 - if (!rt->n && !(rt->rt6i_flags & RTF_NONEXTHOP))
80511 + if (!rt->n && !(rt->rt6i_flags & (RTF_NONEXTHOP | RTF_LOCAL)))
80512 nrt = rt6_alloc_cow(rt, &fl6->daddr, &fl6->saddr);
80513 else if (!(rt->dst.flags & DST_HOST))
80514 nrt = rt6_alloc_clone(rt, &fl6->daddr);
80515 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
80516 index 73f2a6b..f8049a1 100644
80517 --- a/net/ipv6/tcp_ipv6.c
80518 +++ b/net/ipv6/tcp_ipv6.c
80519 @@ -106,6 +106,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
80520 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
80521 }
80522
80523 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80524 +extern int grsec_enable_blackhole;
80525 +#endif
80526 +
80527 static void tcp_v6_hash(struct sock *sk)
80528 {
80529 if (sk->sk_state != TCP_CLOSE) {
80530 @@ -1525,6 +1529,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
80531 return 0;
80532
80533 reset:
80534 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80535 + if (!grsec_enable_blackhole)
80536 +#endif
80537 tcp_v6_send_reset(sk, skb);
80538 discard:
80539 if (opt_skb)
80540 @@ -1606,12 +1613,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
80541 TCP_SKB_CB(skb)->sacked = 0;
80542
80543 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
80544 - if (!sk)
80545 + if (!sk) {
80546 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80547 + ret = 1;
80548 +#endif
80549 goto no_tcp_socket;
80550 + }
80551
80552 process:
80553 - if (sk->sk_state == TCP_TIME_WAIT)
80554 + if (sk->sk_state == TCP_TIME_WAIT) {
80555 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80556 + ret = 2;
80557 +#endif
80558 goto do_time_wait;
80559 + }
80560
80561 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
80562 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
80563 @@ -1660,6 +1675,10 @@ no_tcp_socket:
80564 bad_packet:
80565 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
80566 } else {
80567 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80568 + if (!grsec_enable_blackhole || (ret == 1 &&
80569 + (skb->dev->flags & IFF_LOOPBACK)))
80570 +#endif
80571 tcp_v6_send_reset(NULL, skb);
80572 }
80573
80574 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
80575 index fc99972..69397e8 100644
80576 --- a/net/ipv6/udp.c
80577 +++ b/net/ipv6/udp.c
80578 @@ -51,6 +51,10 @@
80579 #include <trace/events/skb.h>
80580 #include "udp_impl.h"
80581
80582 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80583 +extern int grsec_enable_blackhole;
80584 +#endif
80585 +
80586 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
80587 {
80588 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
80589 @@ -395,7 +399,7 @@ try_again:
80590 if (unlikely(err)) {
80591 trace_kfree_skb(skb, udpv6_recvmsg);
80592 if (!peeked) {
80593 - atomic_inc(&sk->sk_drops);
80594 + atomic_inc_unchecked(&sk->sk_drops);
80595 if (is_udp4)
80596 UDP_INC_STATS_USER(sock_net(sk),
80597 UDP_MIB_INERRORS,
80598 @@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80599 return rc;
80600 drop:
80601 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
80602 - atomic_inc(&sk->sk_drops);
80603 + atomic_inc_unchecked(&sk->sk_drops);
80604 kfree_skb(skb);
80605 return -1;
80606 }
80607 @@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
80608 if (likely(skb1 == NULL))
80609 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
80610 if (!skb1) {
80611 - atomic_inc(&sk->sk_drops);
80612 + atomic_inc_unchecked(&sk->sk_drops);
80613 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
80614 IS_UDPLITE(sk));
80615 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
80616 @@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
80617 goto discard;
80618
80619 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
80620 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80621 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
80622 +#endif
80623 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
80624
80625 kfree_skb(skb);
80626 @@ -1473,7 +1480,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
80627 0,
80628 sock_i_ino(sp),
80629 atomic_read(&sp->sk_refcnt), sp,
80630 - atomic_read(&sp->sk_drops));
80631 + atomic_read_unchecked(&sp->sk_drops));
80632 }
80633
80634 int udp6_seq_show(struct seq_file *seq, void *v)
80635 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
80636 index 496ce2c..f79fac8 100644
80637 --- a/net/irda/ircomm/ircomm_tty.c
80638 +++ b/net/irda/ircomm/ircomm_tty.c
80639 @@ -311,12 +311,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80640 add_wait_queue(&port->open_wait, &wait);
80641
80642 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
80643 - __FILE__, __LINE__, tty->driver->name, port->count);
80644 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
80645
80646 spin_lock_irqsave(&port->lock, flags);
80647 if (!tty_hung_up_p(filp)) {
80648 extra_count = 1;
80649 - port->count--;
80650 + atomic_dec(&port->count);
80651 }
80652 spin_unlock_irqrestore(&port->lock, flags);
80653 port->blocked_open++;
80654 @@ -352,7 +352,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80655 }
80656
80657 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
80658 - __FILE__, __LINE__, tty->driver->name, port->count);
80659 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
80660
80661 schedule();
80662 }
80663 @@ -363,13 +363,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80664 if (extra_count) {
80665 /* ++ is not atomic, so this should be protected - Jean II */
80666 spin_lock_irqsave(&port->lock, flags);
80667 - port->count++;
80668 + atomic_inc(&port->count);
80669 spin_unlock_irqrestore(&port->lock, flags);
80670 }
80671 port->blocked_open--;
80672
80673 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
80674 - __FILE__, __LINE__, tty->driver->name, port->count);
80675 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
80676
80677 if (!retval)
80678 port->flags |= ASYNC_NORMAL_ACTIVE;
80679 @@ -443,12 +443,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
80680
80681 /* ++ is not atomic, so this should be protected - Jean II */
80682 spin_lock_irqsave(&self->port.lock, flags);
80683 - self->port.count++;
80684 + atomic_inc(&self->port.count);
80685 spin_unlock_irqrestore(&self->port.lock, flags);
80686 tty_port_tty_set(&self->port, tty);
80687
80688 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
80689 - self->line, self->port.count);
80690 + self->line, atomic_read(&self->port.count));
80691
80692 /* Not really used by us, but lets do it anyway */
80693 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
80694 @@ -985,7 +985,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
80695 tty_kref_put(port->tty);
80696 }
80697 port->tty = NULL;
80698 - port->count = 0;
80699 + atomic_set(&port->count, 0);
80700 spin_unlock_irqrestore(&port->lock, flags);
80701
80702 wake_up_interruptible(&port->open_wait);
80703 @@ -1342,7 +1342,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
80704 seq_putc(m, '\n');
80705
80706 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
80707 - seq_printf(m, "Open count: %d\n", self->port.count);
80708 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
80709 seq_printf(m, "Max data size: %d\n", self->max_data_size);
80710 seq_printf(m, "Max header size: %d\n", self->max_header_size);
80711
80712 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
80713 index cd6f7a9..e63fe89 100644
80714 --- a/net/iucv/af_iucv.c
80715 +++ b/net/iucv/af_iucv.c
80716 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
80717
80718 write_lock_bh(&iucv_sk_list.lock);
80719
80720 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
80721 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
80722 while (__iucv_get_sock_by_name(name)) {
80723 sprintf(name, "%08x",
80724 - atomic_inc_return(&iucv_sk_list.autobind_name));
80725 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
80726 }
80727
80728 write_unlock_bh(&iucv_sk_list.lock);
80729 diff --git a/net/key/af_key.c b/net/key/af_key.c
80730 index 08897a3..0b812ab 100644
80731 --- a/net/key/af_key.c
80732 +++ b/net/key/af_key.c
80733 @@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
80734 static u32 get_acqseq(void)
80735 {
80736 u32 res;
80737 - static atomic_t acqseq;
80738 + static atomic_unchecked_t acqseq;
80739
80740 do {
80741 - res = atomic_inc_return(&acqseq);
80742 + res = atomic_inc_return_unchecked(&acqseq);
80743 } while (!res);
80744 return res;
80745 }
80746 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
80747 index 494da7f..6ce2ffd 100644
80748 --- a/net/mac80211/cfg.c
80749 +++ b/net/mac80211/cfg.c
80750 @@ -2604,7 +2604,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
80751 else
80752 local->probe_req_reg--;
80753
80754 - if (!local->open_count)
80755 + if (!local_read(&local->open_count))
80756 break;
80757
80758 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
80759 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
80760 index 493e2e8..be76574 100644
80761 --- a/net/mac80211/ieee80211_i.h
80762 +++ b/net/mac80211/ieee80211_i.h
80763 @@ -28,6 +28,7 @@
80764 #include <net/ieee80211_radiotap.h>
80765 #include <net/cfg80211.h>
80766 #include <net/mac80211.h>
80767 +#include <asm/local.h>
80768 #include "key.h"
80769 #include "sta_info.h"
80770 #include "debug.h"
80771 @@ -852,7 +853,7 @@ struct ieee80211_local {
80772 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
80773 spinlock_t queue_stop_reason_lock;
80774
80775 - int open_count;
80776 + local_t open_count;
80777 int monitors, cooked_mntrs;
80778 /* number of interfaces with corresponding FIF_ flags */
80779 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
80780 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
80781 index 0f5af91..4dba9e7 100644
80782 --- a/net/mac80211/iface.c
80783 +++ b/net/mac80211/iface.c
80784 @@ -465,7 +465,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80785 break;
80786 }
80787
80788 - if (local->open_count == 0) {
80789 + if (local_read(&local->open_count) == 0) {
80790 res = drv_start(local);
80791 if (res)
80792 goto err_del_bss;
80793 @@ -508,7 +508,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80794 break;
80795 }
80796
80797 - if (local->monitors == 0 && local->open_count == 0) {
80798 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
80799 res = ieee80211_add_virtual_monitor(local);
80800 if (res)
80801 goto err_stop;
80802 @@ -616,7 +616,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80803 mutex_unlock(&local->mtx);
80804
80805 if (coming_up)
80806 - local->open_count++;
80807 + local_inc(&local->open_count);
80808
80809 if (hw_reconf_flags)
80810 ieee80211_hw_config(local, hw_reconf_flags);
80811 @@ -630,7 +630,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80812 err_del_interface:
80813 drv_remove_interface(local, sdata);
80814 err_stop:
80815 - if (!local->open_count)
80816 + if (!local_read(&local->open_count))
80817 drv_stop(local);
80818 err_del_bss:
80819 sdata->bss = NULL;
80820 @@ -762,7 +762,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
80821 }
80822
80823 if (going_down)
80824 - local->open_count--;
80825 + local_dec(&local->open_count);
80826
80827 switch (sdata->vif.type) {
80828 case NL80211_IFTYPE_AP_VLAN:
80829 @@ -818,7 +818,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
80830
80831 ieee80211_recalc_ps(local, -1);
80832
80833 - if (local->open_count == 0) {
80834 + if (local_read(&local->open_count) == 0) {
80835 if (local->ops->napi_poll)
80836 napi_disable(&local->napi);
80837 ieee80211_clear_tx_pending(local);
80838 @@ -850,7 +850,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
80839 }
80840 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
80841
80842 - if (local->monitors == local->open_count && local->monitors > 0)
80843 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
80844 ieee80211_add_virtual_monitor(local);
80845 }
80846
80847 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
80848 index f57f597..e0a7c03 100644
80849 --- a/net/mac80211/main.c
80850 +++ b/net/mac80211/main.c
80851 @@ -164,7 +164,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
80852 local->hw.conf.power_level = power;
80853 }
80854
80855 - if (changed && local->open_count) {
80856 + if (changed && local_read(&local->open_count)) {
80857 ret = drv_config(local, changed);
80858 /*
80859 * Goal:
80860 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
80861 index 5c572e7..ecf75ce 100644
80862 --- a/net/mac80211/pm.c
80863 +++ b/net/mac80211/pm.c
80864 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
80865 struct ieee80211_sub_if_data *sdata;
80866 struct sta_info *sta;
80867
80868 - if (!local->open_count)
80869 + if (!local_read(&local->open_count))
80870 goto suspend;
80871
80872 ieee80211_scan_cancel(local);
80873 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
80874 cancel_work_sync(&local->dynamic_ps_enable_work);
80875 del_timer_sync(&local->dynamic_ps_timer);
80876
80877 - local->wowlan = wowlan && local->open_count;
80878 + local->wowlan = wowlan && local_read(&local->open_count);
80879 if (local->wowlan) {
80880 int err = drv_suspend(local, wowlan);
80881 if (err < 0) {
80882 @@ -143,7 +143,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
80883 drv_remove_interface(local, sdata);
80884
80885 /* stop hardware - this must stop RX */
80886 - if (local->open_count)
80887 + if (local_read(&local->open_count))
80888 ieee80211_stop_device(local);
80889
80890 suspend:
80891 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
80892 index 3313c11..bec9f17 100644
80893 --- a/net/mac80211/rate.c
80894 +++ b/net/mac80211/rate.c
80895 @@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
80896
80897 ASSERT_RTNL();
80898
80899 - if (local->open_count)
80900 + if (local_read(&local->open_count))
80901 return -EBUSY;
80902
80903 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
80904 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
80905 index c97a065..ff61928 100644
80906 --- a/net/mac80211/rc80211_pid_debugfs.c
80907 +++ b/net/mac80211/rc80211_pid_debugfs.c
80908 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
80909
80910 spin_unlock_irqrestore(&events->lock, status);
80911
80912 - if (copy_to_user(buf, pb, p))
80913 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
80914 return -EFAULT;
80915
80916 return p;
80917 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
80918 index 0151ae3..26709d3 100644
80919 --- a/net/mac80211/util.c
80920 +++ b/net/mac80211/util.c
80921 @@ -1332,7 +1332,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
80922 }
80923 #endif
80924 /* everything else happens only if HW was up & running */
80925 - if (!local->open_count)
80926 + if (!local_read(&local->open_count))
80927 goto wake_up;
80928
80929 /*
80930 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
80931 index 49e96df..63a51c3 100644
80932 --- a/net/netfilter/Kconfig
80933 +++ b/net/netfilter/Kconfig
80934 @@ -936,6 +936,16 @@ config NETFILTER_XT_MATCH_ESP
80935
80936 To compile it as a module, choose M here. If unsure, say N.
80937
80938 +config NETFILTER_XT_MATCH_GRADM
80939 + tristate '"gradm" match support'
80940 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
80941 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
80942 + ---help---
80943 + The gradm match allows to match on grsecurity RBAC being enabled.
80944 + It is useful when iptables rules are applied early on bootup to
80945 + prevent connections to the machine (except from a trusted host)
80946 + while the RBAC system is disabled.
80947 +
80948 config NETFILTER_XT_MATCH_HASHLIMIT
80949 tristate '"hashlimit" match support'
80950 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
80951 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
80952 index 3259697..54d5393 100644
80953 --- a/net/netfilter/Makefile
80954 +++ b/net/netfilter/Makefile
80955 @@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
80956 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
80957 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
80958 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
80959 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
80960 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
80961 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
80962 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
80963 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
80964 index 1548df9..98ad9b4 100644
80965 --- a/net/netfilter/ipvs/ip_vs_conn.c
80966 +++ b/net/netfilter/ipvs/ip_vs_conn.c
80967 @@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
80968 /* Increase the refcnt counter of the dest */
80969 atomic_inc(&dest->refcnt);
80970
80971 - conn_flags = atomic_read(&dest->conn_flags);
80972 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
80973 if (cp->protocol != IPPROTO_UDP)
80974 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
80975 flags = cp->flags;
80976 @@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
80977 atomic_set(&cp->refcnt, 1);
80978
80979 atomic_set(&cp->n_control, 0);
80980 - atomic_set(&cp->in_pkts, 0);
80981 + atomic_set_unchecked(&cp->in_pkts, 0);
80982
80983 atomic_inc(&ipvs->conn_count);
80984 if (flags & IP_VS_CONN_F_NO_CPORT)
80985 @@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
80986
80987 /* Don't drop the entry if its number of incoming packets is not
80988 located in [0, 8] */
80989 - i = atomic_read(&cp->in_pkts);
80990 + i = atomic_read_unchecked(&cp->in_pkts);
80991 if (i > 8 || i < 0) return 0;
80992
80993 if (!todrop_rate[i]) return 0;
80994 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
80995 index 58918e2..4d177a9 100644
80996 --- a/net/netfilter/ipvs/ip_vs_core.c
80997 +++ b/net/netfilter/ipvs/ip_vs_core.c
80998 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
80999 ret = cp->packet_xmit(skb, cp, pd->pp);
81000 /* do not touch skb anymore */
81001
81002 - atomic_inc(&cp->in_pkts);
81003 + atomic_inc_unchecked(&cp->in_pkts);
81004 ip_vs_conn_put(cp);
81005 return ret;
81006 }
81007 @@ -1681,7 +1681,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
81008 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
81009 pkts = sysctl_sync_threshold(ipvs);
81010 else
81011 - pkts = atomic_add_return(1, &cp->in_pkts);
81012 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
81013
81014 if (ipvs->sync_state & IP_VS_STATE_MASTER)
81015 ip_vs_sync_conn(net, cp, pkts);
81016 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
81017 index c4ee437..a774a74 100644
81018 --- a/net/netfilter/ipvs/ip_vs_ctl.c
81019 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
81020 @@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
81021 ip_vs_rs_hash(ipvs, dest);
81022 write_unlock_bh(&ipvs->rs_lock);
81023 }
81024 - atomic_set(&dest->conn_flags, conn_flags);
81025 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
81026
81027 /* bind the service */
81028 if (!dest->svc) {
81029 @@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
81030 " %-7s %-6d %-10d %-10d\n",
81031 &dest->addr.in6,
81032 ntohs(dest->port),
81033 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
81034 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
81035 atomic_read(&dest->weight),
81036 atomic_read(&dest->activeconns),
81037 atomic_read(&dest->inactconns));
81038 @@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
81039 "%-7s %-6d %-10d %-10d\n",
81040 ntohl(dest->addr.ip),
81041 ntohs(dest->port),
81042 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
81043 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
81044 atomic_read(&dest->weight),
81045 atomic_read(&dest->activeconns),
81046 atomic_read(&dest->inactconns));
81047 @@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
81048
81049 entry.addr = dest->addr.ip;
81050 entry.port = dest->port;
81051 - entry.conn_flags = atomic_read(&dest->conn_flags);
81052 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
81053 entry.weight = atomic_read(&dest->weight);
81054 entry.u_threshold = dest->u_threshold;
81055 entry.l_threshold = dest->l_threshold;
81056 @@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
81057 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
81058 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
81059 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
81060 - (atomic_read(&dest->conn_flags) &
81061 + (atomic_read_unchecked(&dest->conn_flags) &
81062 IP_VS_CONN_F_FWD_MASK)) ||
81063 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
81064 atomic_read(&dest->weight)) ||
81065 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
81066 index effa10c..9058928 100644
81067 --- a/net/netfilter/ipvs/ip_vs_sync.c
81068 +++ b/net/netfilter/ipvs/ip_vs_sync.c
81069 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
81070 cp = cp->control;
81071 if (cp) {
81072 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
81073 - pkts = atomic_add_return(1, &cp->in_pkts);
81074 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
81075 else
81076 pkts = sysctl_sync_threshold(ipvs);
81077 ip_vs_sync_conn(net, cp->control, pkts);
81078 @@ -758,7 +758,7 @@ control:
81079 if (!cp)
81080 return;
81081 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
81082 - pkts = atomic_add_return(1, &cp->in_pkts);
81083 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
81084 else
81085 pkts = sysctl_sync_threshold(ipvs);
81086 goto sloop;
81087 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
81088
81089 if (opt)
81090 memcpy(&cp->in_seq, opt, sizeof(*opt));
81091 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
81092 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
81093 cp->state = state;
81094 cp->old_state = cp->state;
81095 /*
81096 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
81097 index cc4c809..50f8fe5 100644
81098 --- a/net/netfilter/ipvs/ip_vs_xmit.c
81099 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
81100 @@ -1202,7 +1202,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
81101 else
81102 rc = NF_ACCEPT;
81103 /* do not touch skb anymore */
81104 - atomic_inc(&cp->in_pkts);
81105 + atomic_inc_unchecked(&cp->in_pkts);
81106 goto out;
81107 }
81108
81109 @@ -1323,7 +1323,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
81110 else
81111 rc = NF_ACCEPT;
81112 /* do not touch skb anymore */
81113 - atomic_inc(&cp->in_pkts);
81114 + atomic_inc_unchecked(&cp->in_pkts);
81115 goto out;
81116 }
81117
81118 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
81119 index ec02168..f0caab6 100644
81120 --- a/net/netfilter/nf_conntrack_core.c
81121 +++ b/net/netfilter/nf_conntrack_core.c
81122 @@ -1533,6 +1533,10 @@ err_extend:
81123 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
81124 #define DYING_NULLS_VAL ((1<<30)+1)
81125
81126 +#ifdef CONFIG_GRKERNSEC_HIDESYM
81127 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
81128 +#endif
81129 +
81130 static int nf_conntrack_init_net(struct net *net)
81131 {
81132 int ret;
81133 @@ -1546,7 +1550,11 @@ static int nf_conntrack_init_net(struct net *net)
81134 goto err_stat;
81135 }
81136
81137 +#ifdef CONFIG_GRKERNSEC_HIDESYM
81138 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
81139 +#else
81140 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
81141 +#endif
81142 if (!net->ct.slabname) {
81143 ret = -ENOMEM;
81144 goto err_slabname;
81145 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
81146 index 92fd8ec..3f6ea4b 100644
81147 --- a/net/netfilter/nfnetlink_log.c
81148 +++ b/net/netfilter/nfnetlink_log.c
81149 @@ -72,7 +72,7 @@ struct nfulnl_instance {
81150 };
81151
81152 static DEFINE_SPINLOCK(instances_lock);
81153 -static atomic_t global_seq;
81154 +static atomic_unchecked_t global_seq;
81155
81156 #define INSTANCE_BUCKETS 16
81157 static struct hlist_head instance_table[INSTANCE_BUCKETS];
81158 @@ -537,7 +537,7 @@ __build_packet_message(struct nfulnl_instance *inst,
81159 /* global sequence number */
81160 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
81161 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
81162 - htonl(atomic_inc_return(&global_seq))))
81163 + htonl(atomic_inc_return_unchecked(&global_seq))))
81164 goto nla_put_failure;
81165
81166 if (data_len) {
81167 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
81168 new file mode 100644
81169 index 0000000..c566332
81170 --- /dev/null
81171 +++ b/net/netfilter/xt_gradm.c
81172 @@ -0,0 +1,51 @@
81173 +/*
81174 + * gradm match for netfilter
81175 + * Copyright © Zbigniew Krzystolik, 2010
81176 + *
81177 + * This program is free software; you can redistribute it and/or modify
81178 + * it under the terms of the GNU General Public License; either version
81179 + * 2 or 3 as published by the Free Software Foundation.
81180 + */
81181 +#include <linux/module.h>
81182 +#include <linux/moduleparam.h>
81183 +#include <linux/skbuff.h>
81184 +#include <linux/netfilter/x_tables.h>
81185 +#include <linux/grsecurity.h>
81186 +#include <linux/netfilter/xt_gradm.h>
81187 +
81188 +static bool
81189 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
81190 +{
81191 + const struct xt_gradm_mtinfo *info = par->matchinfo;
81192 + bool retval = false;
81193 + if (gr_acl_is_enabled())
81194 + retval = true;
81195 + return retval ^ info->invflags;
81196 +}
81197 +
81198 +static struct xt_match gradm_mt_reg __read_mostly = {
81199 + .name = "gradm",
81200 + .revision = 0,
81201 + .family = NFPROTO_UNSPEC,
81202 + .match = gradm_mt,
81203 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
81204 + .me = THIS_MODULE,
81205 +};
81206 +
81207 +static int __init gradm_mt_init(void)
81208 +{
81209 + return xt_register_match(&gradm_mt_reg);
81210 +}
81211 +
81212 +static void __exit gradm_mt_exit(void)
81213 +{
81214 + xt_unregister_match(&gradm_mt_reg);
81215 +}
81216 +
81217 +module_init(gradm_mt_init);
81218 +module_exit(gradm_mt_exit);
81219 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
81220 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
81221 +MODULE_LICENSE("GPL");
81222 +MODULE_ALIAS("ipt_gradm");
81223 +MODULE_ALIAS("ip6t_gradm");
81224 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
81225 index 4fe4fb4..87a89e5 100644
81226 --- a/net/netfilter/xt_statistic.c
81227 +++ b/net/netfilter/xt_statistic.c
81228 @@ -19,7 +19,7 @@
81229 #include <linux/module.h>
81230
81231 struct xt_statistic_priv {
81232 - atomic_t count;
81233 + atomic_unchecked_t count;
81234 } ____cacheline_aligned_in_smp;
81235
81236 MODULE_LICENSE("GPL");
81237 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
81238 break;
81239 case XT_STATISTIC_MODE_NTH:
81240 do {
81241 - oval = atomic_read(&info->master->count);
81242 + oval = atomic_read_unchecked(&info->master->count);
81243 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
81244 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
81245 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
81246 if (nval == 0)
81247 ret = !ret;
81248 break;
81249 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
81250 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
81251 if (info->master == NULL)
81252 return -ENOMEM;
81253 - atomic_set(&info->master->count, info->u.nth.count);
81254 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
81255
81256 return 0;
81257 }
81258 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
81259 index 4da797f..eb1df70 100644
81260 --- a/net/netlink/af_netlink.c
81261 +++ b/net/netlink/af_netlink.c
81262 @@ -782,7 +782,7 @@ static void netlink_overrun(struct sock *sk)
81263 sk->sk_error_report(sk);
81264 }
81265 }
81266 - atomic_inc(&sk->sk_drops);
81267 + atomic_inc_unchecked(&sk->sk_drops);
81268 }
81269
81270 static struct sock *netlink_getsockbyportid(struct sock *ssk, u32 portid)
81271 @@ -2068,7 +2068,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
81272 sk_wmem_alloc_get(s),
81273 nlk->cb,
81274 atomic_read(&s->sk_refcnt),
81275 - atomic_read(&s->sk_drops),
81276 + atomic_read_unchecked(&s->sk_drops),
81277 sock_i_ino(s)
81278 );
81279
81280 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
81281 index 7261eb8..44e8ac6 100644
81282 --- a/net/netrom/af_netrom.c
81283 +++ b/net/netrom/af_netrom.c
81284 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
81285 struct sock *sk = sock->sk;
81286 struct nr_sock *nr = nr_sk(sk);
81287
81288 + memset(sax, 0, sizeof(*sax));
81289 lock_sock(sk);
81290 if (peer != 0) {
81291 if (sk->sk_state != TCP_ESTABLISHED) {
81292 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
81293 *uaddr_len = sizeof(struct full_sockaddr_ax25);
81294 } else {
81295 sax->fsa_ax25.sax25_family = AF_NETROM;
81296 - sax->fsa_ax25.sax25_ndigis = 0;
81297 sax->fsa_ax25.sax25_call = nr->source_addr;
81298 *uaddr_len = sizeof(struct sockaddr_ax25);
81299 }
81300 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
81301 index 94060ed..c9bf90e 100644
81302 --- a/net/packet/af_packet.c
81303 +++ b/net/packet/af_packet.c
81304 @@ -1578,7 +1578,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
81305
81306 spin_lock(&sk->sk_receive_queue.lock);
81307 po->stats.tp_packets++;
81308 - skb->dropcount = atomic_read(&sk->sk_drops);
81309 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
81310 __skb_queue_tail(&sk->sk_receive_queue, skb);
81311 spin_unlock(&sk->sk_receive_queue.lock);
81312 sk->sk_data_ready(sk, skb->len);
81313 @@ -1587,7 +1587,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
81314 drop_n_acct:
81315 spin_lock(&sk->sk_receive_queue.lock);
81316 po->stats.tp_drops++;
81317 - atomic_inc(&sk->sk_drops);
81318 + atomic_inc_unchecked(&sk->sk_drops);
81319 spin_unlock(&sk->sk_receive_queue.lock);
81320
81321 drop_n_restore:
81322 @@ -2335,13 +2335,15 @@ static int packet_release(struct socket *sock)
81323
81324 packet_flush_mclist(sk);
81325
81326 - memset(&req_u, 0, sizeof(req_u));
81327 -
81328 - if (po->rx_ring.pg_vec)
81329 + if (po->rx_ring.pg_vec) {
81330 + memset(&req_u, 0, sizeof(req_u));
81331 packet_set_ring(sk, &req_u, 1, 0);
81332 + }
81333
81334 - if (po->tx_ring.pg_vec)
81335 + if (po->tx_ring.pg_vec) {
81336 + memset(&req_u, 0, sizeof(req_u));
81337 packet_set_ring(sk, &req_u, 1, 1);
81338 + }
81339
81340 fanout_release(sk);
81341
81342 @@ -2537,6 +2539,7 @@ out:
81343
81344 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
81345 {
81346 + struct sock_extended_err ee;
81347 struct sock_exterr_skb *serr;
81348 struct sk_buff *skb, *skb2;
81349 int copied, err;
81350 @@ -2558,8 +2561,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
81351 sock_recv_timestamp(msg, sk, skb);
81352
81353 serr = SKB_EXT_ERR(skb);
81354 + ee = serr->ee;
81355 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
81356 - sizeof(serr->ee), &serr->ee);
81357 + sizeof ee, &ee);
81358
81359 msg->msg_flags |= MSG_ERRQUEUE;
81360 err = copied;
81361 @@ -3171,7 +3175,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
81362 case PACKET_HDRLEN:
81363 if (len > sizeof(int))
81364 len = sizeof(int);
81365 - if (copy_from_user(&val, optval, len))
81366 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
81367 return -EFAULT;
81368 switch (val) {
81369 case TPACKET_V1:
81370 @@ -3210,7 +3214,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
81371 len = lv;
81372 if (put_user(len, optlen))
81373 return -EFAULT;
81374 - if (copy_to_user(optval, data, len))
81375 + if (len > sizeof(st) || copy_to_user(optval, data, len))
81376 return -EFAULT;
81377 return 0;
81378 }
81379 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
81380 index 5a940db..f0b9c12 100644
81381 --- a/net/phonet/af_phonet.c
81382 +++ b/net/phonet/af_phonet.c
81383 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
81384 {
81385 struct phonet_protocol *pp;
81386
81387 - if (protocol >= PHONET_NPROTO)
81388 + if (protocol < 0 || protocol >= PHONET_NPROTO)
81389 return NULL;
81390
81391 rcu_read_lock();
81392 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
81393 {
81394 int err = 0;
81395
81396 - if (protocol >= PHONET_NPROTO)
81397 + if (protocol < 0 || protocol >= PHONET_NPROTO)
81398 return -EINVAL;
81399
81400 err = proto_register(pp->prot, 1);
81401 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
81402 index 576f22c..bc7a71b 100644
81403 --- a/net/phonet/pep.c
81404 +++ b/net/phonet/pep.c
81405 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
81406
81407 case PNS_PEP_CTRL_REQ:
81408 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
81409 - atomic_inc(&sk->sk_drops);
81410 + atomic_inc_unchecked(&sk->sk_drops);
81411 break;
81412 }
81413 __skb_pull(skb, 4);
81414 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
81415 }
81416
81417 if (pn->rx_credits == 0) {
81418 - atomic_inc(&sk->sk_drops);
81419 + atomic_inc_unchecked(&sk->sk_drops);
81420 err = -ENOBUFS;
81421 break;
81422 }
81423 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
81424 }
81425
81426 if (pn->rx_credits == 0) {
81427 - atomic_inc(&sk->sk_drops);
81428 + atomic_inc_unchecked(&sk->sk_drops);
81429 err = NET_RX_DROP;
81430 break;
81431 }
81432 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
81433 index b7e9827..c264c85 100644
81434 --- a/net/phonet/socket.c
81435 +++ b/net/phonet/socket.c
81436 @@ -615,7 +615,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
81437 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
81438 sock_i_ino(sk),
81439 atomic_read(&sk->sk_refcnt), sk,
81440 - atomic_read(&sk->sk_drops), &len);
81441 + atomic_read_unchecked(&sk->sk_drops), &len);
81442 }
81443 seq_printf(seq, "%*s\n", 127 - len, "");
81444 return 0;
81445 diff --git a/net/rds/cong.c b/net/rds/cong.c
81446 index e5b65ac..f3b6fb7 100644
81447 --- a/net/rds/cong.c
81448 +++ b/net/rds/cong.c
81449 @@ -78,7 +78,7 @@
81450 * finds that the saved generation number is smaller than the global generation
81451 * number, it wakes up the process.
81452 */
81453 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
81454 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
81455
81456 /*
81457 * Congestion monitoring
81458 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
81459 rdsdebug("waking map %p for %pI4\n",
81460 map, &map->m_addr);
81461 rds_stats_inc(s_cong_update_received);
81462 - atomic_inc(&rds_cong_generation);
81463 + atomic_inc_unchecked(&rds_cong_generation);
81464 if (waitqueue_active(&map->m_waitq))
81465 wake_up(&map->m_waitq);
81466 if (waitqueue_active(&rds_poll_waitq))
81467 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
81468
81469 int rds_cong_updated_since(unsigned long *recent)
81470 {
81471 - unsigned long gen = atomic_read(&rds_cong_generation);
81472 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
81473
81474 if (likely(*recent == gen))
81475 return 0;
81476 diff --git a/net/rds/ib.h b/net/rds/ib.h
81477 index 8d2b3d5..227ec5b 100644
81478 --- a/net/rds/ib.h
81479 +++ b/net/rds/ib.h
81480 @@ -128,7 +128,7 @@ struct rds_ib_connection {
81481 /* sending acks */
81482 unsigned long i_ack_flags;
81483 #ifdef KERNEL_HAS_ATOMIC64
81484 - atomic64_t i_ack_next; /* next ACK to send */
81485 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
81486 #else
81487 spinlock_t i_ack_lock; /* protect i_ack_next */
81488 u64 i_ack_next; /* next ACK to send */
81489 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
81490 index a1e1162..265e129 100644
81491 --- a/net/rds/ib_cm.c
81492 +++ b/net/rds/ib_cm.c
81493 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
81494 /* Clear the ACK state */
81495 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
81496 #ifdef KERNEL_HAS_ATOMIC64
81497 - atomic64_set(&ic->i_ack_next, 0);
81498 + atomic64_set_unchecked(&ic->i_ack_next, 0);
81499 #else
81500 ic->i_ack_next = 0;
81501 #endif
81502 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
81503 index 8d19491..05a3e65 100644
81504 --- a/net/rds/ib_recv.c
81505 +++ b/net/rds/ib_recv.c
81506 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
81507 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
81508 int ack_required)
81509 {
81510 - atomic64_set(&ic->i_ack_next, seq);
81511 + atomic64_set_unchecked(&ic->i_ack_next, seq);
81512 if (ack_required) {
81513 smp_mb__before_clear_bit();
81514 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
81515 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
81516 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
81517 smp_mb__after_clear_bit();
81518
81519 - return atomic64_read(&ic->i_ack_next);
81520 + return atomic64_read_unchecked(&ic->i_ack_next);
81521 }
81522 #endif
81523
81524 diff --git a/net/rds/iw.h b/net/rds/iw.h
81525 index 04ce3b1..48119a6 100644
81526 --- a/net/rds/iw.h
81527 +++ b/net/rds/iw.h
81528 @@ -134,7 +134,7 @@ struct rds_iw_connection {
81529 /* sending acks */
81530 unsigned long i_ack_flags;
81531 #ifdef KERNEL_HAS_ATOMIC64
81532 - atomic64_t i_ack_next; /* next ACK to send */
81533 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
81534 #else
81535 spinlock_t i_ack_lock; /* protect i_ack_next */
81536 u64 i_ack_next; /* next ACK to send */
81537 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
81538 index a91e1db..cf3053f 100644
81539 --- a/net/rds/iw_cm.c
81540 +++ b/net/rds/iw_cm.c
81541 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
81542 /* Clear the ACK state */
81543 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
81544 #ifdef KERNEL_HAS_ATOMIC64
81545 - atomic64_set(&ic->i_ack_next, 0);
81546 + atomic64_set_unchecked(&ic->i_ack_next, 0);
81547 #else
81548 ic->i_ack_next = 0;
81549 #endif
81550 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
81551 index 4503335..db566b4 100644
81552 --- a/net/rds/iw_recv.c
81553 +++ b/net/rds/iw_recv.c
81554 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
81555 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
81556 int ack_required)
81557 {
81558 - atomic64_set(&ic->i_ack_next, seq);
81559 + atomic64_set_unchecked(&ic->i_ack_next, seq);
81560 if (ack_required) {
81561 smp_mb__before_clear_bit();
81562 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
81563 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
81564 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
81565 smp_mb__after_clear_bit();
81566
81567 - return atomic64_read(&ic->i_ack_next);
81568 + return atomic64_read_unchecked(&ic->i_ack_next);
81569 }
81570 #endif
81571
81572 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
81573 index edac9ef..16bcb98 100644
81574 --- a/net/rds/tcp.c
81575 +++ b/net/rds/tcp.c
81576 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
81577 int val = 1;
81578
81579 set_fs(KERNEL_DS);
81580 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
81581 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
81582 sizeof(val));
81583 set_fs(oldfs);
81584 }
81585 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
81586 index 81cf5a4..b5826ff 100644
81587 --- a/net/rds/tcp_send.c
81588 +++ b/net/rds/tcp_send.c
81589 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
81590
81591 oldfs = get_fs();
81592 set_fs(KERNEL_DS);
81593 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
81594 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
81595 sizeof(val));
81596 set_fs(oldfs);
81597 }
81598 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
81599 index 05996d0..5a1dfe0 100644
81600 --- a/net/rxrpc/af_rxrpc.c
81601 +++ b/net/rxrpc/af_rxrpc.c
81602 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
81603 __be32 rxrpc_epoch;
81604
81605 /* current debugging ID */
81606 -atomic_t rxrpc_debug_id;
81607 +atomic_unchecked_t rxrpc_debug_id;
81608
81609 /* count of skbs currently in use */
81610 atomic_t rxrpc_n_skbs;
81611 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
81612 index e4d9cbc..b229649 100644
81613 --- a/net/rxrpc/ar-ack.c
81614 +++ b/net/rxrpc/ar-ack.c
81615 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
81616
81617 _enter("{%d,%d,%d,%d},",
81618 call->acks_hard, call->acks_unacked,
81619 - atomic_read(&call->sequence),
81620 + atomic_read_unchecked(&call->sequence),
81621 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
81622
81623 stop = 0;
81624 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
81625
81626 /* each Tx packet has a new serial number */
81627 sp->hdr.serial =
81628 - htonl(atomic_inc_return(&call->conn->serial));
81629 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
81630
81631 hdr = (struct rxrpc_header *) txb->head;
81632 hdr->serial = sp->hdr.serial;
81633 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
81634 */
81635 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
81636 {
81637 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
81638 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
81639 }
81640
81641 /*
81642 @@ -629,7 +629,7 @@ process_further:
81643
81644 latest = ntohl(sp->hdr.serial);
81645 hard = ntohl(ack.firstPacket);
81646 - tx = atomic_read(&call->sequence);
81647 + tx = atomic_read_unchecked(&call->sequence);
81648
81649 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
81650 latest,
81651 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
81652 goto maybe_reschedule;
81653
81654 send_ACK_with_skew:
81655 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
81656 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
81657 ntohl(ack.serial));
81658 send_ACK:
81659 mtu = call->conn->trans->peer->if_mtu;
81660 @@ -1173,7 +1173,7 @@ send_ACK:
81661 ackinfo.rxMTU = htonl(5692);
81662 ackinfo.jumbo_max = htonl(4);
81663
81664 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
81665 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
81666 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
81667 ntohl(hdr.serial),
81668 ntohs(ack.maxSkew),
81669 @@ -1191,7 +1191,7 @@ send_ACK:
81670 send_message:
81671 _debug("send message");
81672
81673 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
81674 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
81675 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
81676 send_message_2:
81677
81678 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
81679 index a3bbb36..3341fb9 100644
81680 --- a/net/rxrpc/ar-call.c
81681 +++ b/net/rxrpc/ar-call.c
81682 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
81683 spin_lock_init(&call->lock);
81684 rwlock_init(&call->state_lock);
81685 atomic_set(&call->usage, 1);
81686 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
81687 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
81688 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
81689
81690 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
81691 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
81692 index 4106ca9..a338d7a 100644
81693 --- a/net/rxrpc/ar-connection.c
81694 +++ b/net/rxrpc/ar-connection.c
81695 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
81696 rwlock_init(&conn->lock);
81697 spin_lock_init(&conn->state_lock);
81698 atomic_set(&conn->usage, 1);
81699 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
81700 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
81701 conn->avail_calls = RXRPC_MAXCALLS;
81702 conn->size_align = 4;
81703 conn->header_size = sizeof(struct rxrpc_header);
81704 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
81705 index e7ed43a..6afa140 100644
81706 --- a/net/rxrpc/ar-connevent.c
81707 +++ b/net/rxrpc/ar-connevent.c
81708 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
81709
81710 len = iov[0].iov_len + iov[1].iov_len;
81711
81712 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
81713 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
81714 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
81715
81716 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
81717 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
81718 index 529572f..c758ca7 100644
81719 --- a/net/rxrpc/ar-input.c
81720 +++ b/net/rxrpc/ar-input.c
81721 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
81722 /* track the latest serial number on this connection for ACK packet
81723 * information */
81724 serial = ntohl(sp->hdr.serial);
81725 - hi_serial = atomic_read(&call->conn->hi_serial);
81726 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
81727 while (serial > hi_serial)
81728 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
81729 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
81730 serial);
81731
81732 /* request ACK generation for any ACK or DATA packet that requests
81733 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
81734 index a693aca..81e7293 100644
81735 --- a/net/rxrpc/ar-internal.h
81736 +++ b/net/rxrpc/ar-internal.h
81737 @@ -272,8 +272,8 @@ struct rxrpc_connection {
81738 int error; /* error code for local abort */
81739 int debug_id; /* debug ID for printks */
81740 unsigned int call_counter; /* call ID counter */
81741 - atomic_t serial; /* packet serial number counter */
81742 - atomic_t hi_serial; /* highest serial number received */
81743 + atomic_unchecked_t serial; /* packet serial number counter */
81744 + atomic_unchecked_t hi_serial; /* highest serial number received */
81745 u8 avail_calls; /* number of calls available */
81746 u8 size_align; /* data size alignment (for security) */
81747 u8 header_size; /* rxrpc + security header size */
81748 @@ -346,7 +346,7 @@ struct rxrpc_call {
81749 spinlock_t lock;
81750 rwlock_t state_lock; /* lock for state transition */
81751 atomic_t usage;
81752 - atomic_t sequence; /* Tx data packet sequence counter */
81753 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
81754 u32 abort_code; /* local/remote abort code */
81755 enum { /* current state of call */
81756 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
81757 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
81758 */
81759 extern atomic_t rxrpc_n_skbs;
81760 extern __be32 rxrpc_epoch;
81761 -extern atomic_t rxrpc_debug_id;
81762 +extern atomic_unchecked_t rxrpc_debug_id;
81763 extern struct workqueue_struct *rxrpc_workqueue;
81764
81765 /*
81766 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
81767 index 87f7135..74d3703 100644
81768 --- a/net/rxrpc/ar-local.c
81769 +++ b/net/rxrpc/ar-local.c
81770 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
81771 spin_lock_init(&local->lock);
81772 rwlock_init(&local->services_lock);
81773 atomic_set(&local->usage, 1);
81774 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
81775 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
81776 memcpy(&local->srx, srx, sizeof(*srx));
81777 }
81778
81779 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
81780 index e1ac183..b43e10e 100644
81781 --- a/net/rxrpc/ar-output.c
81782 +++ b/net/rxrpc/ar-output.c
81783 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
81784 sp->hdr.cid = call->cid;
81785 sp->hdr.callNumber = call->call_id;
81786 sp->hdr.seq =
81787 - htonl(atomic_inc_return(&call->sequence));
81788 + htonl(atomic_inc_return_unchecked(&call->sequence));
81789 sp->hdr.serial =
81790 - htonl(atomic_inc_return(&conn->serial));
81791 + htonl(atomic_inc_return_unchecked(&conn->serial));
81792 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
81793 sp->hdr.userStatus = 0;
81794 sp->hdr.securityIndex = conn->security_ix;
81795 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
81796 index bebaa43..2644591 100644
81797 --- a/net/rxrpc/ar-peer.c
81798 +++ b/net/rxrpc/ar-peer.c
81799 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
81800 INIT_LIST_HEAD(&peer->error_targets);
81801 spin_lock_init(&peer->lock);
81802 atomic_set(&peer->usage, 1);
81803 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
81804 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
81805 memcpy(&peer->srx, srx, sizeof(*srx));
81806
81807 rxrpc_assess_MTU_size(peer);
81808 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
81809 index 38047f7..9f48511 100644
81810 --- a/net/rxrpc/ar-proc.c
81811 +++ b/net/rxrpc/ar-proc.c
81812 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
81813 atomic_read(&conn->usage),
81814 rxrpc_conn_states[conn->state],
81815 key_serial(conn->key),
81816 - atomic_read(&conn->serial),
81817 - atomic_read(&conn->hi_serial));
81818 + atomic_read_unchecked(&conn->serial),
81819 + atomic_read_unchecked(&conn->hi_serial));
81820
81821 return 0;
81822 }
81823 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
81824 index 92df566..87ec1bf 100644
81825 --- a/net/rxrpc/ar-transport.c
81826 +++ b/net/rxrpc/ar-transport.c
81827 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
81828 spin_lock_init(&trans->client_lock);
81829 rwlock_init(&trans->conn_lock);
81830 atomic_set(&trans->usage, 1);
81831 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
81832 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
81833
81834 if (peer->srx.transport.family == AF_INET) {
81835 switch (peer->srx.transport_type) {
81836 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
81837 index f226709..0e735a8 100644
81838 --- a/net/rxrpc/rxkad.c
81839 +++ b/net/rxrpc/rxkad.c
81840 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
81841
81842 len = iov[0].iov_len + iov[1].iov_len;
81843
81844 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
81845 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
81846 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
81847
81848 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
81849 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
81850
81851 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
81852
81853 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
81854 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
81855 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
81856
81857 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
81858 diff --git a/net/sctp/auth.c b/net/sctp/auth.c
81859 index 159b9bc..d8420ae 100644
81860 --- a/net/sctp/auth.c
81861 +++ b/net/sctp/auth.c
81862 @@ -71,7 +71,7 @@ void sctp_auth_key_put(struct sctp_auth_bytes *key)
81863 return;
81864
81865 if (atomic_dec_and_test(&key->refcnt)) {
81866 - kfree(key);
81867 + kzfree(key);
81868 SCTP_DBG_OBJCNT_DEC(keys);
81869 }
81870 }
81871 diff --git a/net/sctp/endpointola.c b/net/sctp/endpointola.c
81872 index 1859e2b..80a7264 100644
81873 --- a/net/sctp/endpointola.c
81874 +++ b/net/sctp/endpointola.c
81875 @@ -249,6 +249,8 @@ void sctp_endpoint_free(struct sctp_endpoint *ep)
81876 /* Final destructor for endpoint. */
81877 static void sctp_endpoint_destroy(struct sctp_endpoint *ep)
81878 {
81879 + int i;
81880 +
81881 SCTP_ASSERT(ep->base.dead, "Endpoint is not dead", return);
81882
81883 /* Free up the HMAC transform. */
81884 @@ -271,6 +273,9 @@ static void sctp_endpoint_destroy(struct sctp_endpoint *ep)
81885 sctp_inq_free(&ep->base.inqueue);
81886 sctp_bind_addr_free(&ep->base.bind_addr);
81887
81888 + for (i = 0; i < SCTP_HOW_MANY_SECRETS; ++i)
81889 + memset(&ep->secret_key[i], 0, SCTP_SECRET_SIZE);
81890 +
81891 /* Remove and free the port */
81892 if (sctp_sk(ep->base.sk)->bind_hash)
81893 sctp_put_port(ep->base.sk);
81894 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
81895 index ea14cb4..834e8e4 100644
81896 --- a/net/sctp/ipv6.c
81897 +++ b/net/sctp/ipv6.c
81898 @@ -1037,7 +1037,7 @@ void sctp_v6_pf_init(void)
81899
81900 void sctp_v6_pf_exit(void)
81901 {
81902 - list_del(&sctp_af_inet6.list);
81903 + pax_list_del((struct list_head *)&sctp_af_inet6.list);
81904 }
81905
81906 /* Initialize IPv6 support and register with socket layer. */
81907 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
81908 index 9966e7b..540c575 100644
81909 --- a/net/sctp/proc.c
81910 +++ b/net/sctp/proc.c
81911 @@ -328,7 +328,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
81912 seq_printf(seq,
81913 "%8pK %8pK %-3d %-3d %-2d %-4d "
81914 "%4d %8d %8d %7d %5lu %-5d %5d ",
81915 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
81916 + assoc, sk,
81917 + sctp_sk(sk)->type, sk->sk_state,
81918 assoc->state, hash,
81919 assoc->assoc_id,
81920 assoc->sndbuf_used,
81921 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
81922 index 2d51842..150ba5c 100644
81923 --- a/net/sctp/protocol.c
81924 +++ b/net/sctp/protocol.c
81925 @@ -834,8 +834,10 @@ int sctp_register_af(struct sctp_af *af)
81926 return 0;
81927 }
81928
81929 - INIT_LIST_HEAD(&af->list);
81930 - list_add_tail(&af->list, &sctp_address_families);
81931 + pax_open_kernel();
81932 + INIT_LIST_HEAD((struct list_head *)&af->list);
81933 + pax_close_kernel();
81934 + pax_list_add_tail((struct list_head *)&af->list, &sctp_address_families);
81935 return 1;
81936 }
81937
81938 @@ -1122,7 +1124,7 @@ static void sctp_v4_pf_init(void)
81939
81940 static void sctp_v4_pf_exit(void)
81941 {
81942 - list_del(&sctp_af_inet.list);
81943 + pax_list_del((struct list_head *)&sctp_af_inet.list);
81944 }
81945
81946 static int sctp_v4_protosw_init(void)
81947 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
81948 index 406d957..0a6ae623 100644
81949 --- a/net/sctp/socket.c
81950 +++ b/net/sctp/socket.c
81951 @@ -3388,7 +3388,7 @@ static int sctp_setsockopt_auth_key(struct sock *sk,
81952
81953 ret = sctp_auth_set_key(sctp_sk(sk)->ep, asoc, authkey);
81954 out:
81955 - kfree(authkey);
81956 + kzfree(authkey);
81957 return ret;
81958 }
81959
81960 @@ -4661,6 +4661,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
81961 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
81962 if (space_left < addrlen)
81963 return -ENOMEM;
81964 + if (addrlen > sizeof(temp) || addrlen < 0)
81965 + return -EFAULT;
81966 if (copy_to_user(to, &temp, addrlen))
81967 return -EFAULT;
81968 to += addrlen;
81969 diff --git a/net/socket.c b/net/socket.c
81970 index d92c490..b4bc863 100644
81971 --- a/net/socket.c
81972 +++ b/net/socket.c
81973 @@ -89,6 +89,7 @@
81974 #include <linux/magic.h>
81975 #include <linux/slab.h>
81976 #include <linux/xattr.h>
81977 +#include <linux/in.h>
81978
81979 #include <asm/uaccess.h>
81980 #include <asm/unistd.h>
81981 @@ -106,6 +107,8 @@
81982 #include <linux/sockios.h>
81983 #include <linux/atalk.h>
81984
81985 +#include <linux/grsock.h>
81986 +
81987 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
81988 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
81989 unsigned long nr_segs, loff_t pos);
81990 @@ -322,7 +325,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
81991 &sockfs_dentry_operations, SOCKFS_MAGIC);
81992 }
81993
81994 -static struct vfsmount *sock_mnt __read_mostly;
81995 +struct vfsmount *sock_mnt __read_mostly;
81996
81997 static struct file_system_type sock_fs_type = {
81998 .name = "sockfs",
81999 @@ -1276,6 +1279,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
82000 return -EAFNOSUPPORT;
82001 if (type < 0 || type >= SOCK_MAX)
82002 return -EINVAL;
82003 + if (protocol < 0)
82004 + return -EINVAL;
82005
82006 /* Compatibility.
82007
82008 @@ -1407,6 +1412,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
82009 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
82010 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
82011
82012 + if(!gr_search_socket(family, type, protocol)) {
82013 + retval = -EACCES;
82014 + goto out;
82015 + }
82016 +
82017 + if (gr_handle_sock_all(family, type, protocol)) {
82018 + retval = -EACCES;
82019 + goto out;
82020 + }
82021 +
82022 retval = sock_create(family, type, protocol, &sock);
82023 if (retval < 0)
82024 goto out;
82025 @@ -1534,6 +1549,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
82026 if (sock) {
82027 err = move_addr_to_kernel(umyaddr, addrlen, &address);
82028 if (err >= 0) {
82029 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
82030 + err = -EACCES;
82031 + goto error;
82032 + }
82033 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
82034 + if (err)
82035 + goto error;
82036 +
82037 err = security_socket_bind(sock,
82038 (struct sockaddr *)&address,
82039 addrlen);
82040 @@ -1542,6 +1565,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
82041 (struct sockaddr *)
82042 &address, addrlen);
82043 }
82044 +error:
82045 fput_light(sock->file, fput_needed);
82046 }
82047 return err;
82048 @@ -1565,10 +1589,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
82049 if ((unsigned int)backlog > somaxconn)
82050 backlog = somaxconn;
82051
82052 + if (gr_handle_sock_server_other(sock->sk)) {
82053 + err = -EPERM;
82054 + goto error;
82055 + }
82056 +
82057 + err = gr_search_listen(sock);
82058 + if (err)
82059 + goto error;
82060 +
82061 err = security_socket_listen(sock, backlog);
82062 if (!err)
82063 err = sock->ops->listen(sock, backlog);
82064
82065 +error:
82066 fput_light(sock->file, fput_needed);
82067 }
82068 return err;
82069 @@ -1612,6 +1646,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
82070 newsock->type = sock->type;
82071 newsock->ops = sock->ops;
82072
82073 + if (gr_handle_sock_server_other(sock->sk)) {
82074 + err = -EPERM;
82075 + sock_release(newsock);
82076 + goto out_put;
82077 + }
82078 +
82079 + err = gr_search_accept(sock);
82080 + if (err) {
82081 + sock_release(newsock);
82082 + goto out_put;
82083 + }
82084 +
82085 /*
82086 * We don't need try_module_get here, as the listening socket (sock)
82087 * has the protocol module (sock->ops->owner) held.
82088 @@ -1657,6 +1703,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
82089 fd_install(newfd, newfile);
82090 err = newfd;
82091
82092 + gr_attach_curr_ip(newsock->sk);
82093 +
82094 out_put:
82095 fput_light(sock->file, fput_needed);
82096 out:
82097 @@ -1689,6 +1737,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
82098 int, addrlen)
82099 {
82100 struct socket *sock;
82101 + struct sockaddr *sck;
82102 struct sockaddr_storage address;
82103 int err, fput_needed;
82104
82105 @@ -1699,6 +1748,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
82106 if (err < 0)
82107 goto out_put;
82108
82109 + sck = (struct sockaddr *)&address;
82110 +
82111 + if (gr_handle_sock_client(sck)) {
82112 + err = -EACCES;
82113 + goto out_put;
82114 + }
82115 +
82116 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
82117 + if (err)
82118 + goto out_put;
82119 +
82120 err =
82121 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
82122 if (err)
82123 @@ -2053,7 +2113,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
82124 * checking falls down on this.
82125 */
82126 if (copy_from_user(ctl_buf,
82127 - (void __user __force *)msg_sys->msg_control,
82128 + (void __force_user *)msg_sys->msg_control,
82129 ctl_len))
82130 goto out_freectl;
82131 msg_sys->msg_control = ctl_buf;
82132 @@ -2221,7 +2281,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
82133 * kernel msghdr to use the kernel address space)
82134 */
82135
82136 - uaddr = (__force void __user *)msg_sys->msg_name;
82137 + uaddr = (void __force_user *)msg_sys->msg_name;
82138 uaddr_len = COMPAT_NAMELEN(msg);
82139 if (MSG_CMSG_COMPAT & flags) {
82140 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
82141 @@ -2844,7 +2904,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
82142 }
82143
82144 ifr = compat_alloc_user_space(buf_size);
82145 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
82146 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
82147
82148 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
82149 return -EFAULT;
82150 @@ -2868,12 +2928,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
82151 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
82152
82153 if (copy_in_user(rxnfc, compat_rxnfc,
82154 - (void *)(&rxnfc->fs.m_ext + 1) -
82155 - (void *)rxnfc) ||
82156 + (void __user *)(&rxnfc->fs.m_ext + 1) -
82157 + (void __user *)rxnfc) ||
82158 copy_in_user(&rxnfc->fs.ring_cookie,
82159 &compat_rxnfc->fs.ring_cookie,
82160 - (void *)(&rxnfc->fs.location + 1) -
82161 - (void *)&rxnfc->fs.ring_cookie) ||
82162 + (void __user *)(&rxnfc->fs.location + 1) -
82163 + (void __user *)&rxnfc->fs.ring_cookie) ||
82164 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
82165 sizeof(rxnfc->rule_cnt)))
82166 return -EFAULT;
82167 @@ -2885,12 +2945,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
82168
82169 if (convert_out) {
82170 if (copy_in_user(compat_rxnfc, rxnfc,
82171 - (const void *)(&rxnfc->fs.m_ext + 1) -
82172 - (const void *)rxnfc) ||
82173 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
82174 + (const void __user *)rxnfc) ||
82175 copy_in_user(&compat_rxnfc->fs.ring_cookie,
82176 &rxnfc->fs.ring_cookie,
82177 - (const void *)(&rxnfc->fs.location + 1) -
82178 - (const void *)&rxnfc->fs.ring_cookie) ||
82179 + (const void __user *)(&rxnfc->fs.location + 1) -
82180 + (const void __user *)&rxnfc->fs.ring_cookie) ||
82181 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
82182 sizeof(rxnfc->rule_cnt)))
82183 return -EFAULT;
82184 @@ -2960,7 +3020,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
82185 old_fs = get_fs();
82186 set_fs(KERNEL_DS);
82187 err = dev_ioctl(net, cmd,
82188 - (struct ifreq __user __force *) &kifr);
82189 + (struct ifreq __force_user *) &kifr);
82190 set_fs(old_fs);
82191
82192 return err;
82193 @@ -3069,7 +3129,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
82194
82195 old_fs = get_fs();
82196 set_fs(KERNEL_DS);
82197 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
82198 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
82199 set_fs(old_fs);
82200
82201 if (cmd == SIOCGIFMAP && !err) {
82202 @@ -3174,7 +3234,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
82203 ret |= __get_user(rtdev, &(ur4->rt_dev));
82204 if (rtdev) {
82205 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
82206 - r4.rt_dev = (char __user __force *)devname;
82207 + r4.rt_dev = (char __force_user *)devname;
82208 devname[15] = 0;
82209 } else
82210 r4.rt_dev = NULL;
82211 @@ -3400,8 +3460,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
82212 int __user *uoptlen;
82213 int err;
82214
82215 - uoptval = (char __user __force *) optval;
82216 - uoptlen = (int __user __force *) optlen;
82217 + uoptval = (char __force_user *) optval;
82218 + uoptlen = (int __force_user *) optlen;
82219
82220 set_fs(KERNEL_DS);
82221 if (level == SOL_SOCKET)
82222 @@ -3421,7 +3481,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
82223 char __user *uoptval;
82224 int err;
82225
82226 - uoptval = (char __user __force *) optval;
82227 + uoptval = (char __force_user *) optval;
82228
82229 set_fs(KERNEL_DS);
82230 if (level == SOL_SOCKET)
82231 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
82232 index 7865b44..174662e 100644
82233 --- a/net/sunrpc/sched.c
82234 +++ b/net/sunrpc/sched.c
82235 @@ -240,9 +240,9 @@ static int rpc_wait_bit_killable(void *word)
82236 #ifdef RPC_DEBUG
82237 static void rpc_task_set_debuginfo(struct rpc_task *task)
82238 {
82239 - static atomic_t rpc_pid;
82240 + static atomic_unchecked_t rpc_pid;
82241
82242 - task->tk_pid = atomic_inc_return(&rpc_pid);
82243 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
82244 }
82245 #else
82246 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
82247 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
82248 index 8343737..677025e 100644
82249 --- a/net/sunrpc/xprtrdma/svc_rdma.c
82250 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
82251 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
82252 static unsigned int min_max_inline = 4096;
82253 static unsigned int max_max_inline = 65536;
82254
82255 -atomic_t rdma_stat_recv;
82256 -atomic_t rdma_stat_read;
82257 -atomic_t rdma_stat_write;
82258 -atomic_t rdma_stat_sq_starve;
82259 -atomic_t rdma_stat_rq_starve;
82260 -atomic_t rdma_stat_rq_poll;
82261 -atomic_t rdma_stat_rq_prod;
82262 -atomic_t rdma_stat_sq_poll;
82263 -atomic_t rdma_stat_sq_prod;
82264 +atomic_unchecked_t rdma_stat_recv;
82265 +atomic_unchecked_t rdma_stat_read;
82266 +atomic_unchecked_t rdma_stat_write;
82267 +atomic_unchecked_t rdma_stat_sq_starve;
82268 +atomic_unchecked_t rdma_stat_rq_starve;
82269 +atomic_unchecked_t rdma_stat_rq_poll;
82270 +atomic_unchecked_t rdma_stat_rq_prod;
82271 +atomic_unchecked_t rdma_stat_sq_poll;
82272 +atomic_unchecked_t rdma_stat_sq_prod;
82273
82274 /* Temporary NFS request map and context caches */
82275 struct kmem_cache *svc_rdma_map_cachep;
82276 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
82277 len -= *ppos;
82278 if (len > *lenp)
82279 len = *lenp;
82280 - if (len && copy_to_user(buffer, str_buf, len))
82281 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
82282 return -EFAULT;
82283 *lenp = len;
82284 *ppos += len;
82285 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
82286 {
82287 .procname = "rdma_stat_read",
82288 .data = &rdma_stat_read,
82289 - .maxlen = sizeof(atomic_t),
82290 + .maxlen = sizeof(atomic_unchecked_t),
82291 .mode = 0644,
82292 .proc_handler = read_reset_stat,
82293 },
82294 {
82295 .procname = "rdma_stat_recv",
82296 .data = &rdma_stat_recv,
82297 - .maxlen = sizeof(atomic_t),
82298 + .maxlen = sizeof(atomic_unchecked_t),
82299 .mode = 0644,
82300 .proc_handler = read_reset_stat,
82301 },
82302 {
82303 .procname = "rdma_stat_write",
82304 .data = &rdma_stat_write,
82305 - .maxlen = sizeof(atomic_t),
82306 + .maxlen = sizeof(atomic_unchecked_t),
82307 .mode = 0644,
82308 .proc_handler = read_reset_stat,
82309 },
82310 {
82311 .procname = "rdma_stat_sq_starve",
82312 .data = &rdma_stat_sq_starve,
82313 - .maxlen = sizeof(atomic_t),
82314 + .maxlen = sizeof(atomic_unchecked_t),
82315 .mode = 0644,
82316 .proc_handler = read_reset_stat,
82317 },
82318 {
82319 .procname = "rdma_stat_rq_starve",
82320 .data = &rdma_stat_rq_starve,
82321 - .maxlen = sizeof(atomic_t),
82322 + .maxlen = sizeof(atomic_unchecked_t),
82323 .mode = 0644,
82324 .proc_handler = read_reset_stat,
82325 },
82326 {
82327 .procname = "rdma_stat_rq_poll",
82328 .data = &rdma_stat_rq_poll,
82329 - .maxlen = sizeof(atomic_t),
82330 + .maxlen = sizeof(atomic_unchecked_t),
82331 .mode = 0644,
82332 .proc_handler = read_reset_stat,
82333 },
82334 {
82335 .procname = "rdma_stat_rq_prod",
82336 .data = &rdma_stat_rq_prod,
82337 - .maxlen = sizeof(atomic_t),
82338 + .maxlen = sizeof(atomic_unchecked_t),
82339 .mode = 0644,
82340 .proc_handler = read_reset_stat,
82341 },
82342 {
82343 .procname = "rdma_stat_sq_poll",
82344 .data = &rdma_stat_sq_poll,
82345 - .maxlen = sizeof(atomic_t),
82346 + .maxlen = sizeof(atomic_unchecked_t),
82347 .mode = 0644,
82348 .proc_handler = read_reset_stat,
82349 },
82350 {
82351 .procname = "rdma_stat_sq_prod",
82352 .data = &rdma_stat_sq_prod,
82353 - .maxlen = sizeof(atomic_t),
82354 + .maxlen = sizeof(atomic_unchecked_t),
82355 .mode = 0644,
82356 .proc_handler = read_reset_stat,
82357 },
82358 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
82359 index 41cb63b..c4a1489 100644
82360 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
82361 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
82362 @@ -501,7 +501,7 @@ next_sge:
82363 svc_rdma_put_context(ctxt, 0);
82364 goto out;
82365 }
82366 - atomic_inc(&rdma_stat_read);
82367 + atomic_inc_unchecked(&rdma_stat_read);
82368
82369 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
82370 chl_map->ch[ch_no].count -= read_wr.num_sge;
82371 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
82372 dto_q);
82373 list_del_init(&ctxt->dto_q);
82374 } else {
82375 - atomic_inc(&rdma_stat_rq_starve);
82376 + atomic_inc_unchecked(&rdma_stat_rq_starve);
82377 clear_bit(XPT_DATA, &xprt->xpt_flags);
82378 ctxt = NULL;
82379 }
82380 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
82381 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
82382 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
82383 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
82384 - atomic_inc(&rdma_stat_recv);
82385 + atomic_inc_unchecked(&rdma_stat_recv);
82386
82387 /* Build up the XDR from the receive buffers. */
82388 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
82389 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
82390 index 42eb7ba..c887c45 100644
82391 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
82392 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
82393 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
82394 write_wr.wr.rdma.remote_addr = to;
82395
82396 /* Post It */
82397 - atomic_inc(&rdma_stat_write);
82398 + atomic_inc_unchecked(&rdma_stat_write);
82399 if (svc_rdma_send(xprt, &write_wr))
82400 goto err;
82401 return 0;
82402 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
82403 index 62e4f9b..dd3f2d7 100644
82404 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
82405 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
82406 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
82407 return;
82408
82409 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
82410 - atomic_inc(&rdma_stat_rq_poll);
82411 + atomic_inc_unchecked(&rdma_stat_rq_poll);
82412
82413 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
82414 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
82415 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
82416 }
82417
82418 if (ctxt)
82419 - atomic_inc(&rdma_stat_rq_prod);
82420 + atomic_inc_unchecked(&rdma_stat_rq_prod);
82421
82422 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
82423 /*
82424 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
82425 return;
82426
82427 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
82428 - atomic_inc(&rdma_stat_sq_poll);
82429 + atomic_inc_unchecked(&rdma_stat_sq_poll);
82430 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
82431 if (wc.status != IB_WC_SUCCESS)
82432 /* Close the transport */
82433 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
82434 }
82435
82436 if (ctxt)
82437 - atomic_inc(&rdma_stat_sq_prod);
82438 + atomic_inc_unchecked(&rdma_stat_sq_prod);
82439 }
82440
82441 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
82442 @@ -1262,7 +1262,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
82443 spin_lock_bh(&xprt->sc_lock);
82444 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
82445 spin_unlock_bh(&xprt->sc_lock);
82446 - atomic_inc(&rdma_stat_sq_starve);
82447 + atomic_inc_unchecked(&rdma_stat_sq_starve);
82448
82449 /* See if we can opportunistically reap SQ WR to make room */
82450 sq_cq_reap(xprt);
82451 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
82452 index e3a6e37..be2ea77 100644
82453 --- a/net/sysctl_net.c
82454 +++ b/net/sysctl_net.c
82455 @@ -43,7 +43,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
82456 struct ctl_table *table)
82457 {
82458 /* Allow network administrator to have same access as root. */
82459 - if (capable(CAP_NET_ADMIN)) {
82460 + if (capable_nolog(CAP_NET_ADMIN)) {
82461 int mode = (table->mode >> 6) & 7;
82462 return (mode << 6) | (mode << 3) | mode;
82463 }
82464 diff --git a/net/tipc/link.c b/net/tipc/link.c
82465 index a79c755..eca357d 100644
82466 --- a/net/tipc/link.c
82467 +++ b/net/tipc/link.c
82468 @@ -1169,7 +1169,7 @@ static int link_send_sections_long(struct tipc_port *sender,
82469 struct tipc_msg fragm_hdr;
82470 struct sk_buff *buf, *buf_chain, *prev;
82471 u32 fragm_crs, fragm_rest, hsz, sect_rest;
82472 - const unchar *sect_crs;
82473 + const unchar __user *sect_crs;
82474 int curr_sect;
82475 u32 fragm_no;
82476
82477 @@ -1210,7 +1210,7 @@ again:
82478
82479 if (!sect_rest) {
82480 sect_rest = msg_sect[++curr_sect].iov_len;
82481 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
82482 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
82483 }
82484
82485 if (sect_rest < fragm_rest)
82486 @@ -1229,7 +1229,7 @@ error:
82487 }
82488 } else
82489 skb_copy_to_linear_data_offset(buf, fragm_crs,
82490 - sect_crs, sz);
82491 + (const void __force_kernel *)sect_crs, sz);
82492 sect_crs += sz;
82493 sect_rest -= sz;
82494 fragm_crs += sz;
82495 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
82496 index f2db8a8..9245aa4 100644
82497 --- a/net/tipc/msg.c
82498 +++ b/net/tipc/msg.c
82499 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
82500 msg_sect[cnt].iov_len);
82501 else
82502 skb_copy_to_linear_data_offset(*buf, pos,
82503 - msg_sect[cnt].iov_base,
82504 + (const void __force_kernel *)msg_sect[cnt].iov_base,
82505 msg_sect[cnt].iov_len);
82506 pos += msg_sect[cnt].iov_len;
82507 }
82508 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
82509 index 0f7d0d0..00f89bf 100644
82510 --- a/net/tipc/subscr.c
82511 +++ b/net/tipc/subscr.c
82512 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
82513 {
82514 struct iovec msg_sect;
82515
82516 - msg_sect.iov_base = (void *)&sub->evt;
82517 + msg_sect.iov_base = (void __force_user *)&sub->evt;
82518 msg_sect.iov_len = sizeof(struct tipc_event);
82519
82520 sub->evt.event = htohl(event, sub->swap);
82521 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
82522 index 5b5c876..3127bf7 100644
82523 --- a/net/unix/af_unix.c
82524 +++ b/net/unix/af_unix.c
82525 @@ -786,6 +786,12 @@ static struct sock *unix_find_other(struct net *net,
82526 err = -ECONNREFUSED;
82527 if (!S_ISSOCK(inode->i_mode))
82528 goto put_fail;
82529 +
82530 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
82531 + err = -EACCES;
82532 + goto put_fail;
82533 + }
82534 +
82535 u = unix_find_socket_byinode(inode);
82536 if (!u)
82537 goto put_fail;
82538 @@ -806,6 +812,13 @@ static struct sock *unix_find_other(struct net *net,
82539 if (u) {
82540 struct dentry *dentry;
82541 dentry = unix_sk(u)->path.dentry;
82542 +
82543 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
82544 + err = -EPERM;
82545 + sock_put(u);
82546 + goto fail;
82547 + }
82548 +
82549 if (dentry)
82550 touch_atime(&unix_sk(u)->path);
82551 } else
82552 @@ -839,12 +852,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
82553 */
82554 err = security_path_mknod(&path, dentry, mode, 0);
82555 if (!err) {
82556 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
82557 + err = -EACCES;
82558 + goto out;
82559 + }
82560 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
82561 if (!err) {
82562 res->mnt = mntget(path.mnt);
82563 res->dentry = dget(dentry);
82564 + gr_handle_create(dentry, path.mnt);
82565 }
82566 }
82567 +out:
82568 done_path_create(&path, dentry);
82569 return err;
82570 }
82571 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
82572 index c8717c1..08539f5 100644
82573 --- a/net/wireless/wext-core.c
82574 +++ b/net/wireless/wext-core.c
82575 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
82576 */
82577
82578 /* Support for very large requests */
82579 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
82580 - (user_length > descr->max_tokens)) {
82581 + if (user_length > descr->max_tokens) {
82582 /* Allow userspace to GET more than max so
82583 * we can support any size GET requests.
82584 * There is still a limit : -ENOMEM.
82585 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
82586 }
82587 }
82588
82589 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
82590 - /*
82591 - * If this is a GET, but not NOMAX, it means that the extra
82592 - * data is not bounded by userspace, but by max_tokens. Thus
82593 - * set the length to max_tokens. This matches the extra data
82594 - * allocation.
82595 - * The driver should fill it with the number of tokens it
82596 - * provided, and it may check iwp->length rather than having
82597 - * knowledge of max_tokens. If the driver doesn't change the
82598 - * iwp->length, this ioctl just copies back max_token tokens
82599 - * filled with zeroes. Hopefully the driver isn't claiming
82600 - * them to be valid data.
82601 - */
82602 - iwp->length = descr->max_tokens;
82603 - }
82604 -
82605 err = handler(dev, info, (union iwreq_data *) iwp, extra);
82606
82607 iwp->length += essid_compat;
82608 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
82609 index 41eabc4..8d4e6d6 100644
82610 --- a/net/xfrm/xfrm_policy.c
82611 +++ b/net/xfrm/xfrm_policy.c
82612 @@ -317,7 +317,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
82613 {
82614 policy->walk.dead = 1;
82615
82616 - atomic_inc(&policy->genid);
82617 + atomic_inc_unchecked(&policy->genid);
82618
82619 if (del_timer(&policy->timer))
82620 xfrm_pol_put(policy);
82621 @@ -601,7 +601,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
82622 hlist_add_head(&policy->bydst, chain);
82623 xfrm_pol_hold(policy);
82624 net->xfrm.policy_count[dir]++;
82625 - atomic_inc(&flow_cache_genid);
82626 + atomic_inc_unchecked(&flow_cache_genid);
82627 rt_genid_bump(net);
82628 if (delpol)
82629 __xfrm_policy_unlink(delpol, dir);
82630 @@ -1550,7 +1550,7 @@ free_dst:
82631 goto out;
82632 }
82633
82634 -static int inline
82635 +static inline int
82636 xfrm_dst_alloc_copy(void **target, const void *src, int size)
82637 {
82638 if (!*target) {
82639 @@ -1562,7 +1562,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
82640 return 0;
82641 }
82642
82643 -static int inline
82644 +static inline int
82645 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
82646 {
82647 #ifdef CONFIG_XFRM_SUB_POLICY
82648 @@ -1574,7 +1574,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
82649 #endif
82650 }
82651
82652 -static int inline
82653 +static inline int
82654 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
82655 {
82656 #ifdef CONFIG_XFRM_SUB_POLICY
82657 @@ -1668,7 +1668,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
82658
82659 xdst->num_pols = num_pols;
82660 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
82661 - xdst->policy_genid = atomic_read(&pols[0]->genid);
82662 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
82663
82664 return xdst;
82665 }
82666 @@ -2369,7 +2369,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
82667 if (xdst->xfrm_genid != dst->xfrm->genid)
82668 return 0;
82669 if (xdst->num_pols > 0 &&
82670 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
82671 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
82672 return 0;
82673
82674 mtu = dst_mtu(dst->child);
82675 @@ -2896,7 +2896,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
82676 sizeof(pol->xfrm_vec[i].saddr));
82677 pol->xfrm_vec[i].encap_family = mp->new_family;
82678 /* flush bundles */
82679 - atomic_inc(&pol->genid);
82680 + atomic_inc_unchecked(&pol->genid);
82681 }
82682 }
82683
82684 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
82685 index 3459692..eefb515 100644
82686 --- a/net/xfrm/xfrm_state.c
82687 +++ b/net/xfrm/xfrm_state.c
82688 @@ -278,7 +278,9 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
82689 if (!try_module_get(afinfo->owner))
82690 goto out;
82691
82692 - mode->afinfo = afinfo;
82693 + pax_open_kernel();
82694 + *(void **)&mode->afinfo = afinfo;
82695 + pax_close_kernel();
82696 modemap[mode->encap] = mode;
82697 err = 0;
82698
82699 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
82700 index 0e801c3..5c8ad3b 100644
82701 --- a/scripts/Makefile.build
82702 +++ b/scripts/Makefile.build
82703 @@ -111,7 +111,7 @@ endif
82704 endif
82705
82706 # Do not include host rules unless needed
82707 -ifneq ($(hostprogs-y)$(hostprogs-m),)
82708 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
82709 include scripts/Makefile.host
82710 endif
82711
82712 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
82713 index 686cb0d..9d653bf 100644
82714 --- a/scripts/Makefile.clean
82715 +++ b/scripts/Makefile.clean
82716 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
82717 __clean-files := $(extra-y) $(always) \
82718 $(targets) $(clean-files) \
82719 $(host-progs) \
82720 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
82721 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
82722 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
82723
82724 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
82725
82726 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
82727 index 1ac414f..38575f7 100644
82728 --- a/scripts/Makefile.host
82729 +++ b/scripts/Makefile.host
82730 @@ -31,6 +31,8 @@
82731 # Note: Shared libraries consisting of C++ files are not supported
82732
82733 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
82734 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
82735 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
82736
82737 # C code
82738 # Executables compiled from a single .c file
82739 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
82740 # Shared libaries (only .c supported)
82741 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
82742 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
82743 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
82744 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
82745 # Remove .so files from "xxx-objs"
82746 host-cobjs := $(filter-out %.so,$(host-cobjs))
82747 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
82748
82749 -#Object (.o) files used by the shared libaries
82750 +# Object (.o) files used by the shared libaries
82751 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
82752 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
82753
82754 # output directory for programs/.o files
82755 # hostprogs-y := tools/build may have been specified. Retrieve directory
82756 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
82757 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
82758 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
82759 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
82760 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
82761 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
82762 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
82763 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
82764
82765 obj-dirs += $(host-objdirs)
82766 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
82767 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
82768 $(call if_changed_dep,host-cshobjs)
82769
82770 +# Compile .c file, create position independent .o file
82771 +# host-cxxshobjs -> .o
82772 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
82773 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
82774 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
82775 + $(call if_changed_dep,host-cxxshobjs)
82776 +
82777 # Link a shared library, based on position independent .o files
82778 # *.o -> .so shared library (host-cshlib)
82779 quiet_cmd_host-cshlib = HOSTLLD -shared $@
82780 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
82781 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
82782 $(call if_changed,host-cshlib)
82783
82784 +# Link a shared library, based on position independent .o files
82785 +# *.o -> .so shared library (host-cxxshlib)
82786 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
82787 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
82788 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
82789 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
82790 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
82791 + $(call if_changed,host-cxxshlib)
82792 +
82793 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
82794 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
82795 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
82796
82797 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
82798 index cb1f50c..cef2a7c 100644
82799 --- a/scripts/basic/fixdep.c
82800 +++ b/scripts/basic/fixdep.c
82801 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
82802 /*
82803 * Lookup a value in the configuration string.
82804 */
82805 -static int is_defined_config(const char *name, int len, unsigned int hash)
82806 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
82807 {
82808 struct item *aux;
82809
82810 @@ -211,10 +211,10 @@ static void clear_config(void)
82811 /*
82812 * Record the use of a CONFIG_* word.
82813 */
82814 -static void use_config(const char *m, int slen)
82815 +static void use_config(const char *m, unsigned int slen)
82816 {
82817 unsigned int hash = strhash(m, slen);
82818 - int c, i;
82819 + unsigned int c, i;
82820
82821 if (is_defined_config(m, slen, hash))
82822 return;
82823 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
82824
82825 static void parse_config_file(const char *map, size_t len)
82826 {
82827 - const int *end = (const int *) (map + len);
82828 + const unsigned int *end = (const unsigned int *) (map + len);
82829 /* start at +1, so that p can never be < map */
82830 - const int *m = (const int *) map + 1;
82831 + const unsigned int *m = (const unsigned int *) map + 1;
82832 const char *p, *q;
82833
82834 for (; m < end; m++) {
82835 @@ -406,7 +406,7 @@ static void print_deps(void)
82836 static void traps(void)
82837 {
82838 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
82839 - int *p = (int *)test;
82840 + unsigned int *p = (unsigned int *)test;
82841
82842 if (*p != INT_CONF) {
82843 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
82844 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
82845 new file mode 100644
82846 index 0000000..008ac1a
82847 --- /dev/null
82848 +++ b/scripts/gcc-plugin.sh
82849 @@ -0,0 +1,17 @@
82850 +#!/bin/bash
82851 +plugincc=`$1 -x c -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
82852 +#include "gcc-plugin.h"
82853 +#include "tree.h"
82854 +#include "tm.h"
82855 +#include "rtl.h"
82856 +#ifdef ENABLE_BUILD_WITH_CXX
82857 +#warning $2
82858 +#else
82859 +#warning $1
82860 +#endif
82861 +EOF`
82862 +if [ $? -eq 0 ]
82863 +then
82864 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
82865 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
82866 +fi
82867 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
82868 index b3d907e..a4782ab 100644
82869 --- a/scripts/link-vmlinux.sh
82870 +++ b/scripts/link-vmlinux.sh
82871 @@ -152,7 +152,7 @@ else
82872 fi;
82873
82874 # final build of init/
82875 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
82876 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
82877
82878 kallsymso=""
82879 kallsyms_vmlinux=""
82880 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
82881 index df4fc23..0ea719d 100644
82882 --- a/scripts/mod/file2alias.c
82883 +++ b/scripts/mod/file2alias.c
82884 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
82885 unsigned long size, unsigned long id_size,
82886 void *symval)
82887 {
82888 - int i;
82889 + unsigned int i;
82890
82891 if (size % id_size || size < id_size) {
82892 if (cross_build != 0)
82893 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
82894 /* USB is special because the bcdDevice can be matched against a numeric range */
82895 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
82896 static void do_usb_entry(struct usb_device_id *id,
82897 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
82898 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
82899 unsigned char range_lo, unsigned char range_hi,
82900 unsigned char max, struct module *mod)
82901 {
82902 @@ -262,7 +262,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
82903 {
82904 unsigned int devlo, devhi;
82905 unsigned char chi, clo, max;
82906 - int ndigits;
82907 + unsigned int ndigits;
82908
82909 id->match_flags = TO_NATIVE(id->match_flags);
82910 id->idVendor = TO_NATIVE(id->idVendor);
82911 @@ -507,7 +507,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
82912 for (i = 0; i < count; i++) {
82913 const char *id = (char *)devs[i].id;
82914 char acpi_id[sizeof(devs[0].id)];
82915 - int j;
82916 + unsigned int j;
82917
82918 buf_printf(&mod->dev_table_buf,
82919 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
82920 @@ -537,7 +537,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
82921
82922 for (j = 0; j < PNP_MAX_DEVICES; j++) {
82923 const char *id = (char *)card->devs[j].id;
82924 - int i2, j2;
82925 + unsigned int i2, j2;
82926 int dup = 0;
82927
82928 if (!id[0])
82929 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
82930 /* add an individual alias for every device entry */
82931 if (!dup) {
82932 char acpi_id[sizeof(card->devs[0].id)];
82933 - int k;
82934 + unsigned int k;
82935
82936 buf_printf(&mod->dev_table_buf,
82937 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
82938 @@ -888,7 +888,7 @@ static void dmi_ascii_filter(char *d, const char *s)
82939 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
82940 char *alias)
82941 {
82942 - int i, j;
82943 + unsigned int i, j;
82944
82945 sprintf(alias, "dmi*");
82946
82947 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
82948 index 0d93856..e828363 100644
82949 --- a/scripts/mod/modpost.c
82950 +++ b/scripts/mod/modpost.c
82951 @@ -933,6 +933,7 @@ enum mismatch {
82952 ANY_INIT_TO_ANY_EXIT,
82953 ANY_EXIT_TO_ANY_INIT,
82954 EXPORT_TO_INIT_EXIT,
82955 + DATA_TO_TEXT
82956 };
82957
82958 struct sectioncheck {
82959 @@ -1047,6 +1048,12 @@ const struct sectioncheck sectioncheck[] = {
82960 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
82961 .mismatch = EXPORT_TO_INIT_EXIT,
82962 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
82963 +},
82964 +/* Do not reference code from writable data */
82965 +{
82966 + .fromsec = { DATA_SECTIONS, NULL },
82967 + .tosec = { TEXT_SECTIONS, NULL },
82968 + .mismatch = DATA_TO_TEXT
82969 }
82970 };
82971
82972 @@ -1169,10 +1176,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
82973 continue;
82974 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
82975 continue;
82976 - if (sym->st_value == addr)
82977 - return sym;
82978 /* Find a symbol nearby - addr are maybe negative */
82979 d = sym->st_value - addr;
82980 + if (d == 0)
82981 + return sym;
82982 if (d < 0)
82983 d = addr - sym->st_value;
82984 if (d < distance) {
82985 @@ -1451,6 +1458,14 @@ static void report_sec_mismatch(const char *modname,
82986 tosym, prl_to, prl_to, tosym);
82987 free(prl_to);
82988 break;
82989 + case DATA_TO_TEXT:
82990 +#if 0
82991 + fprintf(stderr,
82992 + "The %s %s:%s references\n"
82993 + "the %s %s:%s%s\n",
82994 + from, fromsec, fromsym, to, tosec, tosym, to_p);
82995 +#endif
82996 + break;
82997 }
82998 fprintf(stderr, "\n");
82999 }
83000 @@ -1685,7 +1700,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
83001 static void check_sec_ref(struct module *mod, const char *modname,
83002 struct elf_info *elf)
83003 {
83004 - int i;
83005 + unsigned int i;
83006 Elf_Shdr *sechdrs = elf->sechdrs;
83007
83008 /* Walk through all sections */
83009 @@ -1783,7 +1798,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
83010 va_end(ap);
83011 }
83012
83013 -void buf_write(struct buffer *buf, const char *s, int len)
83014 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
83015 {
83016 if (buf->size - buf->pos < len) {
83017 buf->size += len + SZ;
83018 @@ -2001,7 +2016,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
83019 if (fstat(fileno(file), &st) < 0)
83020 goto close_write;
83021
83022 - if (st.st_size != b->pos)
83023 + if (st.st_size != (off_t)b->pos)
83024 goto close_write;
83025
83026 tmp = NOFAIL(malloc(b->pos));
83027 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
83028 index 51207e4..f7d603d 100644
83029 --- a/scripts/mod/modpost.h
83030 +++ b/scripts/mod/modpost.h
83031 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
83032
83033 struct buffer {
83034 char *p;
83035 - int pos;
83036 - int size;
83037 + unsigned int pos;
83038 + unsigned int size;
83039 };
83040
83041 void __attribute__((format(printf, 2, 3)))
83042 buf_printf(struct buffer *buf, const char *fmt, ...);
83043
83044 void
83045 -buf_write(struct buffer *buf, const char *s, int len);
83046 +buf_write(struct buffer *buf, const char *s, unsigned int len);
83047
83048 struct module {
83049 struct module *next;
83050 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
83051 index 9dfcd6d..099068e 100644
83052 --- a/scripts/mod/sumversion.c
83053 +++ b/scripts/mod/sumversion.c
83054 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
83055 goto out;
83056 }
83057
83058 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
83059 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
83060 warn("writing sum in %s failed: %s\n",
83061 filename, strerror(errno));
83062 goto out;
83063 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
83064 index 5c11312..72742b5 100644
83065 --- a/scripts/pnmtologo.c
83066 +++ b/scripts/pnmtologo.c
83067 @@ -237,14 +237,14 @@ static void write_header(void)
83068 fprintf(out, " * Linux logo %s\n", logoname);
83069 fputs(" */\n\n", out);
83070 fputs("#include <linux/linux_logo.h>\n\n", out);
83071 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
83072 + fprintf(out, "static unsigned char %s_data[] = {\n",
83073 logoname);
83074 }
83075
83076 static void write_footer(void)
83077 {
83078 fputs("\n};\n\n", out);
83079 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
83080 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
83081 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
83082 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
83083 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
83084 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
83085 fputs("\n};\n\n", out);
83086
83087 /* write logo clut */
83088 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
83089 + fprintf(out, "static unsigned char %s_clut[] = {\n",
83090 logoname);
83091 write_hex_cnt = 0;
83092 for (i = 0; i < logo_clutsize; i++) {
83093 diff --git a/security/Kconfig b/security/Kconfig
83094 index e9c6ac7..01c698c 100644
83095 --- a/security/Kconfig
83096 +++ b/security/Kconfig
83097 @@ -4,6 +4,902 @@
83098
83099 menu "Security options"
83100
83101 +menu "Grsecurity"
83102 +
83103 + config ARCH_TRACK_EXEC_LIMIT
83104 + bool
83105 +
83106 + config PAX_KERNEXEC_PLUGIN
83107 + bool
83108 +
83109 + config PAX_PER_CPU_PGD
83110 + bool
83111 +
83112 + config TASK_SIZE_MAX_SHIFT
83113 + int
83114 + depends on X86_64
83115 + default 47 if !PAX_PER_CPU_PGD
83116 + default 42 if PAX_PER_CPU_PGD
83117 +
83118 + config PAX_ENABLE_PAE
83119 + bool
83120 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
83121 +
83122 + config PAX_USERCOPY_SLABS
83123 + bool
83124 +
83125 +config GRKERNSEC
83126 + bool "Grsecurity"
83127 + select CRYPTO
83128 + select CRYPTO_SHA256
83129 + select PROC_FS
83130 + select STOP_MACHINE
83131 + help
83132 + If you say Y here, you will be able to configure many features
83133 + that will enhance the security of your system. It is highly
83134 + recommended that you say Y here and read through the help
83135 + for each option so that you fully understand the features and
83136 + can evaluate their usefulness for your machine.
83137 +
83138 +choice
83139 + prompt "Configuration Method"
83140 + depends on GRKERNSEC
83141 + default GRKERNSEC_CONFIG_CUSTOM
83142 + help
83143 +
83144 +config GRKERNSEC_CONFIG_AUTO
83145 + bool "Automatic"
83146 + help
83147 + If you choose this configuration method, you'll be able to answer a small
83148 + number of simple questions about how you plan to use this kernel.
83149 + The settings of grsecurity and PaX will be automatically configured for
83150 + the highest commonly-used settings within the provided constraints.
83151 +
83152 + If you require additional configuration, custom changes can still be made
83153 + from the "custom configuration" menu.
83154 +
83155 +config GRKERNSEC_CONFIG_CUSTOM
83156 + bool "Custom"
83157 + help
83158 + If you choose this configuration method, you'll be able to configure all
83159 + grsecurity and PaX settings manually. Via this method, no options are
83160 + automatically enabled.
83161 +
83162 +endchoice
83163 +
83164 +choice
83165 + prompt "Usage Type"
83166 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
83167 + default GRKERNSEC_CONFIG_SERVER
83168 + help
83169 +
83170 +config GRKERNSEC_CONFIG_SERVER
83171 + bool "Server"
83172 + help
83173 + Choose this option if you plan to use this kernel on a server.
83174 +
83175 +config GRKERNSEC_CONFIG_DESKTOP
83176 + bool "Desktop"
83177 + help
83178 + Choose this option if you plan to use this kernel on a desktop.
83179 +
83180 +endchoice
83181 +
83182 +choice
83183 + prompt "Virtualization Type"
83184 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
83185 + default GRKERNSEC_CONFIG_VIRT_NONE
83186 + help
83187 +
83188 +config GRKERNSEC_CONFIG_VIRT_NONE
83189 + bool "None"
83190 + help
83191 + Choose this option if this kernel will be run on bare metal.
83192 +
83193 +config GRKERNSEC_CONFIG_VIRT_GUEST
83194 + bool "Guest"
83195 + help
83196 + Choose this option if this kernel will be run as a VM guest.
83197 +
83198 +config GRKERNSEC_CONFIG_VIRT_HOST
83199 + bool "Host"
83200 + help
83201 + Choose this option if this kernel will be run as a VM host.
83202 +
83203 +endchoice
83204 +
83205 +choice
83206 + prompt "Virtualization Hardware"
83207 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
83208 + help
83209 +
83210 +config GRKERNSEC_CONFIG_VIRT_EPT
83211 + bool "EPT/RVI Processor Support"
83212 + depends on X86
83213 + help
83214 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
83215 + hardware virtualization. This allows for additional kernel hardening protections
83216 + to operate without additional performance impact.
83217 +
83218 + To see if your Intel processor supports EPT, see:
83219 + http://ark.intel.com/Products/VirtualizationTechnology
83220 + (Most Core i3/5/7 support EPT)
83221 +
83222 + To see if your AMD processor supports RVI, see:
83223 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
83224 +
83225 +config GRKERNSEC_CONFIG_VIRT_SOFT
83226 + bool "First-gen/No Hardware Virtualization"
83227 + help
83228 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
83229 + support hardware virtualization or doesn't support the EPT/RVI extensions.
83230 +
83231 +endchoice
83232 +
83233 +choice
83234 + prompt "Virtualization Software"
83235 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
83236 + help
83237 +
83238 +config GRKERNSEC_CONFIG_VIRT_XEN
83239 + bool "Xen"
83240 + help
83241 + Choose this option if this kernel is running as a Xen guest or host.
83242 +
83243 +config GRKERNSEC_CONFIG_VIRT_VMWARE
83244 + bool "VMWare"
83245 + help
83246 + Choose this option if this kernel is running as a VMWare guest or host.
83247 +
83248 +config GRKERNSEC_CONFIG_VIRT_KVM
83249 + bool "KVM"
83250 + help
83251 + Choose this option if this kernel is running as a KVM guest or host.
83252 +
83253 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
83254 + bool "VirtualBox"
83255 + help
83256 + Choose this option if this kernel is running as a VirtualBox guest or host.
83257 +
83258 +endchoice
83259 +
83260 +choice
83261 + prompt "Required Priorities"
83262 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
83263 + default GRKERNSEC_CONFIG_PRIORITY_PERF
83264 + help
83265 +
83266 +config GRKERNSEC_CONFIG_PRIORITY_PERF
83267 + bool "Performance"
83268 + help
83269 + Choose this option if performance is of highest priority for this deployment
83270 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
83271 + and freed memory sanitizing will be disabled.
83272 +
83273 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
83274 + bool "Security"
83275 + help
83276 + Choose this option if security is of highest priority for this deployment of
83277 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
83278 + be enabled for this kernel. In a worst-case scenario, these features can
83279 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
83280 +
83281 +endchoice
83282 +
83283 +menu "Default Special Groups"
83284 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
83285 +
83286 +config GRKERNSEC_PROC_GID
83287 + int "GID exempted from /proc restrictions"
83288 + default 1001
83289 + help
83290 + Setting this GID determines which group will be exempted from
83291 + grsecurity's /proc restrictions, allowing users of the specified
83292 + group to view network statistics and the existence of other users'
83293 + processes on the system. This GID may also be chosen at boot time
83294 + via "grsec_proc_gid=" on the kernel commandline.
83295 +
83296 +config GRKERNSEC_TPE_UNTRUSTED_GID
83297 + int "GID for TPE-untrusted users"
83298 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
83299 + default 1005
83300 + help
83301 + Setting this GID determines which group untrusted users should
83302 + be added to. These users will be placed under grsecurity's Trusted Path
83303 + Execution mechanism, preventing them from executing their own binaries.
83304 + The users will only be able to execute binaries in directories owned and
83305 + writable only by the root user. If the sysctl option is enabled, a sysctl
83306 + option with name "tpe_gid" is created.
83307 +
83308 +config GRKERNSEC_TPE_TRUSTED_GID
83309 + int "GID for TPE-trusted users"
83310 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
83311 + default 1005
83312 + help
83313 + Setting this GID determines what group TPE restrictions will be
83314 + *disabled* for. If the sysctl option is enabled, a sysctl option
83315 + with name "tpe_gid" is created.
83316 +
83317 +config GRKERNSEC_SYMLINKOWN_GID
83318 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
83319 + depends on GRKERNSEC_CONFIG_SERVER
83320 + default 1006
83321 + help
83322 + Setting this GID determines what group kernel-enforced
83323 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
83324 + is enabled, a sysctl option with name "symlinkown_gid" is created.
83325 +
83326 +
83327 +endmenu
83328 +
83329 +menu "Customize Configuration"
83330 +depends on GRKERNSEC
83331 +
83332 +menu "PaX"
83333 +
83334 +config PAX
83335 + bool "Enable various PaX features"
83336 + default y if GRKERNSEC_CONFIG_AUTO
83337 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
83338 + help
83339 + This allows you to enable various PaX features. PaX adds
83340 + intrusion prevention mechanisms to the kernel that reduce
83341 + the risks posed by exploitable memory corruption bugs.
83342 +
83343 +menu "PaX Control"
83344 + depends on PAX
83345 +
83346 +config PAX_SOFTMODE
83347 + bool 'Support soft mode'
83348 + help
83349 + Enabling this option will allow you to run PaX in soft mode, that
83350 + is, PaX features will not be enforced by default, only on executables
83351 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
83352 + support as they are the only way to mark executables for soft mode use.
83353 +
83354 + Soft mode can be activated by using the "pax_softmode=1" kernel command
83355 + line option on boot. Furthermore you can control various PaX features
83356 + at runtime via the entries in /proc/sys/kernel/pax.
83357 +
83358 +config PAX_EI_PAX
83359 + bool 'Use legacy ELF header marking'
83360 + default y if GRKERNSEC_CONFIG_AUTO
83361 + help
83362 + Enabling this option will allow you to control PaX features on
83363 + a per executable basis via the 'chpax' utility available at
83364 + http://pax.grsecurity.net/. The control flags will be read from
83365 + an otherwise reserved part of the ELF header. This marking has
83366 + numerous drawbacks (no support for soft-mode, toolchain does not
83367 + know about the non-standard use of the ELF header) therefore it
83368 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
83369 + support.
83370 +
83371 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
83372 + support as well, they will override the legacy EI_PAX marks.
83373 +
83374 + If you enable none of the marking options then all applications
83375 + will run with PaX enabled on them by default.
83376 +
83377 +config PAX_PT_PAX_FLAGS
83378 + bool 'Use ELF program header marking'
83379 + default y if GRKERNSEC_CONFIG_AUTO
83380 + help
83381 + Enabling this option will allow you to control PaX features on
83382 + a per executable basis via the 'paxctl' utility available at
83383 + http://pax.grsecurity.net/. The control flags will be read from
83384 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
83385 + has the benefits of supporting both soft mode and being fully
83386 + integrated into the toolchain (the binutils patch is available
83387 + from http://pax.grsecurity.net).
83388 +
83389 + Note that if you enable the legacy EI_PAX marking support as well,
83390 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
83391 +
83392 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
83393 + must make sure that the marks are the same if a binary has both marks.
83394 +
83395 + If you enable none of the marking options then all applications
83396 + will run with PaX enabled on them by default.
83397 +
83398 +config PAX_XATTR_PAX_FLAGS
83399 + bool 'Use filesystem extended attributes marking'
83400 + default y if GRKERNSEC_CONFIG_AUTO
83401 + select CIFS_XATTR if CIFS
83402 + select EXT2_FS_XATTR if EXT2_FS
83403 + select EXT3_FS_XATTR if EXT3_FS
83404 + select EXT4_FS_XATTR if EXT4_FS
83405 + select JFFS2_FS_XATTR if JFFS2_FS
83406 + select REISERFS_FS_XATTR if REISERFS_FS
83407 + select SQUASHFS_XATTR if SQUASHFS
83408 + select TMPFS_XATTR if TMPFS
83409 + select UBIFS_FS_XATTR if UBIFS_FS
83410 + help
83411 + Enabling this option will allow you to control PaX features on
83412 + a per executable basis via the 'setfattr' utility. The control
83413 + flags will be read from the user.pax.flags extended attribute of
83414 + the file. This marking has the benefit of supporting binary-only
83415 + applications that self-check themselves (e.g., skype) and would
83416 + not tolerate chpax/paxctl changes. The main drawback is that
83417 + extended attributes are not supported by some filesystems (e.g.,
83418 + isofs, udf, vfat) so copying files through such filesystems will
83419 + lose the extended attributes and these PaX markings.
83420 +
83421 + Note that if you enable the legacy EI_PAX marking support as well,
83422 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
83423 +
83424 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
83425 + must make sure that the marks are the same if a binary has both marks.
83426 +
83427 + If you enable none of the marking options then all applications
83428 + will run with PaX enabled on them by default.
83429 +
83430 +choice
83431 + prompt 'MAC system integration'
83432 + default PAX_HAVE_ACL_FLAGS
83433 + help
83434 + Mandatory Access Control systems have the option of controlling
83435 + PaX flags on a per executable basis, choose the method supported
83436 + by your particular system.
83437 +
83438 + - "none": if your MAC system does not interact with PaX,
83439 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
83440 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
83441 +
83442 + NOTE: this option is for developers/integrators only.
83443 +
83444 + config PAX_NO_ACL_FLAGS
83445 + bool 'none'
83446 +
83447 + config PAX_HAVE_ACL_FLAGS
83448 + bool 'direct'
83449 +
83450 + config PAX_HOOK_ACL_FLAGS
83451 + bool 'hook'
83452 +endchoice
83453 +
83454 +endmenu
83455 +
83456 +menu "Non-executable pages"
83457 + depends on PAX
83458 +
83459 +config PAX_NOEXEC
83460 + bool "Enforce non-executable pages"
83461 + default y if GRKERNSEC_CONFIG_AUTO
83462 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
83463 + help
83464 + By design some architectures do not allow for protecting memory
83465 + pages against execution or even if they do, Linux does not make
83466 + use of this feature. In practice this means that if a page is
83467 + readable (such as the stack or heap) it is also executable.
83468 +
83469 + There is a well known exploit technique that makes use of this
83470 + fact and a common programming mistake where an attacker can
83471 + introduce code of his choice somewhere in the attacked program's
83472 + memory (typically the stack or the heap) and then execute it.
83473 +
83474 + If the attacked program was running with different (typically
83475 + higher) privileges than that of the attacker, then he can elevate
83476 + his own privilege level (e.g. get a root shell, write to files for
83477 + which he does not have write access to, etc).
83478 +
83479 + Enabling this option will let you choose from various features
83480 + that prevent the injection and execution of 'foreign' code in
83481 + a program.
83482 +
83483 + This will also break programs that rely on the old behaviour and
83484 + expect that dynamically allocated memory via the malloc() family
83485 + of functions is executable (which it is not). Notable examples
83486 + are the XFree86 4.x server, the java runtime and wine.
83487 +
83488 +config PAX_PAGEEXEC
83489 + bool "Paging based non-executable pages"
83490 + default y if GRKERNSEC_CONFIG_AUTO
83491 + 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)
83492 + select S390_SWITCH_AMODE if S390
83493 + select S390_EXEC_PROTECT if S390
83494 + select ARCH_TRACK_EXEC_LIMIT if X86_32
83495 + help
83496 + This implementation is based on the paging feature of the CPU.
83497 + On i386 without hardware non-executable bit support there is a
83498 + variable but usually low performance impact, however on Intel's
83499 + P4 core based CPUs it is very high so you should not enable this
83500 + for kernels meant to be used on such CPUs.
83501 +
83502 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
83503 + with hardware non-executable bit support there is no performance
83504 + impact, on ppc the impact is negligible.
83505 +
83506 + Note that several architectures require various emulations due to
83507 + badly designed userland ABIs, this will cause a performance impact
83508 + but will disappear as soon as userland is fixed. For example, ppc
83509 + userland MUST have been built with secure-plt by a recent toolchain.
83510 +
83511 +config PAX_SEGMEXEC
83512 + bool "Segmentation based non-executable pages"
83513 + default y if GRKERNSEC_CONFIG_AUTO
83514 + depends on PAX_NOEXEC && X86_32
83515 + help
83516 + This implementation is based on the segmentation feature of the
83517 + CPU and has a very small performance impact, however applications
83518 + will be limited to a 1.5 GB address space instead of the normal
83519 + 3 GB.
83520 +
83521 +config PAX_EMUTRAMP
83522 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
83523 + default y if PARISC
83524 + help
83525 + There are some programs and libraries that for one reason or
83526 + another attempt to execute special small code snippets from
83527 + non-executable memory pages. Most notable examples are the
83528 + signal handler return code generated by the kernel itself and
83529 + the GCC trampolines.
83530 +
83531 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
83532 + such programs will no longer work under your kernel.
83533 +
83534 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
83535 + utilities to enable trampoline emulation for the affected programs
83536 + yet still have the protection provided by the non-executable pages.
83537 +
83538 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
83539 + your system will not even boot.
83540 +
83541 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
83542 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
83543 + for the affected files.
83544 +
83545 + NOTE: enabling this feature *may* open up a loophole in the
83546 + protection provided by non-executable pages that an attacker
83547 + could abuse. Therefore the best solution is to not have any
83548 + files on your system that would require this option. This can
83549 + be achieved by not using libc5 (which relies on the kernel
83550 + signal handler return code) and not using or rewriting programs
83551 + that make use of the nested function implementation of GCC.
83552 + Skilled users can just fix GCC itself so that it implements
83553 + nested function calls in a way that does not interfere with PaX.
83554 +
83555 +config PAX_EMUSIGRT
83556 + bool "Automatically emulate sigreturn trampolines"
83557 + depends on PAX_EMUTRAMP && PARISC
83558 + default y
83559 + help
83560 + Enabling this option will have the kernel automatically detect
83561 + and emulate signal return trampolines executing on the stack
83562 + that would otherwise lead to task termination.
83563 +
83564 + This solution is intended as a temporary one for users with
83565 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
83566 + Modula-3 runtime, etc) or executables linked to such, basically
83567 + everything that does not specify its own SA_RESTORER function in
83568 + normal executable memory like glibc 2.1+ does.
83569 +
83570 + On parisc you MUST enable this option, otherwise your system will
83571 + not even boot.
83572 +
83573 + NOTE: this feature cannot be disabled on a per executable basis
83574 + and since it *does* open up a loophole in the protection provided
83575 + by non-executable pages, the best solution is to not have any
83576 + files on your system that would require this option.
83577 +
83578 +config PAX_MPROTECT
83579 + bool "Restrict mprotect()"
83580 + default y if GRKERNSEC_CONFIG_AUTO
83581 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
83582 + help
83583 + Enabling this option will prevent programs from
83584 + - changing the executable status of memory pages that were
83585 + not originally created as executable,
83586 + - making read-only executable pages writable again,
83587 + - creating executable pages from anonymous memory,
83588 + - making read-only-after-relocations (RELRO) data pages writable again.
83589 +
83590 + You should say Y here to complete the protection provided by
83591 + the enforcement of non-executable pages.
83592 +
83593 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
83594 + this feature on a per file basis.
83595 +
83596 +config PAX_MPROTECT_COMPAT
83597 + bool "Use legacy/compat protection demoting (read help)"
83598 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
83599 + depends on PAX_MPROTECT
83600 + help
83601 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
83602 + by sending the proper error code to the application. For some broken
83603 + userland, this can cause problems with Python or other applications. The
83604 + current implementation however allows for applications like clamav to
83605 + detect if JIT compilation/execution is allowed and to fall back gracefully
83606 + to an interpreter-based mode if it does not. While we encourage everyone
83607 + to use the current implementation as-is and push upstream to fix broken
83608 + userland (note that the RWX logging option can assist with this), in some
83609 + environments this may not be possible. Having to disable MPROTECT
83610 + completely on certain binaries reduces the security benefit of PaX,
83611 + so this option is provided for those environments to revert to the old
83612 + behavior.
83613 +
83614 +config PAX_ELFRELOCS
83615 + bool "Allow ELF text relocations (read help)"
83616 + depends on PAX_MPROTECT
83617 + default n
83618 + help
83619 + Non-executable pages and mprotect() restrictions are effective
83620 + in preventing the introduction of new executable code into an
83621 + attacked task's address space. There remain only two venues
83622 + for this kind of attack: if the attacker can execute already
83623 + existing code in the attacked task then he can either have it
83624 + create and mmap() a file containing his code or have it mmap()
83625 + an already existing ELF library that does not have position
83626 + independent code in it and use mprotect() on it to make it
83627 + writable and copy his code there. While protecting against
83628 + the former approach is beyond PaX, the latter can be prevented
83629 + by having only PIC ELF libraries on one's system (which do not
83630 + need to relocate their code). If you are sure this is your case,
83631 + as is the case with all modern Linux distributions, then leave
83632 + this option disabled. You should say 'n' here.
83633 +
83634 +config PAX_ETEXECRELOCS
83635 + bool "Allow ELF ET_EXEC text relocations"
83636 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
83637 + select PAX_ELFRELOCS
83638 + default y
83639 + help
83640 + On some architectures there are incorrectly created applications
83641 + that require text relocations and would not work without enabling
83642 + this option. If you are an alpha, ia64 or parisc user, you should
83643 + enable this option and disable it once you have made sure that
83644 + none of your applications need it.
83645 +
83646 +config PAX_EMUPLT
83647 + bool "Automatically emulate ELF PLT"
83648 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
83649 + default y
83650 + help
83651 + Enabling this option will have the kernel automatically detect
83652 + and emulate the Procedure Linkage Table entries in ELF files.
83653 + On some architectures such entries are in writable memory, and
83654 + become non-executable leading to task termination. Therefore
83655 + it is mandatory that you enable this option on alpha, parisc,
83656 + sparc and sparc64, otherwise your system would not even boot.
83657 +
83658 + NOTE: this feature *does* open up a loophole in the protection
83659 + provided by the non-executable pages, therefore the proper
83660 + solution is to modify the toolchain to produce a PLT that does
83661 + not need to be writable.
83662 +
83663 +config PAX_DLRESOLVE
83664 + bool 'Emulate old glibc resolver stub'
83665 + depends on PAX_EMUPLT && SPARC
83666 + default n
83667 + help
83668 + This option is needed if userland has an old glibc (before 2.4)
83669 + that puts a 'save' instruction into the runtime generated resolver
83670 + stub that needs special emulation.
83671 +
83672 +config PAX_KERNEXEC
83673 + bool "Enforce non-executable kernel pages"
83674 + 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))
83675 + depends on (X86 || ARM_LPAE) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
83676 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
83677 + select PAX_KERNEXEC_PLUGIN if X86_64
83678 + help
83679 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
83680 + that is, enabling this option will make it harder to inject
83681 + and execute 'foreign' code in kernel memory itself.
83682 +
83683 +choice
83684 + prompt "Return Address Instrumentation Method"
83685 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
83686 + depends on PAX_KERNEXEC_PLUGIN
83687 + help
83688 + Select the method used to instrument function pointer dereferences.
83689 + Note that binary modules cannot be instrumented by this approach.
83690 +
83691 + Note that the implementation requires a gcc with plugin support,
83692 + i.e., gcc 4.5 or newer. You may need to install the supporting
83693 + headers explicitly in addition to the normal gcc package.
83694 +
83695 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
83696 + bool "bts"
83697 + help
83698 + This method is compatible with binary only modules but has
83699 + a higher runtime overhead.
83700 +
83701 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
83702 + bool "or"
83703 + depends on !PARAVIRT
83704 + help
83705 + This method is incompatible with binary only modules but has
83706 + a lower runtime overhead.
83707 +endchoice
83708 +
83709 +config PAX_KERNEXEC_PLUGIN_METHOD
83710 + string
83711 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
83712 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
83713 + default ""
83714 +
83715 +config PAX_KERNEXEC_MODULE_TEXT
83716 + int "Minimum amount of memory reserved for module code"
83717 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
83718 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
83719 + depends on PAX_KERNEXEC && X86_32 && MODULES
83720 + help
83721 + Due to implementation details the kernel must reserve a fixed
83722 + amount of memory for module code at compile time that cannot be
83723 + changed at runtime. Here you can specify the minimum amount
83724 + in MB that will be reserved. Due to the same implementation
83725 + details this size will always be rounded up to the next 2/4 MB
83726 + boundary (depends on PAE) so the actually available memory for
83727 + module code will usually be more than this minimum.
83728 +
83729 + The default 4 MB should be enough for most users but if you have
83730 + an excessive number of modules (e.g., most distribution configs
83731 + compile many drivers as modules) or use huge modules such as
83732 + nvidia's kernel driver, you will need to adjust this amount.
83733 + A good rule of thumb is to look at your currently loaded kernel
83734 + modules and add up their sizes.
83735 +
83736 +endmenu
83737 +
83738 +menu "Address Space Layout Randomization"
83739 + depends on PAX
83740 +
83741 +config PAX_ASLR
83742 + bool "Address Space Layout Randomization"
83743 + default y if GRKERNSEC_CONFIG_AUTO
83744 + help
83745 + Many if not most exploit techniques rely on the knowledge of
83746 + certain addresses in the attacked program. The following options
83747 + will allow the kernel to apply a certain amount of randomization
83748 + to specific parts of the program thereby forcing an attacker to
83749 + guess them in most cases. Any failed guess will most likely crash
83750 + the attacked program which allows the kernel to detect such attempts
83751 + and react on them. PaX itself provides no reaction mechanisms,
83752 + instead it is strongly encouraged that you make use of Nergal's
83753 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
83754 + (http://www.grsecurity.net/) built-in crash detection features or
83755 + develop one yourself.
83756 +
83757 + By saying Y here you can choose to randomize the following areas:
83758 + - top of the task's kernel stack
83759 + - top of the task's userland stack
83760 + - base address for mmap() requests that do not specify one
83761 + (this includes all libraries)
83762 + - base address of the main executable
83763 +
83764 + It is strongly recommended to say Y here as address space layout
83765 + randomization has negligible impact on performance yet it provides
83766 + a very effective protection.
83767 +
83768 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
83769 + this feature on a per file basis.
83770 +
83771 +config PAX_RANDKSTACK
83772 + bool "Randomize kernel stack base"
83773 + default y if GRKERNSEC_CONFIG_AUTO
83774 + depends on X86_TSC && X86
83775 + help
83776 + By saying Y here the kernel will randomize every task's kernel
83777 + stack on every system call. This will not only force an attacker
83778 + to guess it but also prevent him from making use of possible
83779 + leaked information about it.
83780 +
83781 + Since the kernel stack is a rather scarce resource, randomization
83782 + may cause unexpected stack overflows, therefore you should very
83783 + carefully test your system. Note that once enabled in the kernel
83784 + configuration, this feature cannot be disabled on a per file basis.
83785 +
83786 +config PAX_RANDUSTACK
83787 + bool "Randomize user stack base"
83788 + default y if GRKERNSEC_CONFIG_AUTO
83789 + depends on PAX_ASLR
83790 + help
83791 + By saying Y here the kernel will randomize every task's userland
83792 + stack. The randomization is done in two steps where the second
83793 + one may apply a big amount of shift to the top of the stack and
83794 + cause problems for programs that want to use lots of memory (more
83795 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
83796 + For this reason the second step can be controlled by 'chpax' or
83797 + 'paxctl' on a per file basis.
83798 +
83799 +config PAX_RANDMMAP
83800 + bool "Randomize mmap() base"
83801 + default y if GRKERNSEC_CONFIG_AUTO
83802 + depends on PAX_ASLR
83803 + help
83804 + By saying Y here the kernel will use a randomized base address for
83805 + mmap() requests that do not specify one themselves. As a result
83806 + all dynamically loaded libraries will appear at random addresses
83807 + and therefore be harder to exploit by a technique where an attacker
83808 + attempts to execute library code for his purposes (e.g. spawn a
83809 + shell from an exploited program that is running at an elevated
83810 + privilege level).
83811 +
83812 + Furthermore, if a program is relinked as a dynamic ELF file, its
83813 + base address will be randomized as well, completing the full
83814 + randomization of the address space layout. Attacking such programs
83815 + becomes a guess game. You can find an example of doing this at
83816 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
83817 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
83818 +
83819 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
83820 + feature on a per file basis.
83821 +
83822 +endmenu
83823 +
83824 +menu "Miscellaneous hardening features"
83825 +
83826 +config PAX_MEMORY_SANITIZE
83827 + bool "Sanitize all freed memory"
83828 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
83829 + depends on !HIBERNATION
83830 + help
83831 + By saying Y here the kernel will erase memory pages as soon as they
83832 + are freed. This in turn reduces the lifetime of data stored in the
83833 + pages, making it less likely that sensitive information such as
83834 + passwords, cryptographic secrets, etc stay in memory for too long.
83835 +
83836 + This is especially useful for programs whose runtime is short, long
83837 + lived processes and the kernel itself benefit from this as long as
83838 + they operate on whole memory pages and ensure timely freeing of pages
83839 + that may hold sensitive information.
83840 +
83841 + The tradeoff is performance impact, on a single CPU system kernel
83842 + compilation sees a 3% slowdown, other systems and workloads may vary
83843 + and you are advised to test this feature on your expected workload
83844 + before deploying it.
83845 +
83846 + Note that this feature does not protect data stored in live pages,
83847 + e.g., process memory swapped to disk may stay there for a long time.
83848 +
83849 +config PAX_MEMORY_STACKLEAK
83850 + bool "Sanitize kernel stack"
83851 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
83852 + depends on X86
83853 + help
83854 + By saying Y here the kernel will erase the kernel stack before it
83855 + returns from a system call. This in turn reduces the information
83856 + that a kernel stack leak bug can reveal.
83857 +
83858 + Note that such a bug can still leak information that was put on
83859 + the stack by the current system call (the one eventually triggering
83860 + the bug) but traces of earlier system calls on the kernel stack
83861 + cannot leak anymore.
83862 +
83863 + The tradeoff is performance impact: on a single CPU system kernel
83864 + compilation sees a 1% slowdown, other systems and workloads may vary
83865 + and you are advised to test this feature on your expected workload
83866 + before deploying it.
83867 +
83868 + Note that the full feature requires a gcc with plugin support,
83869 + i.e., gcc 4.5 or newer. You may need to install the supporting
83870 + headers explicitly in addition to the normal gcc package. Using
83871 + older gcc versions means that functions with large enough stack
83872 + frames may leave uninitialized memory behind that may be exposed
83873 + to a later syscall leaking the stack.
83874 +
83875 +config PAX_MEMORY_UDEREF
83876 + bool "Prevent invalid userland pointer dereference"
83877 + default y if GRKERNSEC_CONFIG_AUTO && (X86_32 || (X86_64 && GRKERNSEC_CONFIG_PRIORITY_SECURITY)) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
83878 + depends on X86 && !UML_X86 && !XEN
83879 + select PAX_PER_CPU_PGD if X86_64
83880 + help
83881 + By saying Y here the kernel will be prevented from dereferencing
83882 + userland pointers in contexts where the kernel expects only kernel
83883 + pointers. This is both a useful runtime debugging feature and a
83884 + security measure that prevents exploiting a class of kernel bugs.
83885 +
83886 + The tradeoff is that some virtualization solutions may experience
83887 + a huge slowdown and therefore you should not enable this feature
83888 + for kernels meant to run in such environments. Whether a given VM
83889 + solution is affected or not is best determined by simply trying it
83890 + out, the performance impact will be obvious right on boot as this
83891 + mechanism engages from very early on. A good rule of thumb is that
83892 + VMs running on CPUs without hardware virtualization support (i.e.,
83893 + the majority of IA-32 CPUs) will likely experience the slowdown.
83894 +
83895 +config PAX_REFCOUNT
83896 + bool "Prevent various kernel object reference counter overflows"
83897 + default y if GRKERNSEC_CONFIG_AUTO
83898 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
83899 + help
83900 + By saying Y here the kernel will detect and prevent overflowing
83901 + various (but not all) kinds of object reference counters. Such
83902 + overflows can normally occur due to bugs only and are often, if
83903 + not always, exploitable.
83904 +
83905 + The tradeoff is that data structures protected by an overflowed
83906 + refcount will never be freed and therefore will leak memory. Note
83907 + that this leak also happens even without this protection but in
83908 + that case the overflow can eventually trigger the freeing of the
83909 + data structure while it is still being used elsewhere, resulting
83910 + in the exploitable situation that this feature prevents.
83911 +
83912 + Since this has a negligible performance impact, you should enable
83913 + this feature.
83914 +
83915 +config PAX_USERCOPY
83916 + bool "Harden heap object copies between kernel and userland"
83917 + default y if GRKERNSEC_CONFIG_AUTO
83918 + depends on ARM || IA64 || PPC || SPARC || X86
83919 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
83920 + select PAX_USERCOPY_SLABS
83921 + help
83922 + By saying Y here the kernel will enforce the size of heap objects
83923 + when they are copied in either direction between the kernel and
83924 + userland, even if only a part of the heap object is copied.
83925 +
83926 + Specifically, this checking prevents information leaking from the
83927 + kernel heap during kernel to userland copies (if the kernel heap
83928 + object is otherwise fully initialized) and prevents kernel heap
83929 + overflows during userland to kernel copies.
83930 +
83931 + Note that the current implementation provides the strictest bounds
83932 + checks for the SLUB allocator.
83933 +
83934 + Enabling this option also enables per-slab cache protection against
83935 + data in a given cache being copied into/out of via userland
83936 + accessors. Though the whitelist of regions will be reduced over
83937 + time, it notably protects important data structures like task structs.
83938 +
83939 + If frame pointers are enabled on x86, this option will also restrict
83940 + copies into and out of the kernel stack to local variables within a
83941 + single frame.
83942 +
83943 + Since this has a negligible performance impact, you should enable
83944 + this feature.
83945 +
83946 +
83947 +config PAX_USERCOPY_DEBUG
83948 + bool
83949 + depends on X86 && PAX_USERCOPY
83950 + default n
83951 +
83952 +config PAX_SIZE_OVERFLOW
83953 + bool "Prevent various integer overflows in function size parameters"
83954 + default y if GRKERNSEC_CONFIG_AUTO
83955 + depends on X86
83956 + help
83957 + By saying Y here the kernel recomputes expressions of function
83958 + arguments marked by a size_overflow attribute with double integer
83959 + precision (DImode/TImode for 32/64 bit integer types).
83960 +
83961 + The recomputed argument is checked against TYPE_MAX and an event
83962 + is logged on overflow and the triggering process is killed.
83963 +
83964 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
83965 +
83966 + Note that the implementation requires a gcc with plugin support,
83967 + i.e., gcc 4.5 or newer. You may need to install the supporting
83968 + headers explicitly in addition to the normal gcc package.
83969 +
83970 +config PAX_LATENT_ENTROPY
83971 + bool "Generate some entropy during boot"
83972 + default y if GRKERNSEC_CONFIG_AUTO
83973 + help
83974 + By saying Y here the kernel will instrument early boot code to
83975 + extract some entropy from both original and artificially created
83976 + program state. This will help especially embedded systems where
83977 + there is little 'natural' source of entropy normally. The cost
83978 + is some slowdown of the boot process.
83979 +
83980 + Note that the implementation requires a gcc with plugin support,
83981 + i.e., gcc 4.5 or newer. You may need to install the supporting
83982 + headers explicitly in addition to the normal gcc package.
83983 +
83984 + Note that entropy extracted this way is not cryptographically
83985 + secure!
83986 +
83987 +endmenu
83988 +
83989 +endmenu
83990 +
83991 +source grsecurity/Kconfig
83992 +
83993 +endmenu
83994 +
83995 +endmenu
83996 +
83997 source security/keys/Kconfig
83998
83999 config SECURITY_DMESG_RESTRICT
84000 @@ -103,7 +999,7 @@ config INTEL_TXT
84001 config LSM_MMAP_MIN_ADDR
84002 int "Low address space for LSM to protect from user allocation"
84003 depends on SECURITY && SECURITY_SELINUX
84004 - default 32768 if ARM
84005 + default 32768 if ALPHA || ARM || PARISC || SPARC32
84006 default 65536
84007 help
84008 This is the portion of low virtual memory which should be protected
84009 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
84010 index 8c2a7f6..b133ac9 100644
84011 --- a/security/apparmor/lsm.c
84012 +++ b/security/apparmor/lsm.c
84013 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
84014 return error;
84015 }
84016
84017 -static struct security_operations apparmor_ops = {
84018 +static struct security_operations apparmor_ops __read_only = {
84019 .name = "apparmor",
84020
84021 .ptrace_access_check = apparmor_ptrace_access_check,
84022 diff --git a/security/commoncap.c b/security/commoncap.c
84023 index 6dbae46..d5611fd 100644
84024 --- a/security/commoncap.c
84025 +++ b/security/commoncap.c
84026 @@ -415,6 +415,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
84027 return 0;
84028 }
84029
84030 +/* returns:
84031 + 1 for suid privilege
84032 + 2 for sgid privilege
84033 + 3 for fscap privilege
84034 +*/
84035 +int is_privileged_binary(const struct dentry *dentry)
84036 +{
84037 + struct cpu_vfs_cap_data capdata;
84038 + struct inode *inode = dentry->d_inode;
84039 +
84040 + if (!inode || S_ISDIR(inode->i_mode))
84041 + return 0;
84042 +
84043 + if (inode->i_mode & S_ISUID)
84044 + return 1;
84045 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
84046 + return 2;
84047 +
84048 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
84049 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
84050 + return 3;
84051 + }
84052 +
84053 + return 0;
84054 +}
84055 +
84056 /*
84057 * Attempt to get the on-exec apply capability sets for an executable file from
84058 * its xattrs and, if present, apply them to the proposed credentials being
84059 @@ -583,6 +609,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
84060 const struct cred *cred = current_cred();
84061 kuid_t root_uid = make_kuid(cred->user_ns, 0);
84062
84063 + if (gr_acl_enable_at_secure())
84064 + return 1;
84065 +
84066 if (!uid_eq(cred->uid, root_uid)) {
84067 if (bprm->cap_effective)
84068 return 1;
84069 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
84070 index 6ee8826..6350060 100644
84071 --- a/security/integrity/ima/ima.h
84072 +++ b/security/integrity/ima/ima.h
84073 @@ -96,8 +96,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
84074 extern spinlock_t ima_queue_lock;
84075
84076 struct ima_h_table {
84077 - atomic_long_t len; /* number of stored measurements in the list */
84078 - atomic_long_t violations;
84079 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
84080 + atomic_long_unchecked_t violations;
84081 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
84082 };
84083 extern struct ima_h_table ima_htable;
84084 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
84085 index b356884..fd9676e 100644
84086 --- a/security/integrity/ima/ima_api.c
84087 +++ b/security/integrity/ima/ima_api.c
84088 @@ -79,7 +79,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
84089 int result;
84090
84091 /* can overflow, only indicator */
84092 - atomic_long_inc(&ima_htable.violations);
84093 + atomic_long_inc_unchecked(&ima_htable.violations);
84094
84095 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
84096 if (!entry) {
84097 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
84098 index 38477c9..87a60c7 100644
84099 --- a/security/integrity/ima/ima_fs.c
84100 +++ b/security/integrity/ima/ima_fs.c
84101 @@ -28,12 +28,12 @@
84102 static int valid_policy = 1;
84103 #define TMPBUFLEN 12
84104 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
84105 - loff_t *ppos, atomic_long_t *val)
84106 + loff_t *ppos, atomic_long_unchecked_t *val)
84107 {
84108 char tmpbuf[TMPBUFLEN];
84109 ssize_t len;
84110
84111 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
84112 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
84113 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
84114 }
84115
84116 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
84117 index 55a6271..ad829c3 100644
84118 --- a/security/integrity/ima/ima_queue.c
84119 +++ b/security/integrity/ima/ima_queue.c
84120 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
84121 INIT_LIST_HEAD(&qe->later);
84122 list_add_tail_rcu(&qe->later, &ima_measurements);
84123
84124 - atomic_long_inc(&ima_htable.len);
84125 + atomic_long_inc_unchecked(&ima_htable.len);
84126 key = ima_hash_key(entry->digest);
84127 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
84128 return 0;
84129 diff --git a/security/keys/compat.c b/security/keys/compat.c
84130 index 1c26176..64a1ba2 100644
84131 --- a/security/keys/compat.c
84132 +++ b/security/keys/compat.c
84133 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
84134 if (ret == 0)
84135 goto no_payload_free;
84136
84137 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
84138 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
84139
84140 if (iov != iovstack)
84141 kfree(iov);
84142 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
84143 index 5d34b4e..2456674 100644
84144 --- a/security/keys/keyctl.c
84145 +++ b/security/keys/keyctl.c
84146 @@ -986,7 +986,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
84147 /*
84148 * Copy the iovec data from userspace
84149 */
84150 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
84151 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
84152 unsigned ioc)
84153 {
84154 for (; ioc > 0; ioc--) {
84155 @@ -1008,7 +1008,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
84156 * If successful, 0 will be returned.
84157 */
84158 long keyctl_instantiate_key_common(key_serial_t id,
84159 - const struct iovec *payload_iov,
84160 + const struct iovec __user *payload_iov,
84161 unsigned ioc,
84162 size_t plen,
84163 key_serial_t ringid)
84164 @@ -1103,7 +1103,7 @@ long keyctl_instantiate_key(key_serial_t id,
84165 [0].iov_len = plen
84166 };
84167
84168 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
84169 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
84170 }
84171
84172 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
84173 @@ -1136,7 +1136,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
84174 if (ret == 0)
84175 goto no_payload_free;
84176
84177 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
84178 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
84179
84180 if (iov != iovstack)
84181 kfree(iov);
84182 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
84183 index 6e42df1..aba52bd 100644
84184 --- a/security/keys/keyring.c
84185 +++ b/security/keys/keyring.c
84186 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
84187 ret = -EFAULT;
84188
84189 for (loop = 0; loop < klist->nkeys; loop++) {
84190 + key_serial_t serial;
84191 key = rcu_deref_link_locked(klist, loop,
84192 keyring);
84193 + serial = key->serial;
84194
84195 tmp = sizeof(key_serial_t);
84196 if (tmp > buflen)
84197 tmp = buflen;
84198
84199 - if (copy_to_user(buffer,
84200 - &key->serial,
84201 - tmp) != 0)
84202 + if (copy_to_user(buffer, &serial, tmp))
84203 goto error;
84204
84205 buflen -= tmp;
84206 diff --git a/security/min_addr.c b/security/min_addr.c
84207 index f728728..6457a0c 100644
84208 --- a/security/min_addr.c
84209 +++ b/security/min_addr.c
84210 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
84211 */
84212 static void update_mmap_min_addr(void)
84213 {
84214 +#ifndef SPARC
84215 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
84216 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
84217 mmap_min_addr = dac_mmap_min_addr;
84218 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
84219 #else
84220 mmap_min_addr = dac_mmap_min_addr;
84221 #endif
84222 +#endif
84223 }
84224
84225 /*
84226 diff --git a/security/security.c b/security/security.c
84227 index 8dcd4ae..1124de7 100644
84228 --- a/security/security.c
84229 +++ b/security/security.c
84230 @@ -20,6 +20,7 @@
84231 #include <linux/ima.h>
84232 #include <linux/evm.h>
84233 #include <linux/fsnotify.h>
84234 +#include <linux/mm.h>
84235 #include <linux/mman.h>
84236 #include <linux/mount.h>
84237 #include <linux/personality.h>
84238 @@ -32,8 +33,8 @@
84239 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
84240 CONFIG_DEFAULT_SECURITY;
84241
84242 -static struct security_operations *security_ops;
84243 -static struct security_operations default_security_ops = {
84244 +static struct security_operations *security_ops __read_only;
84245 +static struct security_operations default_security_ops __read_only = {
84246 .name = "default",
84247 };
84248
84249 @@ -74,7 +75,9 @@ int __init security_init(void)
84250
84251 void reset_security_ops(void)
84252 {
84253 + pax_open_kernel();
84254 security_ops = &default_security_ops;
84255 + pax_close_kernel();
84256 }
84257
84258 /* Save user chosen LSM */
84259 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
84260 index 61a5336..27215d8 100644
84261 --- a/security/selinux/hooks.c
84262 +++ b/security/selinux/hooks.c
84263 @@ -95,8 +95,6 @@
84264
84265 #define NUM_SEL_MNT_OPTS 5
84266
84267 -extern struct security_operations *security_ops;
84268 -
84269 /* SECMARK reference count */
84270 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
84271
84272 @@ -5476,7 +5474,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
84273
84274 #endif
84275
84276 -static struct security_operations selinux_ops = {
84277 +static struct security_operations selinux_ops __read_only = {
84278 .name = "selinux",
84279
84280 .ptrace_access_check = selinux_ptrace_access_check,
84281 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
84282 index 65f67cb..3f141ef 100644
84283 --- a/security/selinux/include/xfrm.h
84284 +++ b/security/selinux/include/xfrm.h
84285 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
84286
84287 static inline void selinux_xfrm_notify_policyload(void)
84288 {
84289 - atomic_inc(&flow_cache_genid);
84290 + atomic_inc_unchecked(&flow_cache_genid);
84291 rt_genid_bump(&init_net);
84292 }
84293 #else
84294 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
84295 index 38be92c..21f49ee 100644
84296 --- a/security/smack/smack_lsm.c
84297 +++ b/security/smack/smack_lsm.c
84298 @@ -3398,7 +3398,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
84299 return 0;
84300 }
84301
84302 -struct security_operations smack_ops = {
84303 +struct security_operations smack_ops __read_only = {
84304 .name = "smack",
84305
84306 .ptrace_access_check = smack_ptrace_access_check,
84307 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
84308 index a2ee362..5754f34 100644
84309 --- a/security/tomoyo/tomoyo.c
84310 +++ b/security/tomoyo/tomoyo.c
84311 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
84312 * tomoyo_security_ops is a "struct security_operations" which is used for
84313 * registering TOMOYO.
84314 */
84315 -static struct security_operations tomoyo_security_ops = {
84316 +static struct security_operations tomoyo_security_ops __read_only = {
84317 .name = "tomoyo",
84318 .cred_alloc_blank = tomoyo_cred_alloc_blank,
84319 .cred_prepare = tomoyo_cred_prepare,
84320 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
84321 index 20ef514..4182bed 100644
84322 --- a/security/yama/Kconfig
84323 +++ b/security/yama/Kconfig
84324 @@ -1,6 +1,6 @@
84325 config SECURITY_YAMA
84326 bool "Yama support"
84327 - depends on SECURITY
84328 + depends on SECURITY && !GRKERNSEC
84329 select SECURITYFS
84330 select SECURITY_PATH
84331 default n
84332 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
84333 index 4cedc69..e59d8a3 100644
84334 --- a/sound/aoa/codecs/onyx.c
84335 +++ b/sound/aoa/codecs/onyx.c
84336 @@ -54,7 +54,7 @@ struct onyx {
84337 spdif_locked:1,
84338 analog_locked:1,
84339 original_mute:2;
84340 - int open_count;
84341 + local_t open_count;
84342 struct codec_info *codec_info;
84343
84344 /* mutex serializes concurrent access to the device
84345 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
84346 struct onyx *onyx = cii->codec_data;
84347
84348 mutex_lock(&onyx->mutex);
84349 - onyx->open_count++;
84350 + local_inc(&onyx->open_count);
84351 mutex_unlock(&onyx->mutex);
84352
84353 return 0;
84354 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
84355 struct onyx *onyx = cii->codec_data;
84356
84357 mutex_lock(&onyx->mutex);
84358 - onyx->open_count--;
84359 - if (!onyx->open_count)
84360 + if (local_dec_and_test(&onyx->open_count))
84361 onyx->spdif_locked = onyx->analog_locked = 0;
84362 mutex_unlock(&onyx->mutex);
84363
84364 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
84365 index ffd2025..df062c9 100644
84366 --- a/sound/aoa/codecs/onyx.h
84367 +++ b/sound/aoa/codecs/onyx.h
84368 @@ -11,6 +11,7 @@
84369 #include <linux/i2c.h>
84370 #include <asm/pmac_low_i2c.h>
84371 #include <asm/prom.h>
84372 +#include <asm/local.h>
84373
84374 /* PCM3052 register definitions */
84375
84376 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
84377 index 4c1cc51..16040040 100644
84378 --- a/sound/core/oss/pcm_oss.c
84379 +++ b/sound/core/oss/pcm_oss.c
84380 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
84381 if (in_kernel) {
84382 mm_segment_t fs;
84383 fs = snd_enter_user();
84384 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
84385 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
84386 snd_leave_user(fs);
84387 } else {
84388 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
84389 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
84390 }
84391 if (ret != -EPIPE && ret != -ESTRPIPE)
84392 break;
84393 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
84394 if (in_kernel) {
84395 mm_segment_t fs;
84396 fs = snd_enter_user();
84397 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
84398 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
84399 snd_leave_user(fs);
84400 } else {
84401 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
84402 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
84403 }
84404 if (ret == -EPIPE) {
84405 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
84406 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
84407 struct snd_pcm_plugin_channel *channels;
84408 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
84409 if (!in_kernel) {
84410 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
84411 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
84412 return -EFAULT;
84413 buf = runtime->oss.buffer;
84414 }
84415 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
84416 }
84417 } else {
84418 tmp = snd_pcm_oss_write2(substream,
84419 - (const char __force *)buf,
84420 + (const char __force_kernel *)buf,
84421 runtime->oss.period_bytes, 0);
84422 if (tmp <= 0)
84423 goto err;
84424 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
84425 struct snd_pcm_runtime *runtime = substream->runtime;
84426 snd_pcm_sframes_t frames, frames1;
84427 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
84428 - char __user *final_dst = (char __force __user *)buf;
84429 + char __user *final_dst = (char __force_user *)buf;
84430 if (runtime->oss.plugin_first) {
84431 struct snd_pcm_plugin_channel *channels;
84432 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
84433 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
84434 xfer += tmp;
84435 runtime->oss.buffer_used -= tmp;
84436 } else {
84437 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
84438 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
84439 runtime->oss.period_bytes, 0);
84440 if (tmp <= 0)
84441 goto err;
84442 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
84443 size1);
84444 size1 /= runtime->channels; /* frames */
84445 fs = snd_enter_user();
84446 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
84447 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
84448 snd_leave_user(fs);
84449 }
84450 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
84451 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
84452 index 91cdf943..4085161 100644
84453 --- a/sound/core/pcm_compat.c
84454 +++ b/sound/core/pcm_compat.c
84455 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
84456 int err;
84457
84458 fs = snd_enter_user();
84459 - err = snd_pcm_delay(substream, &delay);
84460 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
84461 snd_leave_user(fs);
84462 if (err < 0)
84463 return err;
84464 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
84465 index f9ddecf..e27404d 100644
84466 --- a/sound/core/pcm_native.c
84467 +++ b/sound/core/pcm_native.c
84468 @@ -2804,11 +2804,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
84469 switch (substream->stream) {
84470 case SNDRV_PCM_STREAM_PLAYBACK:
84471 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
84472 - (void __user *)arg);
84473 + (void __force_user *)arg);
84474 break;
84475 case SNDRV_PCM_STREAM_CAPTURE:
84476 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
84477 - (void __user *)arg);
84478 + (void __force_user *)arg);
84479 break;
84480 default:
84481 result = -EINVAL;
84482 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
84483 index 60e8fc1..786abcb 100644
84484 --- a/sound/core/seq/seq_device.c
84485 +++ b/sound/core/seq/seq_device.c
84486 @@ -64,7 +64,7 @@ struct ops_list {
84487 int argsize; /* argument size */
84488
84489 /* operators */
84490 - struct snd_seq_dev_ops ops;
84491 + struct snd_seq_dev_ops *ops;
84492
84493 /* registred devices */
84494 struct list_head dev_list; /* list of devices */
84495 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
84496
84497 mutex_lock(&ops->reg_mutex);
84498 /* copy driver operators */
84499 - ops->ops = *entry;
84500 + ops->ops = entry;
84501 ops->driver |= DRIVER_LOADED;
84502 ops->argsize = argsize;
84503
84504 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
84505 dev->name, ops->id, ops->argsize, dev->argsize);
84506 return -EINVAL;
84507 }
84508 - if (ops->ops.init_device(dev) >= 0) {
84509 + if (ops->ops->init_device(dev) >= 0) {
84510 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
84511 ops->num_init_devices++;
84512 } else {
84513 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
84514 dev->name, ops->id, ops->argsize, dev->argsize);
84515 return -EINVAL;
84516 }
84517 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
84518 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
84519 dev->status = SNDRV_SEQ_DEVICE_FREE;
84520 dev->driver_data = NULL;
84521 ops->num_init_devices--;
84522 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
84523 index 2d5514b..3afae9c 100644
84524 --- a/sound/drivers/mts64.c
84525 +++ b/sound/drivers/mts64.c
84526 @@ -29,6 +29,7 @@
84527 #include <sound/initval.h>
84528 #include <sound/rawmidi.h>
84529 #include <sound/control.h>
84530 +#include <asm/local.h>
84531
84532 #define CARD_NAME "Miditerminal 4140"
84533 #define DRIVER_NAME "MTS64"
84534 @@ -67,7 +68,7 @@ struct mts64 {
84535 struct pardevice *pardev;
84536 int pardev_claimed;
84537
84538 - int open_count;
84539 + local_t open_count;
84540 int current_midi_output_port;
84541 int current_midi_input_port;
84542 u8 mode[MTS64_NUM_INPUT_PORTS];
84543 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
84544 {
84545 struct mts64 *mts = substream->rmidi->private_data;
84546
84547 - if (mts->open_count == 0) {
84548 + if (local_read(&mts->open_count) == 0) {
84549 /* We don't need a spinlock here, because this is just called
84550 if the device has not been opened before.
84551 So there aren't any IRQs from the device */
84552 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
84553
84554 msleep(50);
84555 }
84556 - ++(mts->open_count);
84557 + local_inc(&mts->open_count);
84558
84559 return 0;
84560 }
84561 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
84562 struct mts64 *mts = substream->rmidi->private_data;
84563 unsigned long flags;
84564
84565 - --(mts->open_count);
84566 - if (mts->open_count == 0) {
84567 + if (local_dec_return(&mts->open_count) == 0) {
84568 /* We need the spinlock_irqsave here because we can still
84569 have IRQs at this point */
84570 spin_lock_irqsave(&mts->lock, flags);
84571 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
84572
84573 msleep(500);
84574
84575 - } else if (mts->open_count < 0)
84576 - mts->open_count = 0;
84577 + } else if (local_read(&mts->open_count) < 0)
84578 + local_set(&mts->open_count, 0);
84579
84580 return 0;
84581 }
84582 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
84583 index b953fb4..1999c01 100644
84584 --- a/sound/drivers/opl4/opl4_lib.c
84585 +++ b/sound/drivers/opl4/opl4_lib.c
84586 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
84587 MODULE_DESCRIPTION("OPL4 driver");
84588 MODULE_LICENSE("GPL");
84589
84590 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
84591 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
84592 {
84593 int timeout = 10;
84594 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
84595 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
84596 index 8364855..59f2e2b 100644
84597 --- a/sound/drivers/portman2x4.c
84598 +++ b/sound/drivers/portman2x4.c
84599 @@ -48,6 +48,7 @@
84600 #include <sound/initval.h>
84601 #include <sound/rawmidi.h>
84602 #include <sound/control.h>
84603 +#include <asm/local.h>
84604
84605 #define CARD_NAME "Portman 2x4"
84606 #define DRIVER_NAME "portman"
84607 @@ -85,7 +86,7 @@ struct portman {
84608 struct pardevice *pardev;
84609 int pardev_claimed;
84610
84611 - int open_count;
84612 + local_t open_count;
84613 int mode[PORTMAN_NUM_INPUT_PORTS];
84614 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
84615 };
84616 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
84617 index ea995af..f1bfa37 100644
84618 --- a/sound/firewire/amdtp.c
84619 +++ b/sound/firewire/amdtp.c
84620 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
84621 ptr = s->pcm_buffer_pointer + data_blocks;
84622 if (ptr >= pcm->runtime->buffer_size)
84623 ptr -= pcm->runtime->buffer_size;
84624 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
84625 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
84626
84627 s->pcm_period_pointer += data_blocks;
84628 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
84629 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
84630 */
84631 void amdtp_out_stream_update(struct amdtp_out_stream *s)
84632 {
84633 - ACCESS_ONCE(s->source_node_id_field) =
84634 + ACCESS_ONCE_RW(s->source_node_id_field) =
84635 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
84636 }
84637 EXPORT_SYMBOL(amdtp_out_stream_update);
84638 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
84639 index b680c5e..061b7a0 100644
84640 --- a/sound/firewire/amdtp.h
84641 +++ b/sound/firewire/amdtp.h
84642 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
84643 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
84644 struct snd_pcm_substream *pcm)
84645 {
84646 - ACCESS_ONCE(s->pcm) = pcm;
84647 + ACCESS_ONCE_RW(s->pcm) = pcm;
84648 }
84649
84650 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
84651 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
84652 index d428ffe..751ef78 100644
84653 --- a/sound/firewire/isight.c
84654 +++ b/sound/firewire/isight.c
84655 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
84656 ptr += count;
84657 if (ptr >= runtime->buffer_size)
84658 ptr -= runtime->buffer_size;
84659 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
84660 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
84661
84662 isight->period_counter += count;
84663 if (isight->period_counter >= runtime->period_size) {
84664 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
84665 if (err < 0)
84666 return err;
84667
84668 - ACCESS_ONCE(isight->pcm_active) = true;
84669 + ACCESS_ONCE_RW(isight->pcm_active) = true;
84670
84671 return 0;
84672 }
84673 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
84674 {
84675 struct isight *isight = substream->private_data;
84676
84677 - ACCESS_ONCE(isight->pcm_active) = false;
84678 + ACCESS_ONCE_RW(isight->pcm_active) = false;
84679
84680 mutex_lock(&isight->mutex);
84681 isight_stop_streaming(isight);
84682 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
84683
84684 switch (cmd) {
84685 case SNDRV_PCM_TRIGGER_START:
84686 - ACCESS_ONCE(isight->pcm_running) = true;
84687 + ACCESS_ONCE_RW(isight->pcm_running) = true;
84688 break;
84689 case SNDRV_PCM_TRIGGER_STOP:
84690 - ACCESS_ONCE(isight->pcm_running) = false;
84691 + ACCESS_ONCE_RW(isight->pcm_running) = false;
84692 break;
84693 default:
84694 return -EINVAL;
84695 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
84696 index b2b3c01..e1c1e1f 100644
84697 --- a/sound/oss/sb_audio.c
84698 +++ b/sound/oss/sb_audio.c
84699 @@ -903,7 +903,7 @@ sb16_copy_from_user(int dev,
84700 buf16 = (signed short *)(localbuf + localoffs);
84701 while (c)
84702 {
84703 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
84704 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
84705 if (copy_from_user(lbuf8,
84706 userbuf+useroffs + p,
84707 locallen))
84708 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
84709 index 7d8803a..559f8d0 100644
84710 --- a/sound/oss/swarm_cs4297a.c
84711 +++ b/sound/oss/swarm_cs4297a.c
84712 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
84713 {
84714 struct cs4297a_state *s;
84715 u32 pwr, id;
84716 - mm_segment_t fs;
84717 int rval;
84718 #ifndef CONFIG_BCM_CS4297A_CSWARM
84719 u64 cfg;
84720 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
84721 if (!rval) {
84722 char *sb1250_duart_present;
84723
84724 +#if 0
84725 + mm_segment_t fs;
84726 fs = get_fs();
84727 set_fs(KERNEL_DS);
84728 -#if 0
84729 val = SOUND_MASK_LINE;
84730 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
84731 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
84732 val = initvol[i].vol;
84733 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
84734 }
84735 + set_fs(fs);
84736 // cs4297a_write_ac97(s, 0x18, 0x0808);
84737 #else
84738 // cs4297a_write_ac97(s, 0x5e, 0x180);
84739 cs4297a_write_ac97(s, 0x02, 0x0808);
84740 cs4297a_write_ac97(s, 0x18, 0x0808);
84741 #endif
84742 - set_fs(fs);
84743
84744 list_add(&s->list, &cs4297a_devs);
84745
84746 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
84747 index 4631a23..001ae57 100644
84748 --- a/sound/pci/ymfpci/ymfpci.h
84749 +++ b/sound/pci/ymfpci/ymfpci.h
84750 @@ -358,7 +358,7 @@ struct snd_ymfpci {
84751 spinlock_t reg_lock;
84752 spinlock_t voice_lock;
84753 wait_queue_head_t interrupt_sleep;
84754 - atomic_t interrupt_sleep_count;
84755 + atomic_unchecked_t interrupt_sleep_count;
84756 struct snd_info_entry *proc_entry;
84757 const struct firmware *dsp_microcode;
84758 const struct firmware *controller_microcode;
84759 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
84760 index 3a6f03f..bc5c86c 100644
84761 --- a/sound/pci/ymfpci/ymfpci_main.c
84762 +++ b/sound/pci/ymfpci/ymfpci_main.c
84763 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
84764 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
84765 break;
84766 }
84767 - if (atomic_read(&chip->interrupt_sleep_count)) {
84768 - atomic_set(&chip->interrupt_sleep_count, 0);
84769 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
84770 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
84771 wake_up(&chip->interrupt_sleep);
84772 }
84773 __end:
84774 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
84775 continue;
84776 init_waitqueue_entry(&wait, current);
84777 add_wait_queue(&chip->interrupt_sleep, &wait);
84778 - atomic_inc(&chip->interrupt_sleep_count);
84779 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
84780 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
84781 remove_wait_queue(&chip->interrupt_sleep, &wait);
84782 }
84783 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
84784 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
84785 spin_unlock(&chip->reg_lock);
84786
84787 - if (atomic_read(&chip->interrupt_sleep_count)) {
84788 - atomic_set(&chip->interrupt_sleep_count, 0);
84789 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
84790 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
84791 wake_up(&chip->interrupt_sleep);
84792 }
84793 }
84794 @@ -2420,7 +2420,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
84795 spin_lock_init(&chip->reg_lock);
84796 spin_lock_init(&chip->voice_lock);
84797 init_waitqueue_head(&chip->interrupt_sleep);
84798 - atomic_set(&chip->interrupt_sleep_count, 0);
84799 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
84800 chip->card = card;
84801 chip->pci = pci;
84802 chip->irq = -1;
84803 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
84804 new file mode 100644
84805 index 0000000..50f2f2f
84806 --- /dev/null
84807 +++ b/tools/gcc/.gitignore
84808 @@ -0,0 +1 @@
84809 +size_overflow_hash.h
84810 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
84811 new file mode 100644
84812 index 0000000..1d09b7e
84813 --- /dev/null
84814 +++ b/tools/gcc/Makefile
84815 @@ -0,0 +1,43 @@
84816 +#CC := gcc
84817 +#PLUGIN_SOURCE_FILES := pax_plugin.c
84818 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
84819 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
84820 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
84821 +
84822 +ifeq ($(PLUGINCC),$(HOSTCC))
84823 +HOSTLIBS := hostlibs
84824 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
84825 +else
84826 +HOSTLIBS := hostcxxlibs
84827 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
84828 +endif
84829 +
84830 +$(HOSTLIBS)-y := constify_plugin.so
84831 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
84832 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
84833 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
84834 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
84835 +$(HOSTLIBS)-y += colorize_plugin.so
84836 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
84837 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
84838 +
84839 +always := $($(HOSTLIBS)-y)
84840 +
84841 +constify_plugin-objs := constify_plugin.o
84842 +stackleak_plugin-objs := stackleak_plugin.o
84843 +kallocstat_plugin-objs := kallocstat_plugin.o
84844 +kernexec_plugin-objs := kernexec_plugin.o
84845 +checker_plugin-objs := checker_plugin.o
84846 +colorize_plugin-objs := colorize_plugin.o
84847 +size_overflow_plugin-objs := size_overflow_plugin.o
84848 +latent_entropy_plugin-objs := latent_entropy_plugin.o
84849 +
84850 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
84851 +
84852 +quiet_cmd_build_size_overflow_hash = GENHASH $@
84853 + cmd_build_size_overflow_hash = \
84854 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
84855 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
84856 + $(call if_changed,build_size_overflow_hash)
84857 +
84858 +targets += size_overflow_hash.h
84859 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
84860 new file mode 100644
84861 index 0000000..d41b5af
84862 --- /dev/null
84863 +++ b/tools/gcc/checker_plugin.c
84864 @@ -0,0 +1,171 @@
84865 +/*
84866 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
84867 + * Licensed under the GPL v2
84868 + *
84869 + * Note: the choice of the license means that the compilation process is
84870 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
84871 + * but for the kernel it doesn't matter since it doesn't link against
84872 + * any of the gcc libraries
84873 + *
84874 + * gcc plugin to implement various sparse (source code checker) features
84875 + *
84876 + * TODO:
84877 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
84878 + *
84879 + * BUGS:
84880 + * - none known
84881 + */
84882 +#include "gcc-plugin.h"
84883 +#include "config.h"
84884 +#include "system.h"
84885 +#include "coretypes.h"
84886 +#include "tree.h"
84887 +#include "tree-pass.h"
84888 +#include "flags.h"
84889 +#include "intl.h"
84890 +#include "toplev.h"
84891 +#include "plugin.h"
84892 +//#include "expr.h" where are you...
84893 +#include "diagnostic.h"
84894 +#include "plugin-version.h"
84895 +#include "tm.h"
84896 +#include "function.h"
84897 +#include "basic-block.h"
84898 +#include "gimple.h"
84899 +#include "rtl.h"
84900 +#include "emit-rtl.h"
84901 +#include "tree-flow.h"
84902 +#include "target.h"
84903 +
84904 +extern void c_register_addr_space (const char *str, addr_space_t as);
84905 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
84906 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
84907 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
84908 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
84909 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
84910 +
84911 +extern void print_gimple_stmt(FILE *, gimple, int, int);
84912 +extern rtx emit_move_insn(rtx x, rtx y);
84913 +
84914 +int plugin_is_GPL_compatible;
84915 +
84916 +static struct plugin_info checker_plugin_info = {
84917 + .version = "201111150100",
84918 +};
84919 +
84920 +#define ADDR_SPACE_KERNEL 0
84921 +#define ADDR_SPACE_FORCE_KERNEL 1
84922 +#define ADDR_SPACE_USER 2
84923 +#define ADDR_SPACE_FORCE_USER 3
84924 +#define ADDR_SPACE_IOMEM 0
84925 +#define ADDR_SPACE_FORCE_IOMEM 0
84926 +#define ADDR_SPACE_PERCPU 0
84927 +#define ADDR_SPACE_FORCE_PERCPU 0
84928 +#define ADDR_SPACE_RCU 0
84929 +#define ADDR_SPACE_FORCE_RCU 0
84930 +
84931 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
84932 +{
84933 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
84934 +}
84935 +
84936 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
84937 +{
84938 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
84939 +}
84940 +
84941 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
84942 +{
84943 + return default_addr_space_valid_pointer_mode(mode, as);
84944 +}
84945 +
84946 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
84947 +{
84948 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
84949 +}
84950 +
84951 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
84952 +{
84953 + return default_addr_space_legitimize_address(x, oldx, mode, as);
84954 +}
84955 +
84956 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
84957 +{
84958 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
84959 + return true;
84960 +
84961 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
84962 + return true;
84963 +
84964 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
84965 + return true;
84966 +
84967 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
84968 + return true;
84969 +
84970 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
84971 + return true;
84972 +
84973 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
84974 + return true;
84975 +
84976 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
84977 + return true;
84978 +
84979 + return subset == superset;
84980 +}
84981 +
84982 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
84983 +{
84984 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
84985 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
84986 +
84987 + return op;
84988 +}
84989 +
84990 +static void register_checker_address_spaces(void *event_data, void *data)
84991 +{
84992 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
84993 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
84994 + c_register_addr_space("__user", ADDR_SPACE_USER);
84995 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
84996 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
84997 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
84998 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
84999 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
85000 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
85001 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
85002 +
85003 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
85004 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
85005 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
85006 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
85007 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
85008 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
85009 + targetm.addr_space.convert = checker_addr_space_convert;
85010 +}
85011 +
85012 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85013 +{
85014 + const char * const plugin_name = plugin_info->base_name;
85015 + const int argc = plugin_info->argc;
85016 + const struct plugin_argument * const argv = plugin_info->argv;
85017 + int i;
85018 +
85019 + if (!plugin_default_version_check(version, &gcc_version)) {
85020 + error(G_("incompatible gcc/plugin versions"));
85021 + return 1;
85022 + }
85023 +
85024 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
85025 +
85026 + for (i = 0; i < argc; ++i)
85027 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85028 +
85029 + if (TARGET_64BIT == 0)
85030 + return 0;
85031 +
85032 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
85033 +
85034 + return 0;
85035 +}
85036 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
85037 new file mode 100644
85038 index 0000000..414fe5e
85039 --- /dev/null
85040 +++ b/tools/gcc/colorize_plugin.c
85041 @@ -0,0 +1,151 @@
85042 +/*
85043 + * Copyright 2012-2013 by PaX Team <pageexec@freemail.hu>
85044 + * Licensed under the GPL v2
85045 + *
85046 + * Note: the choice of the license means that the compilation process is
85047 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
85048 + * but for the kernel it doesn't matter since it doesn't link against
85049 + * any of the gcc libraries
85050 + *
85051 + * gcc plugin to colorize diagnostic output
85052 + *
85053 + */
85054 +
85055 +#include "gcc-plugin.h"
85056 +#include "config.h"
85057 +#include "system.h"
85058 +#include "coretypes.h"
85059 +#include "tree.h"
85060 +#include "tree-pass.h"
85061 +#include "flags.h"
85062 +#include "intl.h"
85063 +#include "toplev.h"
85064 +#include "plugin.h"
85065 +#include "diagnostic.h"
85066 +#include "plugin-version.h"
85067 +#include "tm.h"
85068 +
85069 +int plugin_is_GPL_compatible;
85070 +
85071 +static struct plugin_info colorize_plugin_info = {
85072 + .version = "201302112000",
85073 + .help = NULL,
85074 +};
85075 +
85076 +#define GREEN "\033[32m\033[2m"
85077 +#define LIGHTGREEN "\033[32m\033[1m"
85078 +#define YELLOW "\033[33m\033[2m"
85079 +#define LIGHTYELLOW "\033[33m\033[1m"
85080 +#define RED "\033[31m\033[2m"
85081 +#define LIGHTRED "\033[31m\033[1m"
85082 +#define BLUE "\033[34m\033[2m"
85083 +#define LIGHTBLUE "\033[34m\033[1m"
85084 +#define BRIGHT "\033[m\033[1m"
85085 +#define NORMAL "\033[m"
85086 +
85087 +static diagnostic_starter_fn old_starter;
85088 +static diagnostic_finalizer_fn old_finalizer;
85089 +
85090 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
85091 +{
85092 + const char *color;
85093 + char *newprefix;
85094 +
85095 + switch (diagnostic->kind) {
85096 + case DK_NOTE:
85097 + color = LIGHTBLUE;
85098 + break;
85099 +
85100 + case DK_PEDWARN:
85101 + case DK_WARNING:
85102 + color = LIGHTYELLOW;
85103 + break;
85104 +
85105 + case DK_ERROR:
85106 + case DK_FATAL:
85107 + case DK_ICE:
85108 + case DK_PERMERROR:
85109 + case DK_SORRY:
85110 + color = LIGHTRED;
85111 + break;
85112 +
85113 + default:
85114 + color = NORMAL;
85115 + }
85116 +
85117 + old_starter(context, diagnostic);
85118 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
85119 + return;
85120 + pp_destroy_prefix(context->printer);
85121 + pp_set_prefix(context->printer, newprefix);
85122 +}
85123 +
85124 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
85125 +{
85126 + old_finalizer(context, diagnostic);
85127 +}
85128 +
85129 +static void colorize_arm(void)
85130 +{
85131 + old_starter = diagnostic_starter(global_dc);
85132 + old_finalizer = diagnostic_finalizer(global_dc);
85133 +
85134 + diagnostic_starter(global_dc) = start_colorize;
85135 + diagnostic_finalizer(global_dc) = finalize_colorize;
85136 +}
85137 +
85138 +static unsigned int execute_colorize_rearm(void)
85139 +{
85140 + if (diagnostic_starter(global_dc) == start_colorize)
85141 + return 0;
85142 +
85143 + colorize_arm();
85144 + return 0;
85145 +}
85146 +
85147 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
85148 + .pass = {
85149 + .type = SIMPLE_IPA_PASS,
85150 + .name = "colorize_rearm",
85151 +#if BUILDING_GCC_VERSION >= 4008
85152 + .optinfo_flags = OPTGROUP_NONE,
85153 +#endif
85154 + .gate = NULL,
85155 + .execute = execute_colorize_rearm,
85156 + .sub = NULL,
85157 + .next = NULL,
85158 + .static_pass_number = 0,
85159 + .tv_id = TV_NONE,
85160 + .properties_required = 0,
85161 + .properties_provided = 0,
85162 + .properties_destroyed = 0,
85163 + .todo_flags_start = 0,
85164 + .todo_flags_finish = 0
85165 + }
85166 +};
85167 +
85168 +static void colorize_start_unit(void *gcc_data, void *user_data)
85169 +{
85170 + colorize_arm();
85171 +}
85172 +
85173 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85174 +{
85175 + const char * const plugin_name = plugin_info->base_name;
85176 + struct register_pass_info colorize_rearm_pass_info = {
85177 + .pass = &pass_ipa_colorize_rearm.pass,
85178 + .reference_pass_name = "*free_lang_data",
85179 + .ref_pass_instance_number = 1,
85180 + .pos_op = PASS_POS_INSERT_AFTER
85181 + };
85182 +
85183 + if (!plugin_default_version_check(version, &gcc_version)) {
85184 + error(G_("incompatible gcc/plugin versions"));
85185 + return 1;
85186 + }
85187 +
85188 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
85189 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
85190 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
85191 + return 0;
85192 +}
85193 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
85194 new file mode 100644
85195 index 0000000..c415c9d
85196 --- /dev/null
85197 +++ b/tools/gcc/constify_plugin.c
85198 @@ -0,0 +1,359 @@
85199 +/*
85200 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
85201 + * Copyright 2011-2013 by PaX Team <pageexec@freemail.hu>
85202 + * Licensed under the GPL v2, or (at your option) v3
85203 + *
85204 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
85205 + *
85206 + * Homepage:
85207 + * http://www.grsecurity.net/~ephox/const_plugin/
85208 + *
85209 + * Usage:
85210 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
85211 + * $ gcc -fplugin=constify_plugin.so test.c -O2
85212 + */
85213 +
85214 +#include "gcc-plugin.h"
85215 +#include "config.h"
85216 +#include "system.h"
85217 +#include "coretypes.h"
85218 +#include "tree.h"
85219 +#include "tree-pass.h"
85220 +#include "flags.h"
85221 +#include "intl.h"
85222 +#include "toplev.h"
85223 +#include "plugin.h"
85224 +#include "diagnostic.h"
85225 +#include "plugin-version.h"
85226 +#include "tm.h"
85227 +#include "function.h"
85228 +#include "basic-block.h"
85229 +#include "gimple.h"
85230 +#include "rtl.h"
85231 +#include "emit-rtl.h"
85232 +#include "tree-flow.h"
85233 +
85234 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
85235 +
85236 +int plugin_is_GPL_compatible;
85237 +
85238 +static struct plugin_info const_plugin_info = {
85239 + .version = "201302112000",
85240 + .help = "no-constify\tturn off constification\n",
85241 +};
85242 +
85243 +static tree get_field_type(tree field)
85244 +{
85245 + return strip_array_types(TREE_TYPE(field));
85246 +}
85247 +
85248 +static bool walk_struct(tree node);
85249 +static void deconstify_tree(tree node);
85250 +
85251 +static void deconstify_type(tree type)
85252 +{
85253 + tree field;
85254 +
85255 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
85256 + tree fieldtype = get_field_type(field);
85257 +
85258 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
85259 + continue;
85260 + if (!TYPE_READONLY(fieldtype))
85261 + continue;
85262 + if (!walk_struct(fieldtype))
85263 + continue;
85264 +
85265 + deconstify_tree(field);
85266 + TREE_READONLY(field) = 0;
85267 + }
85268 + TYPE_READONLY(type) = 0;
85269 + C_TYPE_FIELDS_READONLY(type) = 0;
85270 +}
85271 +
85272 +static void deconstify_tree(tree node)
85273 +{
85274 + tree old_type, new_type, field;
85275 +
85276 +// TREE_READONLY(node) = 0;
85277 + old_type = TREE_TYPE(node);
85278 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
85279 + node = old_type;
85280 + old_type = TREE_TYPE(old_type);
85281 + }
85282 +
85283 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
85284 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
85285 +
85286 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
85287 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
85288 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
85289 + DECL_FIELD_CONTEXT(field) = new_type;
85290 +
85291 + deconstify_type(new_type);
85292 +
85293 + TREE_TYPE(node) = new_type;
85294 +}
85295 +
85296 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
85297 +{
85298 + tree type;
85299 +
85300 + *no_add_attrs = true;
85301 + if (TREE_CODE(*node) == FUNCTION_DECL) {
85302 + error("%qE attribute does not apply to functions", name);
85303 + return NULL_TREE;
85304 + }
85305 +
85306 + if (TREE_CODE(*node) == VAR_DECL) {
85307 + error("%qE attribute does not apply to variables", name);
85308 + return NULL_TREE;
85309 + }
85310 +
85311 + if (TYPE_P(*node)) {
85312 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
85313 + *no_add_attrs = false;
85314 + else
85315 + error("%qE attribute applies to struct and union types only", name);
85316 + return NULL_TREE;
85317 + }
85318 +
85319 + type = TREE_TYPE(*node);
85320 +
85321 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
85322 + error("%qE attribute applies to struct and union types only", name);
85323 + return NULL_TREE;
85324 + }
85325 +
85326 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
85327 + error("%qE attribute is already applied to the type", name);
85328 + return NULL_TREE;
85329 + }
85330 +
85331 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
85332 + error("%qE attribute used on type that is not constified", name);
85333 + return NULL_TREE;
85334 + }
85335 +
85336 + if (TREE_CODE(*node) == TYPE_DECL) {
85337 + deconstify_tree(*node);
85338 + return NULL_TREE;
85339 + }
85340 +
85341 + return NULL_TREE;
85342 +}
85343 +
85344 +static void constify_type(tree type)
85345 +{
85346 + TYPE_READONLY(type) = 1;
85347 + C_TYPE_FIELDS_READONLY(type) = 1;
85348 +}
85349 +
85350 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
85351 +{
85352 + *no_add_attrs = true;
85353 + if (!TYPE_P(*node)) {
85354 + error("%qE attribute applies to types only", name);
85355 + return NULL_TREE;
85356 + }
85357 +
85358 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
85359 + error("%qE attribute applies to struct and union types only", name);
85360 + return NULL_TREE;
85361 + }
85362 +
85363 + *no_add_attrs = false;
85364 + constify_type(*node);
85365 + return NULL_TREE;
85366 +}
85367 +
85368 +static struct attribute_spec no_const_attr = {
85369 + .name = "no_const",
85370 + .min_length = 0,
85371 + .max_length = 0,
85372 + .decl_required = false,
85373 + .type_required = false,
85374 + .function_type_required = false,
85375 + .handler = handle_no_const_attribute,
85376 +#if BUILDING_GCC_VERSION >= 4007
85377 + .affects_type_identity = true
85378 +#endif
85379 +};
85380 +
85381 +static struct attribute_spec do_const_attr = {
85382 + .name = "do_const",
85383 + .min_length = 0,
85384 + .max_length = 0,
85385 + .decl_required = false,
85386 + .type_required = false,
85387 + .function_type_required = false,
85388 + .handler = handle_do_const_attribute,
85389 +#if BUILDING_GCC_VERSION >= 4007
85390 + .affects_type_identity = true
85391 +#endif
85392 +};
85393 +
85394 +static void register_attributes(void *event_data, void *data)
85395 +{
85396 + register_attribute(&no_const_attr);
85397 + register_attribute(&do_const_attr);
85398 +}
85399 +
85400 +static bool is_fptr(tree field)
85401 +{
85402 + tree ptr = get_field_type(field);
85403 +
85404 + if (TREE_CODE(ptr) != POINTER_TYPE)
85405 + return false;
85406 +
85407 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
85408 +}
85409 +
85410 +static bool walk_struct(tree node)
85411 +{
85412 + tree field;
85413 +
85414 + if (TYPE_FIELDS(node) == NULL_TREE)
85415 + return false;
85416 +
85417 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node)))
85418 + return true;
85419 +
85420 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
85421 + gcc_assert(!TYPE_READONLY(node));
85422 + deconstify_type(node);
85423 + return false;
85424 + }
85425 +
85426 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
85427 + tree type = get_field_type(field);
85428 + enum tree_code code = TREE_CODE(type);
85429 +
85430 + if (node == type)
85431 + return false;
85432 + if (code == RECORD_TYPE || code == UNION_TYPE) {
85433 + if (!(walk_struct(type)))
85434 + return false;
85435 + } else if (!is_fptr(field) && !TREE_READONLY(field))
85436 + return false;
85437 + }
85438 + return true;
85439 +}
85440 +
85441 +static void finish_type(void *event_data, void *data)
85442 +{
85443 + tree type = (tree)event_data;
85444 +
85445 + if (type == NULL_TREE || type == error_mark_node)
85446 + return;
85447 +
85448 + if (TYPE_READONLY(type))
85449 + return;
85450 +
85451 + if (walk_struct(type))
85452 + constify_type(type);
85453 + else
85454 + deconstify_type(type);
85455 +}
85456 +
85457 +static unsigned int check_local_variables(void)
85458 +{
85459 + unsigned int ret = 0;
85460 + tree var;
85461 +
85462 +#if BUILDING_GCC_VERSION == 4005
85463 + tree vars;
85464 +#else
85465 + unsigned int i;
85466 +#endif
85467 +
85468 +#if BUILDING_GCC_VERSION == 4005
85469 + for (vars = cfun->local_decls; vars; vars = TREE_CHAIN(vars)) {
85470 + var = TREE_VALUE(vars);
85471 +#else
85472 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
85473 +#endif
85474 + tree type = TREE_TYPE(var);
85475 +
85476 + gcc_assert(DECL_P(var));
85477 + if (is_global_var(var))
85478 + continue;
85479 +
85480 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
85481 + continue;
85482 +
85483 + if (!TYPE_READONLY(type))
85484 + continue;
85485 +
85486 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
85487 +// continue;
85488 +
85489 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
85490 + continue;
85491 +
85492 + if (walk_struct(type)) {
85493 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
85494 + ret = 1;
85495 + }
85496 + }
85497 + return ret;
85498 +}
85499 +
85500 +struct gimple_opt_pass pass_local_variable = {
85501 + {
85502 + .type = GIMPLE_PASS,
85503 + .name = "check_local_variables",
85504 +#if BUILDING_GCC_VERSION >= 4008
85505 + .optinfo_flags = OPTGROUP_NONE,
85506 +#endif
85507 + .gate = NULL,
85508 + .execute = check_local_variables,
85509 + .sub = NULL,
85510 + .next = NULL,
85511 + .static_pass_number = 0,
85512 + .tv_id = TV_NONE,
85513 + .properties_required = 0,
85514 + .properties_provided = 0,
85515 + .properties_destroyed = 0,
85516 + .todo_flags_start = 0,
85517 + .todo_flags_finish = 0
85518 + }
85519 +};
85520 +
85521 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85522 +{
85523 + const char * const plugin_name = plugin_info->base_name;
85524 + const int argc = plugin_info->argc;
85525 + const struct plugin_argument * const argv = plugin_info->argv;
85526 + int i;
85527 + bool constify = true;
85528 +
85529 + struct register_pass_info local_variable_pass_info = {
85530 + .pass = &pass_local_variable.pass,
85531 + .reference_pass_name = "ssa",
85532 + .ref_pass_instance_number = 1,
85533 + .pos_op = PASS_POS_INSERT_BEFORE
85534 + };
85535 +
85536 + if (!plugin_default_version_check(version, &gcc_version)) {
85537 + error(G_("incompatible gcc/plugin versions"));
85538 + return 1;
85539 + }
85540 +
85541 + for (i = 0; i < argc; ++i) {
85542 + if (!(strcmp(argv[i].key, "no-constify"))) {
85543 + constify = false;
85544 + continue;
85545 + }
85546 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85547 + }
85548 +
85549 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
85550 + if (constify) {
85551 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
85552 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
85553 + }
85554 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
85555 +
85556 + return 0;
85557 +}
85558 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
85559 new file mode 100644
85560 index 0000000..e518932
85561 --- /dev/null
85562 +++ b/tools/gcc/generate_size_overflow_hash.sh
85563 @@ -0,0 +1,94 @@
85564 +#!/bin/bash
85565 +
85566 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
85567 +
85568 +header1="size_overflow_hash.h"
85569 +database="size_overflow_hash.data"
85570 +n=65536
85571 +
85572 +usage() {
85573 +cat <<EOF
85574 +usage: $0 options
85575 +OPTIONS:
85576 + -h|--help help
85577 + -o header file
85578 + -d database file
85579 + -n hash array size
85580 +EOF
85581 + return 0
85582 +}
85583 +
85584 +while true
85585 +do
85586 + case "$1" in
85587 + -h|--help) usage && exit 0;;
85588 + -n) n=$2; shift 2;;
85589 + -o) header1="$2"; shift 2;;
85590 + -d) database="$2"; shift 2;;
85591 + --) shift 1; break ;;
85592 + *) break ;;
85593 + esac
85594 +done
85595 +
85596 +create_defines() {
85597 + for i in `seq 0 31`
85598 + do
85599 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
85600 + done
85601 + echo >> "$header1"
85602 +}
85603 +
85604 +create_structs() {
85605 + rm -f "$header1"
85606 +
85607 + create_defines
85608 +
85609 + cat "$database" | while read data
85610 + do
85611 + data_array=($data)
85612 + struct_hash_name="${data_array[0]}"
85613 + funcn="${data_array[1]}"
85614 + params="${data_array[2]}"
85615 + next="${data_array[4]}"
85616 +
85617 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
85618 +
85619 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
85620 + echo -en "\t.param\t= " >> "$header1"
85621 + line=
85622 + for param_num in ${params//-/ };
85623 + do
85624 + line="${line}PARAM"$param_num"|"
85625 + done
85626 +
85627 + echo -e "${line%?},\n};\n" >> "$header1"
85628 + done
85629 +}
85630 +
85631 +create_headers() {
85632 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
85633 +}
85634 +
85635 +create_array_elements() {
85636 + index=0
85637 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
85638 + do
85639 + data_array=($data)
85640 + i="${data_array[3]}"
85641 + hash="${data_array[0]}"
85642 + while [[ $index -lt $i ]]
85643 + do
85644 + echo -e "\t["$index"]\t= NULL," >> "$header1"
85645 + index=$(($index + 1))
85646 + done
85647 + index=$(($index + 1))
85648 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
85649 + done
85650 + echo '};' >> $header1
85651 +}
85652 +
85653 +create_structs
85654 +create_headers
85655 +create_array_elements
85656 +
85657 +exit 0
85658 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
85659 new file mode 100644
85660 index 0000000..568b360
85661 --- /dev/null
85662 +++ b/tools/gcc/kallocstat_plugin.c
85663 @@ -0,0 +1,170 @@
85664 +/*
85665 + * Copyright 2011-2013 by the PaX Team <pageexec@freemail.hu>
85666 + * Licensed under the GPL v2
85667 + *
85668 + * Note: the choice of the license means that the compilation process is
85669 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
85670 + * but for the kernel it doesn't matter since it doesn't link against
85671 + * any of the gcc libraries
85672 + *
85673 + * gcc plugin to find the distribution of k*alloc sizes
85674 + *
85675 + * TODO:
85676 + *
85677 + * BUGS:
85678 + * - none known
85679 + */
85680 +#include "gcc-plugin.h"
85681 +#include "config.h"
85682 +#include "system.h"
85683 +#include "coretypes.h"
85684 +#include "tree.h"
85685 +#include "tree-pass.h"
85686 +#include "flags.h"
85687 +#include "intl.h"
85688 +#include "toplev.h"
85689 +#include "plugin.h"
85690 +//#include "expr.h" where are you...
85691 +#include "diagnostic.h"
85692 +#include "plugin-version.h"
85693 +#include "tm.h"
85694 +#include "function.h"
85695 +#include "basic-block.h"
85696 +#include "gimple.h"
85697 +#include "rtl.h"
85698 +#include "emit-rtl.h"
85699 +
85700 +extern void print_gimple_stmt(FILE *, gimple, int, int);
85701 +
85702 +int plugin_is_GPL_compatible;
85703 +
85704 +static const char * const kalloc_functions[] = {
85705 + "__kmalloc",
85706 + "kmalloc",
85707 + "kmalloc_large",
85708 + "kmalloc_node",
85709 + "kmalloc_order",
85710 + "kmalloc_order_trace",
85711 + "kmalloc_slab",
85712 + "kzalloc",
85713 + "kzalloc_node",
85714 +};
85715 +
85716 +static struct plugin_info kallocstat_plugin_info = {
85717 + .version = "201302112000",
85718 +};
85719 +
85720 +static unsigned int execute_kallocstat(void);
85721 +
85722 +static struct gimple_opt_pass kallocstat_pass = {
85723 + .pass = {
85724 + .type = GIMPLE_PASS,
85725 + .name = "kallocstat",
85726 +#if BUILDING_GCC_VERSION >= 4008
85727 + .optinfo_flags = OPTGROUP_NONE,
85728 +#endif
85729 + .gate = NULL,
85730 + .execute = execute_kallocstat,
85731 + .sub = NULL,
85732 + .next = NULL,
85733 + .static_pass_number = 0,
85734 + .tv_id = TV_NONE,
85735 + .properties_required = 0,
85736 + .properties_provided = 0,
85737 + .properties_destroyed = 0,
85738 + .todo_flags_start = 0,
85739 + .todo_flags_finish = 0
85740 + }
85741 +};
85742 +
85743 +static bool is_kalloc(const char *fnname)
85744 +{
85745 + size_t i;
85746 +
85747 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
85748 + if (!strcmp(fnname, kalloc_functions[i]))
85749 + return true;
85750 + return false;
85751 +}
85752 +
85753 +static unsigned int execute_kallocstat(void)
85754 +{
85755 + basic_block bb;
85756 +
85757 + // 1. loop through BBs and GIMPLE statements
85758 + FOR_EACH_BB(bb) {
85759 + gimple_stmt_iterator gsi;
85760 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
85761 + // gimple match:
85762 + tree fndecl, size;
85763 + gimple call_stmt;
85764 + const char *fnname;
85765 +
85766 + // is it a call
85767 + call_stmt = gsi_stmt(gsi);
85768 + if (!is_gimple_call(call_stmt))
85769 + continue;
85770 + fndecl = gimple_call_fndecl(call_stmt);
85771 + if (fndecl == NULL_TREE)
85772 + continue;
85773 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
85774 + continue;
85775 +
85776 + // is it a call to k*alloc
85777 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
85778 + if (!is_kalloc(fnname))
85779 + continue;
85780 +
85781 + // is the size arg the result of a simple const assignment
85782 + size = gimple_call_arg(call_stmt, 0);
85783 + while (true) {
85784 + gimple def_stmt;
85785 + expanded_location xloc;
85786 + size_t size_val;
85787 +
85788 + if (TREE_CODE(size) != SSA_NAME)
85789 + break;
85790 + def_stmt = SSA_NAME_DEF_STMT(size);
85791 + if (!def_stmt || !is_gimple_assign(def_stmt))
85792 + break;
85793 + if (gimple_num_ops(def_stmt) != 2)
85794 + break;
85795 + size = gimple_assign_rhs1(def_stmt);
85796 + if (!TREE_CONSTANT(size))
85797 + continue;
85798 + xloc = expand_location(gimple_location(def_stmt));
85799 + if (!xloc.file)
85800 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
85801 + size_val = TREE_INT_CST_LOW(size);
85802 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
85803 + break;
85804 + }
85805 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
85806 +//debug_tree(gimple_call_fn(call_stmt));
85807 +//print_node(stderr, "pax", fndecl, 4);
85808 + }
85809 + }
85810 +
85811 + return 0;
85812 +}
85813 +
85814 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85815 +{
85816 + const char * const plugin_name = plugin_info->base_name;
85817 + struct register_pass_info kallocstat_pass_info = {
85818 + .pass = &kallocstat_pass.pass,
85819 + .reference_pass_name = "ssa",
85820 + .ref_pass_instance_number = 1,
85821 + .pos_op = PASS_POS_INSERT_AFTER
85822 + };
85823 +
85824 + if (!plugin_default_version_check(version, &gcc_version)) {
85825 + error(G_("incompatible gcc/plugin versions"));
85826 + return 1;
85827 + }
85828 +
85829 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
85830 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
85831 +
85832 + return 0;
85833 +}
85834 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
85835 new file mode 100644
85836 index 0000000..0408e06
85837 --- /dev/null
85838 +++ b/tools/gcc/kernexec_plugin.c
85839 @@ -0,0 +1,465 @@
85840 +/*
85841 + * Copyright 2011-2013 by the PaX Team <pageexec@freemail.hu>
85842 + * Licensed under the GPL v2
85843 + *
85844 + * Note: the choice of the license means that the compilation process is
85845 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
85846 + * but for the kernel it doesn't matter since it doesn't link against
85847 + * any of the gcc libraries
85848 + *
85849 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
85850 + *
85851 + * TODO:
85852 + *
85853 + * BUGS:
85854 + * - none known
85855 + */
85856 +#include "gcc-plugin.h"
85857 +#include "config.h"
85858 +#include "system.h"
85859 +#include "coretypes.h"
85860 +#include "tree.h"
85861 +#include "tree-pass.h"
85862 +#include "flags.h"
85863 +#include "intl.h"
85864 +#include "toplev.h"
85865 +#include "plugin.h"
85866 +//#include "expr.h" where are you...
85867 +#include "diagnostic.h"
85868 +#include "plugin-version.h"
85869 +#include "tm.h"
85870 +#include "function.h"
85871 +#include "basic-block.h"
85872 +#include "gimple.h"
85873 +#include "rtl.h"
85874 +#include "emit-rtl.h"
85875 +#include "tree-flow.h"
85876 +
85877 +extern void print_gimple_stmt(FILE *, gimple, int, int);
85878 +extern rtx emit_move_insn(rtx x, rtx y);
85879 +
85880 +#if BUILDING_GCC_VERSION <= 4006
85881 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
85882 +#endif
85883 +
85884 +#if BUILDING_GCC_VERSION >= 4008
85885 +#define TODO_dump_func 0
85886 +#endif
85887 +
85888 +int plugin_is_GPL_compatible;
85889 +
85890 +static struct plugin_info kernexec_plugin_info = {
85891 + .version = "201302112000",
85892 + .help = "method=[bts|or]\tinstrumentation method\n"
85893 +};
85894 +
85895 +static unsigned int execute_kernexec_reload(void);
85896 +static unsigned int execute_kernexec_fptr(void);
85897 +static unsigned int execute_kernexec_retaddr(void);
85898 +static bool kernexec_cmodel_check(void);
85899 +
85900 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
85901 +static void (*kernexec_instrument_retaddr)(rtx);
85902 +
85903 +static struct gimple_opt_pass kernexec_reload_pass = {
85904 + .pass = {
85905 + .type = GIMPLE_PASS,
85906 + .name = "kernexec_reload",
85907 +#if BUILDING_GCC_VERSION >= 4008
85908 + .optinfo_flags = OPTGROUP_NONE,
85909 +#endif
85910 + .gate = kernexec_cmodel_check,
85911 + .execute = execute_kernexec_reload,
85912 + .sub = NULL,
85913 + .next = NULL,
85914 + .static_pass_number = 0,
85915 + .tv_id = TV_NONE,
85916 + .properties_required = 0,
85917 + .properties_provided = 0,
85918 + .properties_destroyed = 0,
85919 + .todo_flags_start = 0,
85920 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
85921 + }
85922 +};
85923 +
85924 +static struct gimple_opt_pass kernexec_fptr_pass = {
85925 + .pass = {
85926 + .type = GIMPLE_PASS,
85927 + .name = "kernexec_fptr",
85928 +#if BUILDING_GCC_VERSION >= 4008
85929 + .optinfo_flags = OPTGROUP_NONE,
85930 +#endif
85931 + .gate = kernexec_cmodel_check,
85932 + .execute = execute_kernexec_fptr,
85933 + .sub = NULL,
85934 + .next = NULL,
85935 + .static_pass_number = 0,
85936 + .tv_id = TV_NONE,
85937 + .properties_required = 0,
85938 + .properties_provided = 0,
85939 + .properties_destroyed = 0,
85940 + .todo_flags_start = 0,
85941 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
85942 + }
85943 +};
85944 +
85945 +static struct rtl_opt_pass kernexec_retaddr_pass = {
85946 + .pass = {
85947 + .type = RTL_PASS,
85948 + .name = "kernexec_retaddr",
85949 +#if BUILDING_GCC_VERSION >= 4008
85950 + .optinfo_flags = OPTGROUP_NONE,
85951 +#endif
85952 + .gate = kernexec_cmodel_check,
85953 + .execute = execute_kernexec_retaddr,
85954 + .sub = NULL,
85955 + .next = NULL,
85956 + .static_pass_number = 0,
85957 + .tv_id = TV_NONE,
85958 + .properties_required = 0,
85959 + .properties_provided = 0,
85960 + .properties_destroyed = 0,
85961 + .todo_flags_start = 0,
85962 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
85963 + }
85964 +};
85965 +
85966 +static bool kernexec_cmodel_check(void)
85967 +{
85968 + tree section;
85969 +
85970 + if (ix86_cmodel != CM_KERNEL)
85971 + return false;
85972 +
85973 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
85974 + if (!section || !TREE_VALUE(section))
85975 + return true;
85976 +
85977 + section = TREE_VALUE(TREE_VALUE(section));
85978 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
85979 + return true;
85980 +
85981 + return false;
85982 +}
85983 +
85984 +/*
85985 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
85986 + */
85987 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
85988 +{
85989 + gimple asm_movabs_stmt;
85990 +
85991 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
85992 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
85993 + gimple_asm_set_volatile(asm_movabs_stmt, true);
85994 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
85995 + update_stmt(asm_movabs_stmt);
85996 +}
85997 +
85998 +/*
85999 + * find all asm() stmts that clobber r10 and add a reload of r10
86000 + */
86001 +static unsigned int execute_kernexec_reload(void)
86002 +{
86003 + basic_block bb;
86004 +
86005 + // 1. loop through BBs and GIMPLE statements
86006 + FOR_EACH_BB(bb) {
86007 + gimple_stmt_iterator gsi;
86008 +
86009 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
86010 + // gimple match: __asm__ ("" : : : "r10");
86011 + gimple asm_stmt;
86012 + size_t nclobbers;
86013 +
86014 + // is it an asm ...
86015 + asm_stmt = gsi_stmt(gsi);
86016 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
86017 + continue;
86018 +
86019 + // ... clobbering r10
86020 + nclobbers = gimple_asm_nclobbers(asm_stmt);
86021 + while (nclobbers--) {
86022 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
86023 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
86024 + continue;
86025 + kernexec_reload_fptr_mask(&gsi);
86026 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
86027 + break;
86028 + }
86029 + }
86030 + }
86031 +
86032 + return 0;
86033 +}
86034 +
86035 +/*
86036 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
86037 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
86038 + */
86039 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
86040 +{
86041 + gimple assign_intptr, assign_new_fptr, call_stmt;
86042 + tree intptr, old_fptr, new_fptr, kernexec_mask;
86043 +
86044 + call_stmt = gsi_stmt(*gsi);
86045 + old_fptr = gimple_call_fn(call_stmt);
86046 +
86047 + // create temporary unsigned long variable used for bitops and cast fptr to it
86048 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
86049 +#if BUILDING_GCC_VERSION <= 4007
86050 + add_referenced_var(intptr);
86051 + mark_sym_for_renaming(intptr);
86052 +#endif
86053 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
86054 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
86055 + update_stmt(assign_intptr);
86056 +
86057 + // apply logical or to temporary unsigned long and bitmask
86058 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
86059 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
86060 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
86061 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
86062 + update_stmt(assign_intptr);
86063 +
86064 + // cast temporary unsigned long back to a temporary fptr variable
86065 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
86066 +#if BUILDING_GCC_VERSION <= 4007
86067 + add_referenced_var(new_fptr);
86068 + mark_sym_for_renaming(new_fptr);
86069 +#endif
86070 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
86071 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
86072 + update_stmt(assign_new_fptr);
86073 +
86074 + // replace call stmt fn with the new fptr
86075 + gimple_call_set_fn(call_stmt, new_fptr);
86076 + update_stmt(call_stmt);
86077 +}
86078 +
86079 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
86080 +{
86081 + gimple asm_or_stmt, call_stmt;
86082 + tree old_fptr, new_fptr, input, output;
86083 +#if BUILDING_GCC_VERSION <= 4007
86084 + VEC(tree, gc) *inputs = NULL;
86085 + VEC(tree, gc) *outputs = NULL;
86086 +#else
86087 + vec<tree, va_gc> *inputs = NULL;
86088 + vec<tree, va_gc> *outputs = NULL;
86089 +#endif
86090 +
86091 + call_stmt = gsi_stmt(*gsi);
86092 + old_fptr = gimple_call_fn(call_stmt);
86093 +
86094 + // create temporary fptr variable
86095 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
86096 +#if BUILDING_GCC_VERSION <= 4007
86097 + add_referenced_var(new_fptr);
86098 + mark_sym_for_renaming(new_fptr);
86099 +#endif
86100 +
86101 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
86102 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
86103 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
86104 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
86105 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
86106 +#if BUILDING_GCC_VERSION <= 4007
86107 + VEC_safe_push(tree, gc, inputs, input);
86108 + VEC_safe_push(tree, gc, outputs, output);
86109 +#else
86110 + vec_safe_push(inputs, input);
86111 + vec_safe_push(outputs, output);
86112 +#endif
86113 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
86114 + gimple_asm_set_volatile(asm_or_stmt, true);
86115 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
86116 + update_stmt(asm_or_stmt);
86117 +
86118 + // replace call stmt fn with the new fptr
86119 + gimple_call_set_fn(call_stmt, new_fptr);
86120 + update_stmt(call_stmt);
86121 +}
86122 +
86123 +/*
86124 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
86125 + */
86126 +static unsigned int execute_kernexec_fptr(void)
86127 +{
86128 + basic_block bb;
86129 +
86130 + // 1. loop through BBs and GIMPLE statements
86131 + FOR_EACH_BB(bb) {
86132 + gimple_stmt_iterator gsi;
86133 +
86134 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
86135 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
86136 + tree fn;
86137 + gimple call_stmt;
86138 +
86139 + // is it a call ...
86140 + call_stmt = gsi_stmt(gsi);
86141 + if (!is_gimple_call(call_stmt))
86142 + continue;
86143 + fn = gimple_call_fn(call_stmt);
86144 + if (TREE_CODE(fn) == ADDR_EXPR)
86145 + continue;
86146 + if (TREE_CODE(fn) != SSA_NAME)
86147 + gcc_unreachable();
86148 +
86149 + // ... through a function pointer
86150 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
86151 + fn = SSA_NAME_VAR(fn);
86152 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
86153 + debug_tree(fn);
86154 + gcc_unreachable();
86155 + }
86156 + }
86157 + fn = TREE_TYPE(fn);
86158 + if (TREE_CODE(fn) != POINTER_TYPE)
86159 + continue;
86160 + fn = TREE_TYPE(fn);
86161 + if (TREE_CODE(fn) != FUNCTION_TYPE)
86162 + continue;
86163 +
86164 + kernexec_instrument_fptr(&gsi);
86165 +
86166 +//debug_tree(gimple_call_fn(call_stmt));
86167 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
86168 + }
86169 + }
86170 +
86171 + return 0;
86172 +}
86173 +
86174 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
86175 +static void kernexec_instrument_retaddr_bts(rtx insn)
86176 +{
86177 + rtx btsq;
86178 + rtvec argvec, constraintvec, labelvec;
86179 + int line;
86180 +
86181 + // create asm volatile("btsq $63,(%%rsp)":::)
86182 + argvec = rtvec_alloc(0);
86183 + constraintvec = rtvec_alloc(0);
86184 + labelvec = rtvec_alloc(0);
86185 + line = expand_location(RTL_LOCATION(insn)).line;
86186 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
86187 + MEM_VOLATILE_P(btsq) = 1;
86188 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
86189 + emit_insn_before(btsq, insn);
86190 +}
86191 +
86192 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
86193 +static void kernexec_instrument_retaddr_or(rtx insn)
86194 +{
86195 + rtx orq;
86196 + rtvec argvec, constraintvec, labelvec;
86197 + int line;
86198 +
86199 + // create asm volatile("orq %%r10,(%%rsp)":::)
86200 + argvec = rtvec_alloc(0);
86201 + constraintvec = rtvec_alloc(0);
86202 + labelvec = rtvec_alloc(0);
86203 + line = expand_location(RTL_LOCATION(insn)).line;
86204 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
86205 + MEM_VOLATILE_P(orq) = 1;
86206 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
86207 + emit_insn_before(orq, insn);
86208 +}
86209 +
86210 +/*
86211 + * find all asm level function returns and forcibly set the highest bit of the return address
86212 + */
86213 +static unsigned int execute_kernexec_retaddr(void)
86214 +{
86215 + rtx insn;
86216 +
86217 + // 1. find function returns
86218 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
86219 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
86220 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
86221 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
86222 + rtx body;
86223 +
86224 + // is it a retn
86225 + if (!JUMP_P(insn))
86226 + continue;
86227 + body = PATTERN(insn);
86228 + if (GET_CODE(body) == PARALLEL)
86229 + body = XVECEXP(body, 0, 0);
86230 + if (!ANY_RETURN_P(body))
86231 + continue;
86232 + kernexec_instrument_retaddr(insn);
86233 + }
86234 +
86235 +// print_simple_rtl(stderr, get_insns());
86236 +// print_rtl(stderr, get_insns());
86237 +
86238 + return 0;
86239 +}
86240 +
86241 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
86242 +{
86243 + const char * const plugin_name = plugin_info->base_name;
86244 + const int argc = plugin_info->argc;
86245 + const struct plugin_argument * const argv = plugin_info->argv;
86246 + int i;
86247 + struct register_pass_info kernexec_reload_pass_info = {
86248 + .pass = &kernexec_reload_pass.pass,
86249 + .reference_pass_name = "ssa",
86250 + .ref_pass_instance_number = 1,
86251 + .pos_op = PASS_POS_INSERT_AFTER
86252 + };
86253 + struct register_pass_info kernexec_fptr_pass_info = {
86254 + .pass = &kernexec_fptr_pass.pass,
86255 + .reference_pass_name = "ssa",
86256 + .ref_pass_instance_number = 1,
86257 + .pos_op = PASS_POS_INSERT_AFTER
86258 + };
86259 + struct register_pass_info kernexec_retaddr_pass_info = {
86260 + .pass = &kernexec_retaddr_pass.pass,
86261 + .reference_pass_name = "pro_and_epilogue",
86262 + .ref_pass_instance_number = 1,
86263 + .pos_op = PASS_POS_INSERT_AFTER
86264 + };
86265 +
86266 + if (!plugin_default_version_check(version, &gcc_version)) {
86267 + error(G_("incompatible gcc/plugin versions"));
86268 + return 1;
86269 + }
86270 +
86271 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
86272 +
86273 + if (TARGET_64BIT == 0)
86274 + return 0;
86275 +
86276 + for (i = 0; i < argc; ++i) {
86277 + if (!strcmp(argv[i].key, "method")) {
86278 + if (!argv[i].value) {
86279 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
86280 + continue;
86281 + }
86282 + if (!strcmp(argv[i].value, "bts")) {
86283 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
86284 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
86285 + } else if (!strcmp(argv[i].value, "or")) {
86286 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
86287 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
86288 + fix_register("r10", 1, 1);
86289 + } else
86290 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
86291 + continue;
86292 + }
86293 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
86294 + }
86295 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
86296 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
86297 +
86298 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
86299 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
86300 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
86301 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
86302 +
86303 + return 0;
86304 +}
86305 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
86306 new file mode 100644
86307 index 0000000..1276616
86308 --- /dev/null
86309 +++ b/tools/gcc/latent_entropy_plugin.c
86310 @@ -0,0 +1,321 @@
86311 +/*
86312 + * Copyright 2012-2013 by the PaX Team <pageexec@freemail.hu>
86313 + * Licensed under the GPL v2
86314 + *
86315 + * Note: the choice of the license means that the compilation process is
86316 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
86317 + * but for the kernel it doesn't matter since it doesn't link against
86318 + * any of the gcc libraries
86319 + *
86320 + * gcc plugin to help generate a little bit of entropy from program state,
86321 + * used during boot in the kernel
86322 + *
86323 + * TODO:
86324 + * - add ipa pass to identify not explicitly marked candidate functions
86325 + * - mix in more program state (function arguments/return values, loop variables, etc)
86326 + * - more instrumentation control via attribute parameters
86327 + *
86328 + * BUGS:
86329 + * - LTO needs -flto-partition=none for now
86330 + */
86331 +#include "gcc-plugin.h"
86332 +#include "config.h"
86333 +#include "system.h"
86334 +#include "coretypes.h"
86335 +#include "tree.h"
86336 +#include "tree-pass.h"
86337 +#include "flags.h"
86338 +#include "intl.h"
86339 +#include "toplev.h"
86340 +#include "plugin.h"
86341 +//#include "expr.h" where are you...
86342 +#include "diagnostic.h"
86343 +#include "plugin-version.h"
86344 +#include "tm.h"
86345 +#include "function.h"
86346 +#include "basic-block.h"
86347 +#include "gimple.h"
86348 +#include "rtl.h"
86349 +#include "emit-rtl.h"
86350 +#include "tree-flow.h"
86351 +
86352 +#if BUILDING_GCC_VERSION >= 4008
86353 +#define TODO_dump_func 0
86354 +#endif
86355 +
86356 +int plugin_is_GPL_compatible;
86357 +
86358 +static tree latent_entropy_decl;
86359 +
86360 +static struct plugin_info latent_entropy_plugin_info = {
86361 + .version = "201302112000",
86362 + .help = NULL
86363 +};
86364 +
86365 +static unsigned int execute_latent_entropy(void);
86366 +static bool gate_latent_entropy(void);
86367 +
86368 +static struct gimple_opt_pass latent_entropy_pass = {
86369 + .pass = {
86370 + .type = GIMPLE_PASS,
86371 + .name = "latent_entropy",
86372 +#if BUILDING_GCC_VERSION >= 4008
86373 + .optinfo_flags = OPTGROUP_NONE,
86374 +#endif
86375 + .gate = gate_latent_entropy,
86376 + .execute = execute_latent_entropy,
86377 + .sub = NULL,
86378 + .next = NULL,
86379 + .static_pass_number = 0,
86380 + .tv_id = TV_NONE,
86381 + .properties_required = PROP_gimple_leh | PROP_cfg,
86382 + .properties_provided = 0,
86383 + .properties_destroyed = 0,
86384 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
86385 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
86386 + }
86387 +};
86388 +
86389 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
86390 +{
86391 + if (TREE_CODE(*node) != FUNCTION_DECL) {
86392 + *no_add_attrs = true;
86393 + error("%qE attribute only applies to functions", name);
86394 + }
86395 + return NULL_TREE;
86396 +}
86397 +
86398 +static struct attribute_spec latent_entropy_attr = {
86399 + .name = "latent_entropy",
86400 + .min_length = 0,
86401 + .max_length = 0,
86402 + .decl_required = true,
86403 + .type_required = false,
86404 + .function_type_required = false,
86405 + .handler = handle_latent_entropy_attribute,
86406 +#if BUILDING_GCC_VERSION >= 4007
86407 + .affects_type_identity = false
86408 +#endif
86409 +};
86410 +
86411 +static void register_attributes(void *event_data, void *data)
86412 +{
86413 + register_attribute(&latent_entropy_attr);
86414 +}
86415 +
86416 +static bool gate_latent_entropy(void)
86417 +{
86418 + tree latent_entropy_attr;
86419 +
86420 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
86421 + return latent_entropy_attr != NULL_TREE;
86422 +}
86423 +
86424 +static unsigned HOST_WIDE_INT seed;
86425 +static unsigned HOST_WIDE_INT get_random_const(void)
86426 +{
86427 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
86428 + return seed;
86429 +}
86430 +
86431 +static enum tree_code get_op(tree *rhs)
86432 +{
86433 + static enum tree_code op;
86434 + unsigned HOST_WIDE_INT random_const;
86435 +
86436 + random_const = get_random_const();
86437 +
86438 + switch (op) {
86439 + case BIT_XOR_EXPR:
86440 + op = PLUS_EXPR;
86441 + break;
86442 +
86443 + case PLUS_EXPR:
86444 + if (rhs) {
86445 + op = LROTATE_EXPR;
86446 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
86447 + break;
86448 + }
86449 +
86450 + case LROTATE_EXPR:
86451 + default:
86452 + op = BIT_XOR_EXPR;
86453 + break;
86454 + }
86455 + if (rhs)
86456 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
86457 + return op;
86458 +}
86459 +
86460 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
86461 +{
86462 + gimple_stmt_iterator gsi;
86463 + gimple assign;
86464 + tree addxorrol, rhs;
86465 + enum tree_code op;
86466 +
86467 + op = get_op(&rhs);
86468 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
86469 + assign = gimple_build_assign(local_entropy, addxorrol);
86470 +#if BUILDING_GCC_VERSION <= 4007
86471 + find_referenced_vars_in(assign);
86472 +#endif
86473 +//debug_bb(bb);
86474 + gsi = gsi_after_labels(bb);
86475 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
86476 + update_stmt(assign);
86477 +}
86478 +
86479 +static void perturb_latent_entropy(basic_block bb, tree rhs)
86480 +{
86481 + gimple_stmt_iterator gsi;
86482 + gimple assign;
86483 + tree addxorrol, temp;
86484 +
86485 + // 1. create temporary copy of latent_entropy
86486 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
86487 +#if BUILDING_GCC_VERSION <= 4007
86488 + add_referenced_var(temp);
86489 + mark_sym_for_renaming(temp);
86490 +#endif
86491 +
86492 + // 2. read...
86493 + assign = gimple_build_assign(temp, latent_entropy_decl);
86494 +#if BUILDING_GCC_VERSION <= 4007
86495 + find_referenced_vars_in(assign);
86496 +#endif
86497 + gsi = gsi_after_labels(bb);
86498 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
86499 + update_stmt(assign);
86500 +
86501 + // 3. ...modify...
86502 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
86503 + assign = gimple_build_assign(temp, addxorrol);
86504 +#if BUILDING_GCC_VERSION <= 4007
86505 + find_referenced_vars_in(assign);
86506 +#endif
86507 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
86508 + update_stmt(assign);
86509 +
86510 + // 4. ...write latent_entropy
86511 + assign = gimple_build_assign(latent_entropy_decl, temp);
86512 +#if BUILDING_GCC_VERSION <= 4007
86513 + find_referenced_vars_in(assign);
86514 +#endif
86515 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
86516 + update_stmt(assign);
86517 +}
86518 +
86519 +static unsigned int execute_latent_entropy(void)
86520 +{
86521 + basic_block bb;
86522 + gimple assign;
86523 + gimple_stmt_iterator gsi;
86524 + tree local_entropy;
86525 +
86526 + if (!latent_entropy_decl) {
86527 + struct varpool_node *node;
86528 +
86529 +#if BUILDING_GCC_VERSION <= 4007
86530 + for (node = varpool_nodes; node; node = node->next) {
86531 + tree var = node->decl;
86532 +#else
86533 + FOR_EACH_VARIABLE(node) {
86534 + tree var = node->symbol.decl;
86535 +#endif
86536 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
86537 + continue;
86538 + latent_entropy_decl = var;
86539 +// debug_tree(var);
86540 + break;
86541 + }
86542 + if (!latent_entropy_decl) {
86543 +// debug_tree(current_function_decl);
86544 + return 0;
86545 + }
86546 + }
86547 +
86548 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
86549 +
86550 + // 1. create local entropy variable
86551 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
86552 +#if BUILDING_GCC_VERSION <= 4007
86553 + add_referenced_var(local_entropy);
86554 + mark_sym_for_renaming(local_entropy);
86555 +#endif
86556 +
86557 + // 2. initialize local entropy variable
86558 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
86559 + if (dom_info_available_p(CDI_DOMINATORS))
86560 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
86561 + gsi = gsi_start_bb(bb);
86562 +
86563 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
86564 +// gimple_set_location(assign, loc);
86565 +#if BUILDING_GCC_VERSION <= 4007
86566 + find_referenced_vars_in(assign);
86567 +#endif
86568 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
86569 + update_stmt(assign);
86570 + bb = bb->next_bb;
86571 +
86572 + // 3. instrument each BB with an operation on the local entropy variable
86573 + while (bb != EXIT_BLOCK_PTR) {
86574 + perturb_local_entropy(bb, local_entropy);
86575 + bb = bb->next_bb;
86576 + };
86577 +
86578 + // 4. mix local entropy into the global entropy variable
86579 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
86580 + return 0;
86581 +}
86582 +
86583 +static void start_unit_callback(void *gcc_data, void *user_data)
86584 +{
86585 +#if BUILDING_GCC_VERSION >= 4007
86586 + seed = get_random_seed(false);
86587 +#else
86588 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
86589 + seed *= seed;
86590 +#endif
86591 +
86592 + if (in_lto_p)
86593 + return;
86594 +
86595 + // extern u64 latent_entropy
86596 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), unsigned_intDI_type_node);
86597 +
86598 + TREE_STATIC(latent_entropy_decl) = 1;
86599 + TREE_PUBLIC(latent_entropy_decl) = 1;
86600 + TREE_USED(latent_entropy_decl) = 1;
86601 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
86602 + DECL_EXTERNAL(latent_entropy_decl) = 1;
86603 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
86604 + DECL_INITIAL(latent_entropy_decl) = NULL;
86605 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
86606 +// varpool_finalize_decl(latent_entropy_decl);
86607 +// varpool_mark_needed_node(latent_entropy_decl);
86608 +}
86609 +
86610 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
86611 +{
86612 + const char * const plugin_name = plugin_info->base_name;
86613 + struct register_pass_info latent_entropy_pass_info = {
86614 + .pass = &latent_entropy_pass.pass,
86615 + .reference_pass_name = "optimized",
86616 + .ref_pass_instance_number = 1,
86617 + .pos_op = PASS_POS_INSERT_BEFORE
86618 + };
86619 +
86620 + if (!plugin_default_version_check(version, &gcc_version)) {
86621 + error(G_("incompatible gcc/plugin versions"));
86622 + return 1;
86623 + }
86624 +
86625 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
86626 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
86627 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
86628 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
86629 +
86630 + return 0;
86631 +}
86632 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
86633 new file mode 100644
86634 index 0000000..5921fd7
86635 --- /dev/null
86636 +++ b/tools/gcc/size_overflow_hash.data
86637 @@ -0,0 +1,3713 @@
86638 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
86639 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
86640 +batadv_orig_node_del_if_4 batadv_orig_node_del_if 2 4 NULL
86641 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
86642 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
86643 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
86644 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
86645 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
86646 +diva_os_malloc_16406 diva_os_malloc 2 16406 NULL
86647 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
86648 +xfs_dir2_leaf_getdents_23841 xfs_dir2_leaf_getdents 3 23841 NULL
86649 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
86650 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
86651 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
86652 +create_log_8225 create_log 2 8225 NULL
86653 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
86654 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
86655 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
86656 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
86657 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
86658 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
86659 +padzero_55 padzero 1 55 &sel_read_policyvers_55
86660 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
86661 +alloc_wr_24635 alloc_wr 1-2 24635 NULL
86662 +read_file_blob_57406 read_file_blob 3 57406 NULL
86663 +add_rx_skb_8257 add_rx_skb 3 8257 NULL
86664 +enclosure_register_57412 enclosure_register 3 57412 NULL
86665 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
86666 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
86667 +gre_manip_pkt_57416 gre_manip_pkt 4 57416 NULL
86668 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
86669 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
86670 +DepcaSignature_80 DepcaSignature 2 80 NULL nohasharray
86671 +crypto_authenc_setkey_80 crypto_authenc_setkey 3 80 &DepcaSignature_80
86672 +init_cdev_8274 init_cdev 1 8274 NULL
86673 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
86674 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL nohasharray
86675 +alloc_ftrace_hash_57431 alloc_ftrace_hash 1 57431 &compat_keyctl_instantiate_key_iov_57431
86676 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
86677 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
86678 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
86679 +load_msg_95 load_msg 2 95 NULL
86680 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
86681 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
86682 +acpi_tb_check_xsdt_21862 acpi_tb_check_xsdt 1 21862 NULL
86683 +sys_pselect6_57449 sys_pselect6 1 57449 NULL
86684 +biovec_create_pools_9575 biovec_create_pools 2 9575 NULL
86685 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
86686 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
86687 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 NULL nohasharray
86688 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 &ath6kl_usb_submit_ctrl_in_32880
86689 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
86690 +send_midi_async_57463 send_midi_async 3 57463 NULL
86691 +sisusb_clear_vram_57466 sisusb_clear_vram 3-2 57466 NULL
86692 +ath6kl_usb_post_recv_transfers_32892 ath6kl_usb_post_recv_transfers 2 32892 NULL
86693 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL nohasharray
86694 +sep_lock_user_pages_57470 sep_lock_user_pages 2-3 57470 &ieee80211_if_read_flags_57470
86695 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
86696 +construct_key_and_link_8321 construct_key_and_link 4 8321 NULL
86697 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
86698 +init_q_132 init_q 4 132 NULL
86699 +roccat_read_41093 roccat_read 3 41093 NULL nohasharray
86700 +nvme_map_user_pages_41093 nvme_map_user_pages 3-4 41093 &roccat_read_41093
86701 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
86702 +unifi_net_data_malloc_24716 unifi_net_data_malloc 3 24716 NULL
86703 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
86704 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 NULL
86705 +uio_read_49300 uio_read 3 49300 NULL
86706 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
86707 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 NULL
86708 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
86709 +firmwareUpload_32794 firmwareUpload 3 32794 NULL
86710 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
86711 +play_iframe_8219 play_iframe 3 8219 NULL
86712 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
86713 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
86714 +ath_rxbuf_alloc_24745 ath_rxbuf_alloc 2 24745 NULL
86715 +nvme_create_queue_170 nvme_create_queue 3 170 NULL
86716 +init_tag_map_57515 init_tag_map 3 57515 NULL
86717 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 NULL
86718 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-3-4 49330 NULL
86719 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
86720 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
86721 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
86722 +DoC_Probe_57534 DoC_Probe 1 57534 NULL
86723 +cfpkt_setlen_49343 cfpkt_setlen 2 49343 NULL
86724 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
86725 +mI_alloc_skb_24770 mI_alloc_skb 1 24770 NULL
86726 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
86727 +virtblk_add_req_197 virtblk_add_req 2-3 197 NULL
86728 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
86729 +rds_tcp_data_recv_53476 rds_tcp_data_recv 3 53476 NULL
86730 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
86731 +skb_make_writable_24783 skb_make_writable 2 24783 NULL
86732 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
86733 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
86734 +cache_read_24790 cache_read 3 24790 NULL
86735 +px_raw_event_49371 px_raw_event 4 49371 NULL
86736 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
86737 +compat_filldir_32999 compat_filldir 3 32999 NULL
86738 +hci_si_event_1404 hci_si_event 3 1404 NULL
86739 +compat_sys_process_vm_writev_41194 compat_sys_process_vm_writev 3-5 41194 NULL
86740 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
86741 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
86742 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
86743 +applesmc_create_nodes_49392 applesmc_create_nodes 2 49392 NULL
86744 +snd_usb_ctl_msg_8436 snd_usb_ctl_msg 8 8436 NULL
86745 +comedi_buf_alloc_24822 comedi_buf_alloc 3 24822 NULL
86746 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
86747 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
86748 +tun_alloc_skb_41216 tun_alloc_skb 2-4-3 41216 NULL
86749 +proc_scsi_write_proc_267 proc_scsi_write_proc 3 267 NULL
86750 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
86751 +sk_stream_alloc_skb_57622 sk_stream_alloc_skb 2 57622 NULL
86752 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
86753 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
86754 +mfd_add_devices_16668 mfd_add_devices 4 16668 NULL
86755 +packet_recv_error_16669 packet_recv_error 3 16669 NULL
86756 +osdmap_set_max_osd_57630 osdmap_set_max_osd 2 57630 NULL nohasharray
86757 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 &osdmap_set_max_osd_57630
86758 +mem_read_57631 mem_read 3 57631 NULL
86759 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
86760 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
86761 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
86762 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
86763 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
86764 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
86765 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
86766 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
86767 +queues_read_24877 queues_read 3 24877 NULL
86768 +__fprog_create_41263 __fprog_create 2 41263 NULL
86769 +syslog_print_307 syslog_print 2 307 NULL
86770 +platform_device_add_data_310 platform_device_add_data 3 310 NULL
86771 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
86772 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
86773 +sys_mq_timedsend_57661 sys_mq_timedsend 3 57661 NULL
86774 +r3964_write_57662 r3964_write 4 57662 NULL
86775 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
86776 +savu_sysfs_read_49473 savu_sysfs_read 6 49473 NULL
86777 +dn_nsp_do_disc_49474 dn_nsp_do_disc 6-2 49474 NULL
86778 +alloc_context_41283 alloc_context 1 41283 NULL
86779 +__lgwrite_57669 __lgwrite 4 57669 NULL
86780 +ath9k_wmi_cmd_327 ath9k_wmi_cmd 4 327 NULL
86781 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
86782 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
86783 +alloc_pg_vec_8533 alloc_pg_vec 2 8533 NULL
86784 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
86785 +ieee80211_fragment_33112 ieee80211_fragment 4 33112 NULL
86786 +arch_gnttab_map_shared_41306 arch_gnttab_map_shared 3 41306 NULL
86787 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL
86788 +write_node_33121 write_node 4 33121 NULL
86789 +vring_new_virtqueue_54673 vring_new_virtqueue 2 54673 NULL
86790 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
86791 +profile_remove_8556 profile_remove 3 8556 NULL
86792 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
86793 +iscsi_recv_pdu_16755 iscsi_recv_pdu 4 16755 NULL
86794 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
86795 +cmtp_send_interopmsg_376 cmtp_send_interopmsg 7 376 NULL
86796 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
86797 +mga_ioremap_8571 mga_ioremap 1-2 8571 NULL
86798 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
86799 +sys_rt_sigpending_24961 sys_rt_sigpending 2 24961 NULL
86800 +tower_write_8580 tower_write 3 8580 NULL
86801 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
86802 +compat_sys_set_mempolicy_57742 compat_sys_set_mempolicy 3 57742 NULL nohasharray
86803 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 &compat_sys_set_mempolicy_57742
86804 +jbd2_alloc_41359 jbd2_alloc 1 41359 NULL
86805 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
86806 +nf_nat_sdp_port_24977 nf_nat_sdp_port 7 24977 NULL
86807 +smk_write_access_49561 smk_write_access 3 49561 NULL
86808 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
86809 +kmp_init_41373 kmp_init 2 41373 NULL
86810 +context_alloc_24645 context_alloc 3 24645 NULL
86811 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
86812 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
86813 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
86814 +tipc_send2name_16809 tipc_send2name 6 16809 NULL
86815 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
86816 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
86817 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
86818 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
86819 +dm_vcalloc_16814 dm_vcalloc 1-2 16814 NULL
86820 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
86821 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
86822 +pp_read_33210 pp_read 3 33210 NULL
86823 +sys_flistxattr_41407 sys_flistxattr 3 41407 NULL
86824 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
86825 +ivtv_read_57796 ivtv_read 3 57796 NULL
86826 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
86827 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
86828 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
86829 +heap_init_49617 heap_init 2 49617 NULL
86830 +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
86831 +ieee80211_send_probe_req_38307 ieee80211_send_probe_req 6-4 38307 NULL
86832 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
86833 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
86834 +_alloc_get_attr_desc_470 _alloc_get_attr_desc 2 470 NULL
86835 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
86836 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
86837 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
86838 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 4-6 41442 NULL
86839 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
86840 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
86841 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
86842 +st_write_16874 st_write 3 16874 NULL
86843 +copy_to_user_57835 copy_to_user 3 57835 NULL
86844 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
86845 +pidlist_resize_496 pidlist_resize 2 496 NULL
86846 +flash_read_57843 flash_read 3 57843 NULL
86847 +read_vbt_r0_503 read_vbt_r0 1 503 NULL
86848 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
86849 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
86850 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
86851 +arcfb_write_8702 arcfb_write 3 8702 NULL
86852 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
86853 +smp_send_cmd_512 smp_send_cmd 3 512 NULL
86854 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
86855 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 NULL nohasharray
86856 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 &rfcomm_sock_sendmsg_37661
86857 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
86858 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
86859 +cxio_hal_init_rhdl_resource_25104 cxio_hal_init_rhdl_resource 1 25104 NULL
86860 +sock_wmalloc_16472 sock_wmalloc 2 16472 NULL
86861 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
86862 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
86863 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
86864 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
86865 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
86866 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
86867 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
86868 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
86869 +sys_gethostname_49698 sys_gethostname 2 49698 NULL
86870 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
86871 +ieee80211_rx_mgmt_probe_resp_6918 ieee80211_rx_mgmt_probe_resp 3 6918 NULL
86872 +devres_alloc_551 devres_alloc 2 551 NULL
86873 +ldisc_receive_41516 ldisc_receive 4 41516 NULL
86874 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
86875 +ip_append_data_16942 ip_append_data 5-6 16942 NULL
86876 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
86877 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
86878 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
86879 +emi26_writememory_57908 emi26_writememory 4 57908 NULL
86880 +start_isoc_chain_565 start_isoc_chain 2 565 NULL
86881 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
86882 +gsm_mux_rx_netchar_33336 gsm_mux_rx_netchar 3 33336 NULL
86883 +brcmu_pkt_buf_get_skb_5556 brcmu_pkt_buf_get_skb 1 5556 NULL
86884 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
86885 +sys_prctl_8766 sys_prctl 4 8766 NULL
86886 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
86887 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
86888 +compat_sys_preadv_583 compat_sys_preadv 3 583 NULL
86889 +sys_fsetxattr_49736 sys_fsetxattr 4 49736 NULL
86890 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
86891 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
86892 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
86893 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
86894 +sys_fgetxattr_25166 sys_fgetxattr 4 25166 NULL
86895 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
86896 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
86897 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
86898 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
86899 +ath6kl_buf_alloc_57304 ath6kl_buf_alloc 1 57304 NULL
86900 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
86901 +gserial_setup_41558 gserial_setup 2 41558 NULL
86902 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
86903 +rx_57944 rx 4 57944 NULL
86904 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
86905 +nci_skb_alloc_49757 nci_skb_alloc 2 49757 NULL
86906 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
86907 +cpuset_common_file_read_8800 cpuset_common_file_read 5 8800 NULL
86908 +sctp_ulpevent_new_33377 sctp_ulpevent_new 1 33377 NULL
86909 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
86910 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
86911 +isku_sysfs_write_49767 isku_sysfs_write 6 49767 NULL
86912 +i915_cache_sharing_write_57961 i915_cache_sharing_write 3 57961 NULL
86913 +batadv_receive_client_update_packet_41578 batadv_receive_client_update_packet 3 41578 NULL
86914 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
86915 +handle_response_icmp_39574 handle_response_icmp 7 39574 NULL
86916 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
86917 +hfc_empty_fifo_57972 hfc_empty_fifo 2 57972 NULL
86918 +ceph_dns_resolve_name_62488 ceph_dns_resolve_name 2 62488 NULL
86919 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
86920 +icmpv6_manip_pkt_8833 icmpv6_manip_pkt 4 8833 NULL
86921 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
86922 +read_file_rx_chainmask_41605 read_file_rx_chainmask 3 41605 NULL
86923 +vmw_du_crtc_cursor_set_28479 vmw_du_crtc_cursor_set 4-5 28479 NULL
86924 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
86925 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
86926 +a2mp_send_41615 a2mp_send 4 41615 NULL
86927 +ceph_copy_user_to_page_vector_656 ceph_copy_user_to_page_vector 4-3 656 NULL
86928 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
86929 +arch_gnttab_map_status_49812 arch_gnttab_map_status 3 49812 NULL
86930 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
86931 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
86932 +tcf_csum_ipv6_udp_25241 tcf_csum_ipv6_udp 4 25241 NULL
86933 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
86934 +macvtap_alloc_skb_50629 macvtap_alloc_skb 2-4-3 50629 NULL
86935 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
86936 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6 49829 NULL
86937 +add_uuid_49831 add_uuid 4 49831 NULL
86938 +send_pages_8872 send_pages 3 8872 NULL
86939 +ath6kl_fwlog_block_read_49836 ath6kl_fwlog_block_read 3 49836 NULL
86940 +__btrfs_map_block_49839 __btrfs_map_block 3 49839 NULL
86941 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
86942 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
86943 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
86944 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
86945 +__kmalloc_reserve_17080 __kmalloc_reserve 1 17080 NULL
86946 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
86947 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
86948 +vfs_writev_25278 vfs_writev 3 25278 NULL
86949 +rtl8169_try_rx_copy_705 rtl8169_try_rx_copy 3 705 NULL
86950 +alloc_async_14208 alloc_async 1 14208 NULL
86951 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
86952 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
86953 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
86954 +create_entry_33479 create_entry 2 33479 NULL
86955 +mce_async_out_58056 mce_async_out 3 58056 NULL
86956 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
86957 +sys_preadv_17100 sys_preadv 3 17100 NULL
86958 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
86959 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
86960 +netxen_nic_hw_write_wx_128M_33488 netxen_nic_hw_write_wx_128M 2 33488 NULL
86961 +aac_src_ioremap_41688 aac_src_ioremap 2 41688 NULL
86962 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
86963 +res_counter_read_33499 res_counter_read 4 33499 NULL
86964 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
86965 +cm4040_write_58079 cm4040_write 3 58079 NULL
86966 +fb_read_33506 fb_read 3 33506 NULL
86967 +help_25316 help 5 25316 NULL nohasharray
86968 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 &help_25316
86969 +rfcomm_wmalloc_58090 rfcomm_wmalloc 2 58090 NULL
86970 +mwifiex_get_common_rates_17131 mwifiex_get_common_rates 3 17131 NULL
86971 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
86972 +ddp_set_map_751 ddp_set_map 4 751 NULL
86973 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
86974 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
86975 +dvb_video_write_754 dvb_video_write 3 754 NULL
86976 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
86977 +osd_req_add_get_attr_list_49278 osd_req_add_get_attr_list 3 49278 NULL
86978 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
86979 +bdx_tx_db_init_41719 bdx_tx_db_init 2 41719 NULL
86980 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
86981 +udi_log_event_58105 udi_log_event 3 58105 NULL
86982 +sys_pwritev_41722 sys_pwritev 3 41722 NULL
86983 +l2cap_sock_alloc_skb_cb_33532 l2cap_sock_alloc_skb_cb 2 33532 NULL
86984 +ib_send_cm_mra_60202 ib_send_cm_mra 4 60202 NULL nohasharray
86985 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 &ib_send_cm_mra_60202
86986 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
86987 +__copy_from_user_inatomic_nocache_49921 __copy_from_user_inatomic_nocache 3 49921 NULL
86988 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL
86989 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
86990 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
86991 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
86992 +vol_cdev_read_8968 vol_cdev_read 3 8968 NULL nohasharray
86993 +seq_open_net_8968 seq_open_net 4 8968 &vol_cdev_read_8968
86994 +sep_read_17161 sep_read 3 17161 NULL
86995 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
86996 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
86997 +dup_array_33551 dup_array 3 33551 NULL
86998 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
86999 +solo_enc_read_33553 solo_enc_read 3 33553 NULL
87000 +fillonedir_41746 fillonedir 3 41746 NULL
87001 +init_bch_64130 init_bch 1-2 64130 NULL
87002 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
87003 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
87004 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
87005 +btrfs_alloc_free_block_8986 btrfs_alloc_free_block 3 8986 NULL
87006 +savemem_58129 savemem 3 58129 NULL
87007 +batadv_tt_realloc_packet_buff_49960 batadv_tt_realloc_packet_buff 4 49960 NULL
87008 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
87009 +driver_state_read_17194 driver_state_read 3 17194 NULL nohasharray
87010 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 &driver_state_read_17194
87011 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL
87012 +if_writecmd_815 if_writecmd 2 815 NULL
87013 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
87014 +read_fifo_826 read_fifo 3 826 NULL
87015 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
87016 +scsi_execute_33596 scsi_execute 5 33596 NULL
87017 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
87018 +ms_rw_17220 ms_rw 3-4 17220 NULL
87019 +read_tree_block_841 read_tree_block 3 841 NULL
87020 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
87021 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
87022 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
87023 +__pskb_copy_9038 __pskb_copy 2 9038 NULL
87024 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
87025 +asix_write_cmd_58192 asix_write_cmd 5 58192 NULL
87026 +um_idi_read_850 um_idi_read 3 850 NULL
87027 +__module_alloc_50004 __module_alloc 1 50004 NULL
87028 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
87029 +ts_read_44687 ts_read 3 44687 NULL
87030 +nci_send_cmd_58206 nci_send_cmd 3 58206 NULL
87031 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
87032 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
87033 +provide_user_output_41105 provide_user_output 3 41105 NULL
87034 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
87035 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
87036 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
87037 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
87038 +alloc_ep_17269 alloc_ep 1 17269 NULL
87039 +ath6kl_wmi_beginscan_cmd_25462 ath6kl_wmi_beginscan_cmd 8 25462 NULL
87040 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 NULL
87041 +generic_file_buffered_write_25464 generic_file_buffered_write 4 25464 NULL
87042 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
87043 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
87044 +alloc_ebda_hpc_50046 alloc_ebda_hpc 1-2 50046 NULL
87045 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
87046 +create_queues_9088 create_queues 2-3 9088 NULL
87047 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
87048 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
87049 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
87050 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
87051 +rbd_alloc_coll_33678 rbd_alloc_coll 1 33678 NULL
87052 +read_file_debug_58256 read_file_debug 3 58256 NULL
87053 +skb_pad_17302 skb_pad 2 17302 NULL
87054 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
87055 +btmrvl_hsstate_read_920 btmrvl_hsstate_read 3 920 NULL
87056 +profile_load_58267 profile_load 3 58267 NULL
87057 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
87058 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4 25502 NULL
87059 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
87060 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
87061 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
87062 +pcpu_get_vm_areas_50085 pcpu_get_vm_areas 3 50085 NULL
87063 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
87064 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
87065 +sys_keyctl_33708 sys_keyctl 4 33708 NULL nohasharray
87066 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 &sys_keyctl_33708
87067 +ata_host_alloc_pinfo_17325 ata_host_alloc_pinfo 3 17325 NULL
87068 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
87069 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
87070 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
87071 +get_packet_41914 get_packet 3 41914 NULL
87072 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
87073 +ceph_get_direct_page_vector_41917 ceph_get_direct_page_vector 2 41917 NULL
87074 +read_file_slot_50111 read_file_slot 3 50111 NULL
87075 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
87076 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
87077 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
87078 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
87079 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
87080 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
87081 +copy_items_50140 copy_items 6 50140 NULL
87082 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
87083 +pcim_iomap_58334 pcim_iomap 3 58334 NULL
87084 +diva_init_dma_map_58336 diva_init_dma_map 3 58336 NULL
87085 +map_addr_56144 map_addr 7 56144 NULL
87086 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
87087 +btmrvl_psstate_read_50683 btmrvl_psstate_read 3 50683 NULL
87088 +hdlcdev_rx_997 hdlcdev_rx 3 997 NULL
87089 +portnames_read_41958 portnames_read 3 41958 NULL
87090 +ubi_self_check_all_ff_41959 ubi_self_check_all_ff 4 41959 NULL
87091 +hashtab_create_33769 hashtab_create 3 33769 NULL
87092 +alloc_group_attrs_9194 alloc_group_attrs 2 9194 NULL nohasharray
87093 +altera_swap_ir_9194 altera_swap_ir 2 9194 &alloc_group_attrs_9194
87094 +vmalloc_to_sg_58354 vmalloc_to_sg 2 58354 NULL
87095 +aac_nark_ioremap_50163 aac_nark_ioremap 2 50163 NULL nohasharray
87096 +kmalloc_node_50163 kmalloc_node 1 50163 &aac_nark_ioremap_50163
87097 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
87098 +odev_update_50169 odev_update 2 50169 NULL
87099 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL
87100 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
87101 +__devres_alloc_25598 __devres_alloc 2 25598 NULL
87102 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
87103 +netpoll_send_udp_58955 netpoll_send_udp 3 58955 NULL
87104 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
87105 +ib_send_cm_drep_50186 ib_send_cm_drep 3 50186 NULL
87106 +do_write_orph_node_64343 do_write_orph_node 2 64343 NULL
87107 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
87108 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
87109 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
87110 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
87111 +lguest_map_42008 lguest_map 1-2 42008 NULL
87112 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
87113 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
87114 +pool_allocate_42012 pool_allocate 3 42012 NULL
87115 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
87116 +sctp_make_init_58401 sctp_make_init 4 58401 NULL
87117 +ieee80211_skb_resize_50211 ieee80211_skb_resize 3 50211 NULL
87118 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
87119 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
87120 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
87121 +udplite_manip_pkt_33832 udplite_manip_pkt 4 33832 NULL
87122 +tcf_csum_ipv4_icmp_9258 tcf_csum_ipv4_icmp 3 9258 NULL
87123 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
87124 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
87125 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
87126 +sparse_early_usemaps_alloc_node_9269 sparse_early_usemaps_alloc_node 4 9269 NULL
87127 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
87128 +iscsi_offload_mesg_58425 iscsi_offload_mesg 5 58425 NULL
87129 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
87130 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
87131 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
87132 +nfs_pgarray_set_1085 nfs_pgarray_set 2 1085 NULL
87133 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
87134 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
87135 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
87136 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
87137 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
87138 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
87139 +__alloc_session_17485 __alloc_session 2-1 17485 NULL
87140 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
87141 +pm860x_bulk_write_43875 pm860x_bulk_write 3 43875 NULL
87142 +afs_extract_data_50261 afs_extract_data 5 50261 NULL
87143 +config_proc_write_33878 config_proc_write 3 33878 NULL
87144 +capabilities_read_58457 capabilities_read 3 58457 NULL
87145 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
87146 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
87147 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 NULL nohasharray
87148 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 &lpfc_idiag_baracc_read_58466
87149 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
87150 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
87151 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
87152 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
87153 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
87154 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
87155 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
87156 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
87157 +batadv_bla_is_backbone_gw_58488 batadv_bla_is_backbone_gw 3 58488 NULL
87158 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
87159 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
87160 +sel_write_context_25726 sel_write_context 3 25726 NULL nohasharray
87161 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 &sel_write_context_25726
87162 +sysfs_read_file_42113 sysfs_read_file 3 42113 NULL
87163 +mcs_unwrap_fir_25733 mcs_unwrap_fir 3 25733 NULL
87164 +vme_user_write_15587 vme_user_write 3 15587 NULL
87165 +xlog_do_log_recovery_17550 xlog_do_log_recovery 3 17550 NULL
87166 +__copy_to_user_17551 __copy_to_user 3 17551 NULL
87167 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
87168 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
87169 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
87170 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
87171 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
87172 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
87173 +v9fs_alloc_rdir_buf_42150 v9fs_alloc_rdir_buf 2 42150 NULL
87174 +roccat_common2_send_with_status_50343 roccat_common2_send_with_status 4 50343 NULL
87175 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
87176 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
87177 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
87178 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
87179 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
87180 +read_9397 read 3 9397 NULL
87181 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
87182 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
87183 +printer_write_60276 printer_write 3 60276 NULL
87184 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
87185 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
87186 +rts51x_write_mem_17598 rts51x_write_mem 4 17598 NULL
87187 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
87188 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
87189 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
87190 +osst_execute_17607 osst_execute 7-6 17607 NULL
87191 +nf_nat_sip_expect_9418 nf_nat_sip_expect 8 9418 NULL
87192 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
87193 +ipw_packet_received_skb_1230 ipw_packet_received_skb 2 1230 NULL
87194 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
87195 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
87196 +sys32_rt_sigpending_25814 sys32_rt_sigpending 2 25814 NULL
87197 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
87198 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
87199 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
87200 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
87201 +xip_file_read_58592 xip_file_read 3 58592 NULL
87202 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
87203 +kmalloc_array_9444 kmalloc_array 1-2 9444 NULL
87204 +__ntfs_malloc_34022 __ntfs_malloc 1 34022 NULL
87205 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
87206 +mcs_unwrap_mir_9455 mcs_unwrap_mir 3 9455 NULL
87207 +ppp_write_34034 ppp_write 3 34034 NULL
87208 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
87209 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
87210 +tty_insert_flip_string_34042 tty_insert_flip_string 3 34042 NULL
87211 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
87212 +batadv_tt_prepare_packet_buff_1280 batadv_tt_prepare_packet_buff 4 1280 NULL
87213 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
87214 +module_alloc_update_bounds_rx_58634 module_alloc_update_bounds_rx 1 58634 NULL nohasharray
87215 +efi_ioremap_58634 efi_ioremap 1-2 58634 &module_alloc_update_bounds_rx_58634
87216 +btmrvl_hsmode_write_42252 btmrvl_hsmode_write 3 42252 NULL
87217 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
87218 +dsp_tone_hw_message_17678 dsp_tone_hw_message 3 17678 NULL
87219 +netxen_nic_map_indirect_address_128M_42257 netxen_nic_map_indirect_address_128M 2 42257 NULL
87220 +ulog_alloc_skb_23427 ulog_alloc_skb 1 23427 NULL
87221 +__alloc_preds_9492 __alloc_preds 2 9492 NULL
87222 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
87223 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
87224 +read_file_ant_diversity_34071 read_file_ant_diversity 3 34071 NULL
87225 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
87226 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
87227 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
87228 +savu_sysfs_write_42273 savu_sysfs_write 6 42273 NULL
87229 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 NULL
87230 +lp_write_9511 lp_write 3 9511 NULL
87231 +__einj_error_trigger_17707 __einj_error_trigger 1 17707 NULL nohasharray
87232 +venus_rename_17707 venus_rename 5-4 17707 &__einj_error_trigger_17707
87233 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
87234 +nfs_readdir_make_qstr_12509 nfs_readdir_make_qstr 3 12509 NULL
87235 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
87236 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
87237 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
87238 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
87239 +read_file_dma_9530 read_file_dma 3 9530 NULL
87240 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
87241 +rcname_read_25919 rcname_read 3 25919 NULL
87242 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
87243 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
87244 +tps6586x_writes_58689 tps6586x_writes 3 58689 NULL
87245 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
87246 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
87247 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
87248 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
87249 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
87250 +key_flags_read_25931 key_flags_read 3 25931 NULL
87251 +audit_log_n_untrustedstring_9548 audit_log_n_untrustedstring 3 9548 NULL
87252 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
87253 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
87254 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
87255 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
87256 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
87257 +fw_node_create_9559 fw_node_create 2 9559 NULL
87258 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
87259 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
87260 +kobj_map_9566 kobj_map 2-3 9566 NULL
87261 +snd_pcm_plug_alloc_42339 snd_pcm_plug_alloc 2 42339 NULL
87262 +acpi_map_58725 acpi_map 1-2 58725 NULL
87263 +brcmf_usb_attach_17766 brcmf_usb_attach 2-3 17766 NULL
87264 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
87265 +fwnet_receive_packet_50537 fwnet_receive_packet 9 50537 NULL
87266 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
87267 +ieee80211_tdls_mgmt_9581 ieee80211_tdls_mgmt 8 9581 NULL
87268 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
87269 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
87270 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
87271 +file_read_actor_1401 file_read_actor 4 1401 NULL
87272 +av7110_ipack_init_46655 av7110_ipack_init 2 46655 NULL
87273 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
87274 +ubifs_leb_change_17789 ubifs_leb_change 4 17789 NULL
87275 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
87276 +do_sync_9604 do_sync 1 9604 NULL
87277 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5 9605 NULL
87278 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
87279 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
87280 +__do_config_autodelink_58763 __do_config_autodelink 3 58763 NULL
87281 +sctp_sf_abort_violation_1420 sctp_sf_abort_violation 7 1420 NULL
87282 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
87283 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
87284 +lpfc_sli_probe_sriov_nr_virtfn_26004 lpfc_sli_probe_sriov_nr_virtfn 2 26004 NULL
87285 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
87286 +fat_readpages_50582 fat_readpages 4 50582 NULL nohasharray
87287 +pep_reply_50582 pep_reply 5 50582 &fat_readpages_50582
87288 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
87289 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
87290 +_snd_pcm_lib_alloc_vmalloc_buffer_17820 _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 NULL
87291 +xfs_readdir_41200 xfs_readdir 3 41200 NULL
87292 +sge_rx_50594 sge_rx 3 50594 NULL
87293 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
87294 +compat_sys_keyctl_9639 compat_sys_keyctl 4 9639 NULL
87295 +skb_padto_50759 skb_padto 2 50759 NULL
87296 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
87297 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
87298 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
87299 +isku_sysfs_read_58806 isku_sysfs_read 6 58806 NULL
87300 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
87301 +uvc_alloc_buffers_9656 uvc_alloc_buffers 2-3 9656 NULL
87302 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
87303 +ep_read_58813 ep_read 3 58813 NULL
87304 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
87305 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
87306 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
87307 +pci_enable_sriov_35745 pci_enable_sriov 2 35745 NULL
87308 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
87309 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
87310 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
87311 +dns_query_9676 dns_query 3 9676 NULL
87312 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
87313 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
87314 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
87315 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL
87316 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
87317 +command_write_58841 command_write 3 58841 NULL
87318 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
87319 +dev_config_8506 dev_config 3 8506 NULL
87320 +compat_sys_pwritev_17886 compat_sys_pwritev 3 17886 NULL
87321 +sys_readv_50664 sys_readv 3 50664 NULL
87322 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
87323 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
87324 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
87325 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
87326 +recover_head_17904 recover_head 3 17904 NULL
87327 +dccp_feat_register_sp_17914 dccp_feat_register_sp 5 17914 NULL
87328 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
87329 +brcmf_sdbrcm_bus_txctl_42492 brcmf_sdbrcm_bus_txctl 3 42492 NULL
87330 +srp_iu_pool_alloc_17920 srp_iu_pool_alloc 2 17920 NULL
87331 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
87332 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
87333 +cs553x_init_one_58886 cs553x_init_one 3 58886 NULL
87334 +ddb_input_read_9743 ddb_input_read 3 9743 NULL
87335 +skb_cow_26138 skb_cow 2 26138 NULL
87336 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
87337 +snd_emux_create_port_42533 snd_emux_create_port 3 42533 NULL
87338 +do_sigpending_9766 do_sigpending 2 9766 NULL
87339 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
87340 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
87341 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
87342 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
87343 +copy_oldmem_page_26164 copy_oldmem_page 3-1 26164 NULL
87344 +i915_ring_stop_read_42549 i915_ring_stop_read 3 42549 NULL nohasharray
87345 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 &i915_ring_stop_read_42549
87346 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 NULL
87347 +snd_mem_proc_write_9786 snd_mem_proc_write 3 9786 NULL
87348 +fc_frame_alloc_1596 fc_frame_alloc 2 1596 NULL
87349 +rngapi_reset_34366 rngapi_reset 3 34366 NULL nohasharray
87350 +p54_alloc_skb_34366 p54_alloc_skb 3 34366 &rngapi_reset_34366
87351 +iwl_calib_set_34400 iwl_calib_set 3 34400 NULL nohasharray
87352 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 &iwl_calib_set_34400
87353 +solo_v4l2_read_59247 solo_v4l2_read 3 59247 NULL
87354 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
87355 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
87356 +reiserfs_resize_34377 reiserfs_resize 2 34377 NULL
87357 +get_registers_26187 get_registers 3 26187 NULL
87358 +cgroup_setxattr_26188 cgroup_setxattr 4 26188 NULL
87359 +ttm_bo_fbdev_io_9805 ttm_bo_fbdev_io 4 9805 NULL
87360 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
87361 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
87362 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
87363 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3 27332 NULL
87364 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 NULL nohasharray
87365 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 &udpv6_recvmsg_9813
87366 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL nohasharray
87367 +pipe_handler_request_50774 pipe_handler_request 5 50774 &tm6000_read_write_usb_50774
87368 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
87369 +mce_write_26201 mce_write 3 26201 NULL
87370 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
87371 +bio_alloc_map_data_50782 bio_alloc_map_data 1-2 50782 NULL
87372 +alloc_rx_desc_ring_18016 alloc_rx_desc_ring 2 18016 NULL
87373 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
87374 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
87375 +__pskb_pull_42602 __pskb_pull 2 42602 NULL
87376 +sctp_make_heartbeat_ack_34411 sctp_make_heartbeat_ack 4 34411 NULL
87377 +tpm_write_50798 tpm_write 3 50798 NULL
87378 +btmrvl_hsmode_read_1647 btmrvl_hsmode_read 3 1647 NULL
87379 +tun_do_read_50800 tun_do_read 4 50800 NULL
87380 +handle_rx_packet_58993 handle_rx_packet 3 58993 NULL
87381 +write_flush_50803 write_flush 3 50803 NULL
87382 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
87383 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
87384 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
87385 +dvb_play_50814 dvb_play 3 50814 NULL
87386 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
87387 +sys_move_pages_42626 sys_move_pages 2 42626 NULL
87388 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
87389 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
87390 +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
87391 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
87392 +dma_attach_50831 dma_attach 6-7 50831 NULL
87393 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
87394 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
87395 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
87396 +packet_came_18072 packet_came 3 18072 NULL
87397 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
87398 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
87399 +sctp_make_abort_34459 sctp_make_abort 3 34459 NULL
87400 +_regmap_raw_write_42652 _regmap_raw_write 4 42652 NULL
87401 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
87402 +get_vm_area_18080 get_vm_area 1 18080 NULL
87403 +dvb_dvr_set_buffer_size_9840 dvb_dvr_set_buffer_size 2 9840 NULL
87404 +bm_register_write_9893 bm_register_write 3 9893 NULL nohasharray
87405 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 &bm_register_write_9893
87406 +self_check_write_50856 self_check_write 5 50856 NULL
87407 +line6_dumpreq_init_34473 line6_dumpreq_init 3 34473 NULL
87408 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
87409 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
87410 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
87411 +l2tp_xmit_skb_42672 l2tp_xmit_skb 3 42672 NULL
87412 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
87413 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
87414 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
87415 +sis190_try_rx_copy_57069 sis190_try_rx_copy 3 57069 NULL
87416 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
87417 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
87418 +vb2_read_42703 vb2_read 3 42703 NULL
87419 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
87420 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
87421 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
87422 +snd_pcm_plugin_alloc_12580 snd_pcm_plugin_alloc 2 12580 NULL
87423 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
87424 +read_file_misc_9948 read_file_misc 3 9948 NULL
87425 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
87426 +set_rxd_buffer_pointer_9950 set_rxd_buffer_pointer 8 9950 NULL
87427 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
87428 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
87429 +tracing_stats_read_34537 tracing_stats_read 3 34537 NULL
87430 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
87431 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
87432 +cosa_write_1774 cosa_write 3 1774 NULL
87433 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
87434 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4 34547 NULL
87435 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
87436 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
87437 +bnx2fc_cmd_mgr_alloc_24873 bnx2fc_cmd_mgr_alloc 3-2 24873 NULL
87438 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
87439 +ath6kl_usb_submit_ctrl_out_9978 ath6kl_usb_submit_ctrl_out 6 9978 NULL
87440 +dup_to_netobj_26363 dup_to_netobj 3 26363 NULL
87441 +sock_bindtodevice_50942 sock_bindtodevice 3 50942 NULL
87442 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
87443 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
87444 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
87445 +mld_newpack_50950 mld_newpack 2 50950 NULL
87446 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL
87447 +i915_ring_stop_write_59010 i915_ring_stop_write 3 59010 NULL
87448 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
87449 +cfpkt_create_18197 cfpkt_create 1 18197 NULL
87450 +velocity_rx_copy_34583 velocity_rx_copy 2 34583 NULL
87451 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
87452 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
87453 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4 37428 NULL
87454 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
87455 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
87456 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
87457 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
87458 +handle_request_10024 handle_request 9 10024 NULL
87459 +__tty_alloc_driver_53799 __tty_alloc_driver 1 53799 NULL
87460 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
87461 +timeout_write_50991 timeout_write 3 50991 NULL
87462 +batadv_orig_hash_add_if_10033 batadv_orig_hash_add_if 2 10033 NULL
87463 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
87464 +ip_vs_create_timeout_table_64478 ip_vs_create_timeout_table 2 64478 NULL
87465 +proc_write_51003 proc_write 3 51003 NULL
87466 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
87467 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
87468 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
87469 +set_arg_42824 set_arg 3 42824 NULL
87470 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
87471 +fast_rx_path_59214 fast_rx_path 3 59214 NULL
87472 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
87473 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
87474 +audit_log_n_string_31705 audit_log_n_string 3 31705 NULL
87475 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
87476 +pstore_mkfile_50830 pstore_mkfile 5 50830 NULL
87477 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
87478 +hidp_queue_report_1881 hidp_queue_report 3 1881 NULL
87479 +dt3155_read_59226 dt3155_read 3 59226 NULL
87480 +xfs_buf_read_uncached_42844 xfs_buf_read_uncached 3 42844 NULL
87481 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
87482 +dump_midi_51040 dump_midi 3 51040 NULL
87483 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
87484 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
87485 +nf_nat_mangle_udp_packet_34661 nf_nat_mangle_udp_packet 8-6 34661 NULL
87486 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
87487 +tty_prepare_flip_string_flags_59240 tty_prepare_flip_string_flags 4 59240 NULL
87488 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 NULL
87489 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
87490 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
87491 +em28xx_v4l2_read_16701 em28xx_v4l2_read 3 16701 NULL
87492 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
87493 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
87494 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
87495 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
87496 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 NULL
87497 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
87498 +pskb_expand_head_42881 pskb_expand_head 2-3 42881 NULL
87499 +ip6ip6_err_18308 ip6ip6_err 5 18308 NULL
87500 +read_vmcore_26501 read_vmcore 3 26501 NULL
87501 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
87502 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
87503 +tipc_port_recv_sections_42890 tipc_port_recv_sections 4 42890 NULL
87504 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 3-4 26507 NULL
87505 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
87506 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
87507 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
87508 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
87509 +SendTxCommandPacket_42901 SendTxCommandPacket 3 42901 NULL
87510 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
87511 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
87512 +ath6kl_wmi_send_probe_response_cmd_31728 ath6kl_wmi_send_probe_response_cmd 6 31728 NULL
87513 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
87514 +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
87515 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
87516 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
87517 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
87518 +rds_message_inc_copy_to_user_26540 rds_message_inc_copy_to_user 3 26540 NULL
87519 +iscsi_nop_out_rsp_51117 iscsi_nop_out_rsp 4 51117 NULL
87520 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
87521 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
87522 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
87523 +sctp_make_datafrag_empty_34737 sctp_make_datafrag_empty 3 34737 NULL
87524 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
87525 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
87526 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
87527 +fd_copyout_59323 fd_copyout 3 59323 NULL
87528 +nfs_map_name_to_uid_51132 nfs_map_name_to_uid 3 51132 NULL
87529 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
87530 +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
87531 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
87532 +diva_alloc_dma_map_23798 diva_alloc_dma_map 2 23798 NULL
87533 +solos_param_store_34755 solos_param_store 4 34755 NULL
87534 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
87535 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
87536 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
87537 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
87538 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
87539 +ib_send_cm_rtu_63138 ib_send_cm_rtu 3 63138 NULL
87540 +compat_sys_pwritev64_51151 compat_sys_pwritev64 3 51151 NULL
87541 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL nohasharray
87542 +batadv_receive_server_sync_packet_26577 batadv_receive_server_sync_packet 3 26577 &rts51x_read_mem_26577
87543 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
87544 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
87545 +batadv_tt_commit_changes_2008 batadv_tt_commit_changes 4 2008 NULL
87546 +sep_prepare_input_dma_table_2009 sep_prepare_input_dma_table 2-3 2009 NULL
87547 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
87548 +ubifs_write_node_11258 ubifs_write_node 5-3 11258 NULL
87549 +reada_tree_block_flagged_18402 reada_tree_block_flagged 3 18402 NULL
87550 +iscsi_if_send_reply_52219 iscsi_if_send_reply 7 52219 NULL
87551 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
87552 +__copy_in_user_34790 __copy_in_user 3 34790 NULL
87553 +crystalhd_user_data_18407 crystalhd_user_data 3 18407 NULL
87554 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL
87555 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
87556 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
87557 +devm_ioremap_nocache_2036 devm_ioremap_nocache 2-3 2036 NULL
87558 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
87559 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
87560 +batadv_orig_node_add_if_18433 batadv_orig_node_add_if 2 18433 NULL
87561 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
87562 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
87563 +nfc_alloc_recv_skb_10244 nfc_alloc_recv_skb 1 10244 NULL
87564 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
87565 +mangle_sdp_packet_30381 mangle_sdp_packet 10 30381 NULL
87566 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
87567 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
87568 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
87569 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
87570 +subbuf_read_actor_2071 subbuf_read_actor 3 2071 NULL
87571 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
87572 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL
87573 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
87574 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
87575 +receive_DataRequest_9904 receive_DataRequest 3 9904 NULL
87576 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
87577 +tipc_send_51238 tipc_send 4 51238 NULL
87578 +drm_property_create_51239 drm_property_create 4 51239 NULL
87579 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
87580 +squashfs_read_data_59440 squashfs_read_data 6 59440 NULL
87581 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
87582 +audit_expand_2098 audit_expand 2 2098 NULL
87583 +st_read_51251 st_read 3 51251 NULL
87584 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
87585 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
87586 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
87587 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
87588 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
87589 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
87590 +rtsx_read_cfg_seq_48139 rtsx_read_cfg_seq 5-3 48139 NULL
87591 +__find_xattr_2117 __find_xattr 6 2117 NULL nohasharray
87592 +enable_read_2117 enable_read 3 2117 &__find_xattr_2117
87593 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
87594 +pcf50633_write_block_2124 pcf50633_write_block 3 2124 NULL
87595 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
87596 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
87597 +c4_add_card_54968 c4_add_card 3 54968 NULL
87598 +rtllib_authentication_req_26713 rtllib_authentication_req 3 26713 NULL
87599 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
87600 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
87601 +fd_do_readv_51297 fd_do_readv 3 51297 NULL
87602 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 5-6-9 18530 NULL
87603 +nfc_hci_send_cmd_async_26723 nfc_hci_send_cmd_async 5 26723 NULL
87604 +mlx4_init_icm_table_2151 mlx4_init_icm_table 5-4 2151 NULL
87605 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
87606 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
87607 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
87608 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
87609 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
87610 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
87611 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
87612 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
87613 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
87614 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
87615 +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
87616 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
87617 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
87618 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
87619 +set_bypass_pwoff_pfs_27669 set_bypass_pwoff_pfs 3 27669 NULL
87620 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
87621 +srp_ring_alloc_26760 srp_ring_alloc 2 26760 NULL
87622 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
87623 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
87624 +ntfs_malloc_nofs_nofail_63631 ntfs_malloc_nofs_nofail 1 63631 NULL
87625 +cosa_net_setup_rx_38594 cosa_net_setup_rx 2 38594 NULL
87626 +skb_gro_header_slow_34958 skb_gro_header_slow 2 34958 NULL
87627 +debug_output_18575 debug_output 3 18575 NULL
87628 +Realloc_34961 Realloc 2 34961 NULL
87629 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
87630 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
87631 +_rtl92s_firmware_downloadcode_14021 _rtl92s_firmware_downloadcode 3 14021 NULL
87632 +__netdev_alloc_skb_18595 __netdev_alloc_skb 2 18595 NULL
87633 +slabinfo_write_18600 slabinfo_write 3 18600 NULL
87634 +ssb_bus_ssbbus_register_2217 ssb_bus_ssbbus_register 2 2217 NULL
87635 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
87636 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
87637 +vhci_write_2224 vhci_write 3 2224 NULL
87638 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
87639 +acpi_os_ioremap_49523 acpi_os_ioremap 1-2 49523 NULL
87640 +rb_alloc_3102 rb_alloc 1 3102 NULL
87641 +uf_create_device_nodes_24948 uf_create_device_nodes 2 24948 NULL
87642 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
87643 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
87644 +write_pbl_59583 write_pbl 4 59583 NULL
87645 +from_buffer_18625 from_buffer 3 18625 NULL
87646 +uio_write_43202 uio_write 3 43202 NULL
87647 +memdup_user_59590 memdup_user 2 59590 NULL
87648 +ieee80211_wx_set_gen_ie_51399 ieee80211_wx_set_gen_ie 3 51399 NULL
87649 +iso_callback_43208 iso_callback 3 43208 NULL
87650 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
87651 +smk_write_load_26829 smk_write_load 3 26829 NULL
87652 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
87653 +do_update_counters_2259 do_update_counters 4 2259 NULL
87654 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
87655 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
87656 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
87657 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
87658 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
87659 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
87660 +mtrr_write_59622 mtrr_write 3 59622 NULL
87661 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
87662 +ip_vs_icmp_xmit_59624 ip_vs_icmp_xmit 4 59624 NULL
87663 +netxen_nic_hw_read_wx_128M_26858 netxen_nic_hw_read_wx_128M 2 26858 NULL
87664 +edge_tty_recv_18667 edge_tty_recv 4 18667 NULL nohasharray
87665 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 &edge_tty_recv_18667
87666 +btmrvl_gpiogap_write_35053 btmrvl_gpiogap_write 3 35053 NULL
87667 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
87668 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
87669 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
87670 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
87671 +fixup_leb_43256 fixup_leb 3 43256 NULL
87672 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
87673 +ubifs_recover_log_leb_12079 ubifs_recover_log_leb 3 12079 NULL
87674 +ubifs_setxattr_59650 ubifs_setxattr 4 59650 NULL nohasharray
87675 +hidraw_read_59650 hidraw_read 3 59650 &ubifs_setxattr_59650
87676 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
87677 +ca91cx42_alloc_resource_10502 ca91cx42_alloc_resource 2 10502 NULL
87678 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
87679 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
87680 +evtchn_write_43278 evtchn_write 3 43278 NULL
87681 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
87682 +store_ifalias_35088 store_ifalias 4 35088 NULL
87683 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
87684 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
87685 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
87686 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
87687 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
87688 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
87689 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
87690 +get_vm_area_caller_10527 get_vm_area_caller 1 10527 NULL
87691 +capi_write_35104 capi_write 3 35104 NULL nohasharray
87692 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
87693 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
87694 +sys_semtimedop_4486 sys_semtimedop 3 4486 NULL
87695 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
87696 +osd_req_write_sg_50908 osd_req_write_sg 5 50908 NULL
87697 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
87698 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
87699 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
87700 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
87701 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
87702 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 NULL nohasharray
87703 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 &pwr_ps_enter_read_26935
87704 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
87705 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 NULL
87706 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
87707 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
87708 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
87709 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
87710 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
87711 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
87712 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
87713 +do_trimming_26952 do_trimming 3 26952 NULL
87714 +ath6kl_wmi_set_ie_cmd_37260 ath6kl_wmi_set_ie_cmd 6 37260 NULL
87715 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
87716 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
87717 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
87718 +alloc_buf_34532 alloc_buf 1 34532 NULL
87719 +sock_rmalloc_59740 sock_rmalloc 2 59740 NULL nohasharray
87720 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 &sock_rmalloc_59740
87721 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
87722 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
87723 +otp_read_10594 otp_read 2-4-5 10594 NULL
87724 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
87725 +sctp_manip_pkt_59749 sctp_manip_pkt 4 59749 NULL
87726 +icmp_manip_pkt_51560 icmp_manip_pkt 4 51560 NULL
87727 +brcmf_sdbrcm_read_control_22721 brcmf_sdbrcm_read_control 3 22721 NULL
87728 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
87729 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
87730 +roccat_common2_send_2422 roccat_common2_send 4 2422 NULL
87731 +ieee80211_auth_challenge_18810 ieee80211_auth_challenge 3 18810 NULL
87732 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
87733 +cxgb3_get_cpl_reply_skb_10620 cxgb3_get_cpl_reply_skb 2 10620 NULL
87734 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
87735 +venus_remove_59781 venus_remove 4 59781 NULL
87736 +ioremap_nocache_2439 ioremap_nocache 1-2 2439 NULL
87737 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
87738 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
87739 +tty_buffer_find_2443 tty_buffer_find 2 2443 NULL
87740 +xlog_do_recover_59789 xlog_do_recover 3 59789 NULL
87741 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
87742 +rfcomm_tty_write_51603 rfcomm_tty_write 3 51603 NULL
87743 +xenfb_write_43412 xenfb_write 3 43412 NULL
87744 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
87745 +nfs4_alloc_slots_2454 nfs4_alloc_slots 1 2454 NULL nohasharray
87746 +ath6kl_usb_bmi_write_2454 ath6kl_usb_bmi_write 3 2454 &nfs4_alloc_slots_2454
87747 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
87748 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
87749 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL nohasharray
87750 +gdm_wimax_netif_rx_43423 gdm_wimax_netif_rx 3 43423 &__alloc_bootmem_low_43423
87751 +rtllib_wx_set_gen_ie_59808 rtllib_wx_set_gen_ie 3 59808 NULL
87752 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
87753 +udp_manip_pkt_45467 udp_manip_pkt 4 45467 NULL
87754 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
87755 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
87756 +ni65_alloc_mem_10664 ni65_alloc_mem 3 10664 NULL
87757 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
87758 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
87759 +cmd_complete_51629 cmd_complete 6 51629 NULL
87760 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
87761 +btmrvl_txdnldready_read_413 btmrvl_txdnldready_read 3 413 NULL
87762 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
87763 +set_fd_set_35249 set_fd_set 1 35249 NULL
87764 +wiphy_new_2482 wiphy_new 2 2482 NULL
87765 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
87766 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
87767 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
87768 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
87769 +tcp_push_10680 tcp_push 3 10680 NULL
87770 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
87771 +c101_run_37279 c101_run 2 37279 NULL
87772 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
87773 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
87774 +tun_put_user_59849 tun_put_user 4 59849 NULL
87775 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
87776 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
87777 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
87778 +dm_write_2513 dm_write 3 2513 NULL
87779 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
87780 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
87781 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL
87782 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
87783 +ntfs_malloc_nofs_49572 ntfs_malloc_nofs 1 49572 NULL
87784 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
87785 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 NULL nohasharray
87786 +shash_async_setkey_10720 shash_async_setkey 3 10720 &pvr2_ioread_read_10720
87787 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
87788 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
87789 +__iscsi_complete_pdu_10726 __iscsi_complete_pdu 4 10726 NULL
87790 +sfi_sysfs_install_table_51688 sfi_sysfs_install_table 1 51688 NULL
87791 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
87792 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
87793 +__btrfs_direct_write_22273 __btrfs_direct_write 4 22273 NULL
87794 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
87795 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 NULL nohasharray
87796 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 &brcmf_sdio_forensic_read_35311
87797 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
87798 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL
87799 +compat_sys_msgsnd_10738 compat_sys_msgsnd 2 10738 NULL
87800 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
87801 +sel_write_access_51704 sel_write_access 3 51704 NULL
87802 +sys_syslog_10746 sys_syslog 3 10746 NULL
87803 +alloc_one_pg_vec_page_10747 alloc_one_pg_vec_page 1 10747 NULL
87804 +new_bind_ctl_35324 new_bind_ctl 2 35324 NULL
87805 +do_readlink_43518 do_readlink 2 43518 NULL
87806 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
87807 +gem_alloc_skb_51715 gem_alloc_skb 2 51715 NULL
87808 +fallback_on_nodma_alloc_35332 fallback_on_nodma_alloc 2 35332 NULL
87809 +read_file_reset_52310 read_file_reset 3 52310 NULL
87810 +pms_capture_27142 pms_capture 4 27142 NULL
87811 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
87812 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
87813 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
87814 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
87815 +msg_set_51725 msg_set 3 51725 NULL
87816 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
87817 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
87818 +hpi_alloc_control_cache_35351 hpi_alloc_control_cache 1 35351 NULL
87819 +hid_parse_report_51737 hid_parse_report 3 51737 NULL
87820 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
87821 +alc_auto_create_extra_outs_18975 alc_auto_create_extra_outs 2 18975 NULL
87822 +i2400m_net_rx_27170 i2400m_net_rx 5 27170 NULL
87823 +l3_alloc_skb_32289 l3_alloc_skb 1 32289 NULL
87824 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
87825 +ath_rx_init_43564 ath_rx_init 2 43564 NULL
87826 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 NULL nohasharray
87827 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 &il_dbgfs_rxon_flags_read_59950
87828 +sys_bind_10799 sys_bind 3 10799 NULL
87829 +_fc_frame_alloc_43568 _fc_frame_alloc 1 43568 NULL
87830 +nfcwilink_send_bts_cmd_10802 nfcwilink_send_bts_cmd 3 10802 NULL
87831 +ioremap_prot_51764 ioremap_prot 1-2 51764 NULL
87832 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
87833 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 2-3 33204 NULL
87834 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
87835 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
87836 +drm_vblank_init_11362 drm_vblank_init 2 11362 NULL
87837 +send_command_10832 send_command 4 10832 NULL
87838 +lro_gen_skb_2644 lro_gen_skb 6 2644 NULL
87839 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
87840 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
87841 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
87842 +proc_read_43614 proc_read 3 43614 NULL
87843 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
87844 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
87845 +drm_fb_helper_init_19044 drm_fb_helper_init 3-4 19044 NULL
87846 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
87847 +xlbd_reserve_minors_18365 xlbd_reserve_minors 1-2 18365 NULL
87848 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
87849 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
87850 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
87851 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
87852 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
87853 +vmalloc_15464 vmalloc 1 15464 NULL
87854 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
87855 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
87856 +ieee80211_key_alloc_19065 ieee80211_key_alloc 3 19065 NULL
87857 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
87858 +cfpkt_add_trail_27260 cfpkt_add_trail 3 27260 NULL
87859 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
87860 +sys_sched_getaffinity_60033 sys_sched_getaffinity 2 60033 NULL
87861 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 NULL
87862 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
87863 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
87864 +adu_write_30487 adu_write 3 30487 NULL
87865 +ieee80211_if_read_tkip_mic_test_19565 ieee80211_if_read_tkip_mic_test 3 19565 NULL
87866 +get_scq_10897 get_scq 2 10897 NULL
87867 +sys_process_vm_readv_19090 sys_process_vm_readv 3-5 19090 NULL nohasharray
87868 +brcmf_usbdev_qinit_19090 brcmf_usbdev_qinit 2 19090 &sys_process_vm_readv_19090
87869 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
87870 +cgroup_write_string_10900 cgroup_write_string 5 10900 NULL
87871 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
87872 +load_module_60056 load_module 2 60056 NULL nohasharray
87873 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 &load_module_60056
87874 +__videobuf_alloc_cached_12740 __videobuf_alloc_cached 1 12740 NULL
87875 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
87876 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4-2 43679 NULL
87877 +ieee80211_build_probe_req_60064 ieee80211_build_probe_req 8-6 60064 NULL
87878 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
87879 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
87880 +__netdev_alloc_skb_ip_align_55067 __netdev_alloc_skb_ip_align 2 55067 NULL
87881 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
87882 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
87883 +__copy_from_user_10918 __copy_from_user 3 10918 NULL
87884 +user_read_51881 user_read 3 51881 NULL
87885 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
87886 +__xip_file_write_2733 __xip_file_write 4-3 2733 NULL
87887 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL
87888 +ath6kl_wmi_test_cmd_27312 ath6kl_wmi_test_cmd 3 27312 NULL
87889 +max77693_bulk_write_43698 max77693_bulk_write 3 43698 NULL
87890 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
87891 +hidp_send_ctrl_message_43702 hidp_send_ctrl_message 4 43702 NULL
87892 +async_setkey_35521 async_setkey 3 35521 NULL
87893 +set_dev_class_39645 set_dev_class 4 39645 NULL nohasharray
87894 +dm_exception_table_init_39645 dm_exception_table_init 2 39645 &set_dev_class_39645
87895 +cxgb4_pktgl_to_skb_61899 cxgb4_pktgl_to_skb 2 61899 NULL
87896 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
87897 +iio_read_first_n_sw_rb_51911 iio_read_first_n_sw_rb 2 51911 NULL
87898 +hid_report_raw_event_2762 hid_report_raw_event 4 2762 NULL
87899 +add_tty_40055 add_tty 1 40055 NULL nohasharray
87900 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 &add_tty_40055
87901 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
87902 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
87903 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
87904 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
87905 +ttm_bo_kmap_60118 ttm_bo_kmap 3-2 60118 NULL
87906 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
87907 +alloc_context_3194 alloc_context 1 3194 NULL
87908 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
87909 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
87910 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
87911 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
87912 +i915_min_freq_write_10981 i915_min_freq_write 3 10981 NULL
87913 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
87914 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
87915 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
87916 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
87917 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
87918 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
87919 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
87920 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
87921 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
87922 +init_state_60165 init_state 2 60165 NULL
87923 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
87924 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
87925 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3 19214 NULL
87926 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
87927 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
87928 +sg_build_sgat_60179 sg_build_sgat 3 60179 NULL nohasharray
87929 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 &sg_build_sgat_60179
87930 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
87931 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
87932 +calc_hmac_32010 calc_hmac 3 32010 NULL
87933 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
87934 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
87935 +btrfs_copy_from_user_43806 btrfs_copy_from_user 3-1 43806 NULL
87936 +kernel_readv_35617 kernel_readv 3 35617 NULL
87937 +hci_send_cmd_43810 hci_send_cmd 3 43810 NULL
87938 +sys_lgetxattr_45531 sys_lgetxattr 4 45531 NULL
87939 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
87940 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
87941 +nouveau_gpio_create__11048 nouveau_gpio_create_ 4 11048 NULL
87942 +dccp_manip_pkt_476 dccp_manip_pkt 4 476 NULL
87943 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
87944 +set_tap_pfs_60203 set_tap_pfs 3 60203 NULL
87945 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
87946 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
87947 +carl9170_handle_mpdu_11056 carl9170_handle_mpdu 3 11056 NULL
87948 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
87949 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
87950 +vxge_rx_alloc_52024 vxge_rx_alloc 3 52024 NULL
87951 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
87952 +__ip_append_data_16864 __ip_append_data 8-9 16864 NULL
87953 +p54_download_eeprom_43842 p54_download_eeprom 4 43842 NULL
87954 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
87955 +store_debug_level_35652 store_debug_level 3 35652 NULL
87956 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
87957 +read_flush_43851 read_flush 3 43851 NULL
87958 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
87959 +cmm_write_2896 cmm_write 3 2896 NULL
87960 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
87961 +io_mapping_map_wc_19284 io_mapping_map_wc 2 19284 NULL
87962 +tunables_write_59563 tunables_write 3 59563 NULL
87963 +compat_sys_kexec_load_35674 compat_sys_kexec_load 2 35674 NULL
87964 +rtsx_write_cfg_seq_27485 rtsx_write_cfg_seq 5-3 27485 NULL
87965 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
87966 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
87967 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
87968 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
87969 +dm_table_create_35687 dm_table_create 3 35687 NULL
87970 +qib_create_cq_27497 qib_create_cq 2 27497 NULL
87971 +nfc_hci_execute_cmd_43882 nfc_hci_execute_cmd 5 43882 NULL
87972 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
87973 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
87974 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
87975 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL
87976 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
87977 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
87978 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
87979 +debug_read_19322 debug_read 3 19322 NULL
87980 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
87981 +__pskb_pull_tail_60287 __pskb_pull_tail 2 60287 NULL
87982 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
87983 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 NULL
87984 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
87985 +dn_nsp_return_disc_60296 dn_nsp_return_disc 2 60296 NULL
87986 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
87987 +prism2_sta_send_mgmt_43916 prism2_sta_send_mgmt 5 43916 NULL
87988 +mgmt_device_found_14146 mgmt_device_found 10 14146 NULL
87989 +snd_seq_oss_readq_new_14283 snd_seq_oss_readq_new 2 14283 NULL
87990 +doc_probe_23285 doc_probe 1 23285 NULL
87991 +ppp_cp_event_2965 ppp_cp_event 6 2965 NULL
87992 +SendString_43928 SendString 3 43928 NULL
87993 +acpi_os_map_memory_11161 acpi_os_map_memory 1-2 11161 NULL
87994 +ceph_parse_server_name_60318 ceph_parse_server_name 2 60318 NULL
87995 +retry_count_read_52129 retry_count_read 3 52129 NULL
87996 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
87997 +ioat2_alloc_ring_11172 ioat2_alloc_ring 2 11172 NULL
87998 +read_zero_19366 read_zero 3 19366 NULL
87999 +bch_alloc_4593 bch_alloc 1 4593 NULL
88000 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
88001 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
88002 +libipw_alloc_txb_27579 libipw_alloc_txb 1-2-3 27579 NULL
88003 +raid5_resize_63306 raid5_resize 2 63306 NULL
88004 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
88005 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
88006 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
88007 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
88008 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
88009 +depth_write_3021 depth_write 3 3021 NULL
88010 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
88011 +read_file_stations_35795 read_file_stations 3 35795 NULL
88012 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
88013 +tipc_cfg_reply_alloc_27606 tipc_cfg_reply_alloc 1 27606 NULL
88014 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 NULL
88015 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
88016 +ubi_eba_atomic_leb_change_60379 ubi_eba_atomic_leb_change 5 60379 NULL
88017 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 NULL
88018 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
88019 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
88020 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
88021 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
88022 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
88023 +driver_names_read_60399 driver_names_read 3 60399 NULL
88024 +read_flush_procfs_27642 read_flush_procfs 3 27642 NULL
88025 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
88026 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
88027 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
88028 +_alloc_mISDN_skb_52232 _alloc_mISDN_skb 3 52232 NULL
88029 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
88030 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
88031 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
88032 +do_dmabuf_dirty_ldu_52241 do_dmabuf_dirty_ldu 6 52241 NULL
88033 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
88034 +rx_data_60442 rx_data 4 60442 NULL
88035 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
88036 +efivar_create_sysfs_entry_19485 efivar_create_sysfs_entry 2 19485 NULL
88037 +tcf_csum_ipv4_igmp_60446 tcf_csum_ipv4_igmp 3 60446 NULL
88038 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
88039 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
88040 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
88041 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
88042 +__tty_buffer_request_room_27700 __tty_buffer_request_room 2 27700 NULL
88043 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
88044 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
88045 +tcp_mark_head_lost_35895 tcp_mark_head_lost 2 35895 NULL
88046 +skb_realloc_headroom_19516 skb_realloc_headroom 2 19516 NULL
88047 +atm_alloc_charge_19517 atm_alloc_charge 2 19517 NULL nohasharray
88048 +dev_alloc_skb_19517 dev_alloc_skb 1 19517 &atm_alloc_charge_19517
88049 +construct_key_11329 construct_key 3 11329 NULL
88050 +evm_write_key_27715 evm_write_key 3 27715 NULL
88051 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
88052 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
88053 +filldir_55137 filldir 3 55137 NULL
88054 +igmpv3_newpack_35912 igmpv3_newpack 2 35912 NULL
88055 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
88056 +reg_w_buf_27724 reg_w_buf 3 27724 NULL
88057 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
88058 +compat_sys_migrate_pages_3157 compat_sys_migrate_pages 2 3157 NULL
88059 +a4t_cs_init_27734 a4t_cs_init 3 27734 NULL
88060 +sel_write_create_11353 sel_write_create 3 11353 NULL
88061 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
88062 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
88063 +hwflags_read_52318 hwflags_read 3 52318 NULL
88064 +nfc_alloc_send_skb_3167 nfc_alloc_send_skb 4 3167 NULL
88065 +batadv_skb_head_push_11360 batadv_skb_head_push 2 11360 NULL
88066 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
88067 +vmw_gmr_bind_44130 vmw_gmr_bind 3 44130 NULL
88068 +ath_tx_init_60515 ath_tx_init 2 60515 NULL
88069 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
88070 +ntfs_rl_split_52328 ntfs_rl_split 2-4 52328 NULL
88071 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
88072 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
88073 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
88074 +nfsd_read_19568 nfsd_read 5 19568 NULL
88075 +cgroup_read_s64_19570 cgroup_read_s64 5 19570 NULL
88076 +hysdn_sched_rx_60533 hysdn_sched_rx 3 60533 NULL
88077 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
88078 +kcalloc_27770 kcalloc 1-2 27770 NULL
88079 +shmem_pread_slow_3198 shmem_pread_slow 3 3198 NULL
88080 +bm_status_read_19583 bm_status_read 3 19583 NULL
88081 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
88082 +zd_mac_rx_38296 zd_mac_rx 3 38296 NULL
88083 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
88084 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 NULL
88085 +acl_alloc_35979 acl_alloc 1 35979 NULL
88086 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
88087 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
88088 +str_to_user_11411 str_to_user 2 11411 NULL
88089 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
88090 +koneplus_sysfs_write_35993 koneplus_sysfs_write 6 35993 NULL
88091 +trace_options_read_11419 trace_options_read 3 11419 NULL
88092 +ttm_object_file_init_27804 ttm_object_file_init 2 27804 NULL
88093 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
88094 +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
88095 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
88096 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
88097 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
88098 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
88099 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
88100 +console_store_36007 console_store 4 36007 NULL
88101 +bttv_read_11432 bttv_read 3 11432 NULL
88102 +key_key_read_3241 key_key_read 3 3241 NULL
88103 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
88104 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
88105 +__feat_register_sp_64712 __feat_register_sp 6 64712 NULL
88106 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
88107 +check_vendor_extension_3254 check_vendor_extension 1 3254 NULL
88108 +ieee80211_amsdu_to_8023s_15561 ieee80211_amsdu_to_8023s 5 15561 NULL
88109 +sys_listxattr_27833 sys_listxattr 3 27833 NULL
88110 +aac_rx_ioremap_52410 aac_rx_ioremap 2 52410 NULL
88111 +ubi_eba_write_leb_36029 ubi_eba_write_leb 5-6 36029 NULL
88112 +um_idi_write_18293 um_idi_write 3 18293 NULL
88113 +cgroup_file_write_52417 cgroup_file_write 3 52417 NULL
88114 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
88115 +usbvision_rvmalloc_19655 usbvision_rvmalloc 1 19655 NULL
88116 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
88117 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
88118 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
88119 +sys_init_module_36047 sys_init_module 2 36047 NULL
88120 +read_profile_27859 read_profile 3 27859 NULL
88121 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
88122 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL
88123 +enlarge_skb_44248 enlarge_skb 2 44248 NULL nohasharray
88124 +xfs_buf_readahead_map_44248 xfs_buf_readahead_map 3 44248 &enlarge_skb_44248
88125 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
88126 +refill_pool_19477 refill_pool 2 19477 NULL
88127 +ubifs_recover_leb_60639 ubifs_recover_leb 3 60639 NULL
88128 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
88129 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
88130 +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4 11492 NULL
88131 +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
88132 +tcp_sacktag_walk_49703 tcp_sacktag_walk 6 49703 NULL
88133 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
88134 +arvo_sysfs_write_3311 arvo_sysfs_write 6 3311 NULL
88135 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
88136 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
88137 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
88138 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
88139 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
88140 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1-2 52477 NULL
88141 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
88142 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
88143 +venus_symlink_23570 venus_symlink 4-6 23570 NULL
88144 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
88145 +aac_rkt_ioremap_3333 aac_rkt_ioremap 2 3333 NULL
88146 +sctp_make_init_ack_3335 sctp_make_init_ack 4 3335 NULL
88147 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
88148 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
88149 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
88150 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
88151 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
88152 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
88153 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
88154 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
88155 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
88156 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
88157 +ath6kl_usb_ctrl_msg_exchange_33327 ath6kl_usb_ctrl_msg_exchange 4 33327 NULL
88158 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
88159 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
88160 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
88161 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
88162 +vmalloc_exec_36132 vmalloc_exec 1 36132 NULL
88163 +init_data_container_60709 init_data_container 1 60709 NULL
88164 +p9_client_read_19750 p9_client_read 5 19750 NULL
88165 +skb_cow_data_11565 skb_cow_data 2 11565 NULL
88166 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
88167 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
88168 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
88169 +mlx4_init_cmpt_table_11569 mlx4_init_cmpt_table 3 11569 NULL
88170 +iwl_trans_txq_alloc_36147 iwl_trans_txq_alloc 3 36147 NULL
88171 +alloc_vm_area_36149 alloc_vm_area 1 36149 NULL
88172 +ubi_eba_write_leb_st_44343 ubi_eba_write_leb_st 5 44343 NULL
88173 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL
88174 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
88175 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
88176 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
88177 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 NULL nohasharray
88178 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 &nfs_fscache_get_super_cookie_44355
88179 +saa7146_vmalloc_build_pgtable_19780 saa7146_vmalloc_build_pgtable 2 19780 NULL
88180 +send_stream_3397 send_stream 4 3397 NULL
88181 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
88182 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
88183 +ipx_recvmsg_44366 ipx_recvmsg 4 44366 NULL
88184 +hycapi_rx_capipkt_11602 hycapi_rx_capipkt 3 11602 NULL
88185 +msix_map_region_3411 msix_map_region 3 3411 NULL
88186 +sys_kexec_load_14222 sys_kexec_load 2 14222 NULL
88187 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
88188 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
88189 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
88190 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
88191 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
88192 +opticon_write_60775 opticon_write 4 60775 NULL
88193 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
88194 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
88195 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
88196 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
88197 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
88198 +pipe_iov_copy_to_user_3447 pipe_iov_copy_to_user 3 3447 NULL
88199 +vip_read_19832 vip_read 3 19832 NULL
88200 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
88201 +llc_shdlc_alloc_skb_11645 llc_shdlc_alloc_skb 2 11645 NULL
88202 +security_context_to_sid_19839 security_context_to_sid 2 19839 NULL
88203 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
88204 +nfqnl_mangle_36226 nfqnl_mangle 4-2 36226 NULL
88205 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
88206 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
88207 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
88208 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
88209 +alloc_skb_fclone_3467 alloc_skb_fclone 1 3467 NULL
88210 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
88211 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
88212 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2 28053 NULL
88213 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
88214 +llcp_allocate_pdu_19866 llcp_allocate_pdu 3 19866 NULL
88215 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
88216 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
88217 +compat_sys_mbind_36256 compat_sys_mbind 5 36256 NULL
88218 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
88219 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
88220 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
88221 +split_11691 split 2 11691 NULL
88222 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
88223 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 NULL
88224 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
88225 +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 NULL
88226 +__kfifo_alloc_22173 __kfifo_alloc 2-3 22173 NULL
88227 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
88228 +gdth_init_isa_28091 gdth_init_isa 1 28091 NULL
88229 +readahead_tree_block_36285 readahead_tree_block 3 36285 NULL
88230 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL nohasharray
88231 +ieee80211_wx_set_gen_ie_rsl_3521 ieee80211_wx_set_gen_ie_rsl 3 3521 &mem_tx_free_mem_blks_read_3521
88232 +nouveau_cli_create_36293 nouveau_cli_create 3 36293 NULL
88233 +vmw_unlocked_ioctl_19212 vmw_unlocked_ioctl 2 19212 NULL
88234 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
88235 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
88236 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
88237 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
88238 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
88239 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 NULL
88240 +tcf_csum_ipv6_icmp_11738 tcf_csum_ipv6_icmp 4 11738 NULL
88241 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
88242 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
88243 +spidev_write_44510 spidev_write 3 44510 NULL
88244 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
88245 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
88246 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
88247 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL
88248 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
88249 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
88250 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
88251 +kone_receive_4690 kone_receive 4 4690 NULL
88252 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
88253 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
88254 +evtchn_read_3569 evtchn_read 3 3569 NULL
88255 +video_read_28148 video_read 3 28148 NULL
88256 +compat_sys_setsockopt_3326 compat_sys_setsockopt 5 3326 NULL
88257 +sys_msgsnd_44537 sys_msgsnd 3 44537 NULL nohasharray
88258 +comm_write_44537 comm_write 3 44537 &sys_msgsnd_44537
88259 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
88260 +ax25_send_frame_19964 ax25_send_frame 2 19964 NULL
88261 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
88262 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
88263 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
88264 +vc_resize_3585 vc_resize 2-3 3585 NULL
88265 +gluebi_write_27905 gluebi_write 3 27905 NULL
88266 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
88267 +c4iw_reject_cr_28174 c4iw_reject_cr 3 28174 NULL
88268 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
88269 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
88270 +compat_sys_semtimedop_3606 compat_sys_semtimedop 3 3606 NULL
88271 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
88272 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
88273 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
88274 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
88275 +pti_char_write_60960 pti_char_write 3 60960 NULL
88276 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
88277 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
88278 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
88279 +read_vbt_r10_60679 read_vbt_r10 1 60679 NULL
88280 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
88281 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
88282 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL nohasharray
88283 +fwnet_pd_new_39947 fwnet_pd_new 4 39947 &error_error_frame_read_39947
88284 +snd_pcm_alloc_vmalloc_buffer_44595 snd_pcm_alloc_vmalloc_buffer 2 44595 NULL
88285 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
88286 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
88287 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
88288 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
88289 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
88290 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
88291 +cm_copy_private_data_3649 cm_copy_private_data 2 3649 NULL
88292 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
88293 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 NULL nohasharray
88294 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 &ieee80211_if_read_auto_open_plinks_38268
88295 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL
88296 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
88297 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
88298 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
88299 +cfpkt_add_body_44630 cfpkt_add_body 3 44630 NULL
88300 +nf_nat_sdp_media_11863 nf_nat_sdp_media 9 11863 NULL
88301 +alloc_extent_buffer_52824 alloc_extent_buffer 3 52824 NULL
88302 +skb_cow_head_52495 skb_cow_head 2 52495 NULL
88303 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
88304 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
88305 +alloc_ieee80211_20063 alloc_ieee80211 1 20063 NULL
88306 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
88307 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
88308 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
88309 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
88310 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
88311 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
88312 +btmrvl_psmode_write_3703 btmrvl_psmode_write 3 3703 NULL
88313 +symtab_init_61050 symtab_init 2 61050 NULL
88314 +team_options_register_20091 team_options_register 3 20091 NULL
88315 +videobuf_pages_to_sg_3708 videobuf_pages_to_sg 2 3708 NULL
88316 +mon_bin_get_event_52863 mon_bin_get_event 4 52863 NULL
88317 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
88318 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
88319 +mpi_resize_44674 mpi_resize 2 44674 NULL
88320 +ip6_append_data_36490 ip6_append_data 4-5 36490 NULL nohasharray
88321 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 &ip6_append_data_36490
88322 +kmalloc_slab_11917 kmalloc_slab 1 11917 NULL
88323 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
88324 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
88325 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
88326 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
88327 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
88328 +xfs_trans_read_buf_map_37487 xfs_trans_read_buf_map 5 37487 NULL
88329 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
88330 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
88331 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
88332 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL
88333 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
88334 +dccp_feat_clone_sp_val_11942 dccp_feat_clone_sp_val 3 11942 NULL
88335 +pms_read_53873 pms_read 3 53873 NULL
88336 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
88337 +get_derived_key_61100 get_derived_key 4 61100 NULL
88338 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
88339 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
88340 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
88341 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
88342 +dm_read_15674 dm_read 3 15674 NULL
88343 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
88344 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
88345 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
88346 +kone_send_63435 kone_send 4 63435 NULL
88347 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
88348 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
88349 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
88350 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
88351 +__kfifo_to_user_36555 __kfifo_to_user 3 36555 NULL nohasharray
88352 +macvtap_do_read_36555 macvtap_do_read 4 36555 &__kfifo_to_user_36555
88353 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
88354 +create_trace_probe_20175 create_trace_probe 1 20175 NULL
88355 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
88356 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
88357 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
88358 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
88359 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
88360 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
88361 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
88362 +send_packet_52960 send_packet 4 52960 NULL
88363 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
88364 +ssb_bus_scan_36578 ssb_bus_scan 2 36578 NULL
88365 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
88366 +tipc_port_reject_sections_55229 tipc_port_reject_sections 5 55229 NULL
88367 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
88368 +set_bypass_pfs_28395 set_bypass_pfs 3 28395 NULL
88369 +put_cmsg_36589 put_cmsg 4 36589 NULL
88370 +__vmalloc_61168 __vmalloc 1 61168 NULL
88371 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
88372 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
88373 +read_file_tx_chainmask_3829 read_file_tx_chainmask 3 3829 NULL
88374 +pcnet32_realloc_rx_ring_36598 pcnet32_realloc_rx_ring 3 36598 NULL
88375 +event_oom_late_read_61175 event_oom_late_read 3 61175 NULL nohasharray
88376 +pair_device_61175 pair_device 4 61175 &event_oom_late_read_61175
88377 +sys_lsetxattr_61177 sys_lsetxattr 4 61177 NULL
88378 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
88379 +nfs4_alloc_pages_48426 nfs4_alloc_pages 1 48426 NULL
88380 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
88381 +batadv_check_management_packet_52993 batadv_check_management_packet 3 52993 NULL
88382 +tpci200_slot_map_space_3848 tpci200_slot_map_space 2 3848 NULL
88383 +regmap_bulk_write_59049 regmap_bulk_write 4 59049 NULL
88384 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
88385 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
88386 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
88387 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
88388 +cfpkt_append_61206 cfpkt_append 3 61206 NULL
88389 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
88390 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
88391 +get_fd_set_3866 get_fd_set 1 3866 NULL
88392 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
88393 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
88394 +unlink_queued_645 unlink_queued 3-4 645 NULL
88395 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
88396 +sisusb_write_44834 sisusb_write 3 44834 NULL
88397 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
88398 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
88399 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
88400 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
88401 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
88402 +uea_send_modem_cmd_3888 uea_send_modem_cmd 3 3888 NULL
88403 +h5_prepare_pkt_12085 h5_prepare_pkt 4 12085 NULL
88404 +nvram_write_3894 nvram_write 3 3894 NULL
88405 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
88406 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
88407 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
88408 +vcs_write_3910 vcs_write 3 3910 NULL
88409 +sctp_make_abort_violation_27959 sctp_make_abort_violation 4 27959 NULL
88410 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
88411 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
88412 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL
88413 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
88414 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
88415 +do_tty_write_44896 do_tty_write 5 44896 NULL
88416 +set_powered_12129 set_powered 4 12129 NULL
88417 +qib_resize_cq_53090 qib_resize_cq 2 53090 NULL
88418 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
88419 +nfs_writedata_alloc_12133 nfs_writedata_alloc 2 12133 NULL
88420 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
88421 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
88422 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
88423 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
88424 +vmw_fifo_reserve_12141 vmw_fifo_reserve 2 12141 NULL
88425 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
88426 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
88427 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
88428 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
88429 +capinc_tty_write_28539 capinc_tty_write 3 28539 NULL
88430 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
88431 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL
88432 +line6_dumpreq_initbuf_53123 line6_dumpreq_initbuf 3 53123 NULL
88433 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4 36740 NULL
88434 +gather_array_56641 gather_array 3 56641 NULL
88435 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
88436 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
88437 +dma_memcpy_to_iovec_12173 dma_memcpy_to_iovec 5 12173 NULL
88438 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
88439 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
88440 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
88441 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
88442 +regcache_rbtree_insert_to_block_58009 regcache_rbtree_insert_to_block 5 58009 NULL
88443 +do_add_counters_3992 do_add_counters 3 3992 NULL
88444 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL
88445 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
88446 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
88447 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
88448 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
88449 +ip4ip6_err_36772 ip4ip6_err 5 36772 NULL
88450 +mei_write_4005 mei_write 3 4005 NULL
88451 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
88452 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
88453 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 NULL
88454 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
88455 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
88456 +receive_copy_12216 receive_copy 3 12216 NULL
88457 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 NULL
88458 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
88459 +bcsp_prepare_pkt_12961 bcsp_prepare_pkt 3 12961 NULL
88460 +ftdi_process_packet_45005 ftdi_process_packet 5 45005 NULL
88461 +change_xattr_61390 change_xattr 5 61390 NULL
88462 +find_skb_20431 find_skb 2 20431 NULL
88463 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
88464 +fmc_send_cmd_20435 fmc_send_cmd 5 20435 NULL
88465 +tcp_fragment_20436 tcp_fragment 3 20436 NULL
88466 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
88467 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
88468 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
88469 +sys_sethostname_42962 sys_sethostname 2 42962 NULL
88470 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
88471 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
88472 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
88473 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
88474 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
88475 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
88476 +sctp_make_asconf_4078 sctp_make_asconf 3 4078 NULL
88477 +vhci_get_user_45039 vhci_get_user 3 45039 NULL
88478 +ip_vs_icmp_xmit_v6_20464 ip_vs_icmp_xmit_v6 4 20464 NULL
88479 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
88480 +read_buf_20469 read_buf 2 20469 NULL
88481 +cm_write_36858 cm_write 3 36858 NULL
88482 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
88483 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
88484 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 NULL
88485 +sel_write_user_45060 sel_write_user 3 45060 NULL
88486 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 NULL
88487 +__dev_alloc_skb_28681 __dev_alloc_skb 1 28681 NULL
88488 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
88489 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
88490 +fast_user_write_20494 fast_user_write 5 20494 NULL
88491 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
88492 +sctp_make_fwdtsn_53265 sctp_make_fwdtsn 3 53265 NULL
88493 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
88494 +hidraw_report_event_20503 hidraw_report_event 3 20503 NULL
88495 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
88496 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
88497 +lirc_buffer_init_53282 lirc_buffer_init 3-2 53282 NULL
88498 +tipc_msg_build_12326 tipc_msg_build 4 12326 NULL
88499 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
88500 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
88501 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
88502 +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
88503 +osst_read_40237 osst_read 3 40237 NULL
88504 +tm6000_read_4151 tm6000_read 3 4151 NULL
88505 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
88506 +usbdev_read_45114 usbdev_read 3 45114 NULL
88507 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
88508 +spi_execute_28736 spi_execute 5 28736 NULL
88509 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
88510 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
88511 +get_alua_req_4166 get_alua_req 3 4166 NULL
88512 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
88513 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
88514 +venus_create_20555 venus_create 4 20555 NULL
88515 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
88516 +batadv_interface_rx_53325 batadv_interface_rx 4 53325 NULL
88517 +receive_packet_12367 receive_packet 2 12367 NULL
88518 +squashfs_cache_init_41656 squashfs_cache_init 2 41656 NULL
88519 +mem_write_22232 mem_write 3 22232 NULL
88520 +read_file_bool_4180 read_file_bool 3 4180 NULL
88521 +send_to_tty_45141 send_to_tty 3 45141 NULL
88522 +fops_read_40672 fops_read 3 40672 NULL
88523 +cxio_init_resource_fifo_28764 cxio_init_resource_fifo 3 28764 NULL
88524 +write_leb_36957 write_leb 5 36957 NULL
88525 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
88526 +device_write_45156 device_write 3 45156 NULL
88527 +i915_max_freq_read_20581 i915_max_freq_read 3 20581 NULL
88528 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
88529 +sparse_early_mem_maps_alloc_node_36971 sparse_early_mem_maps_alloc_node 4 36971 NULL
88530 +batadv_tt_append_diff_20588 batadv_tt_append_diff 4 20588 NULL
88531 +dvb_net_sec_callback_28786 dvb_net_sec_callback 2 28786 NULL
88532 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
88533 +isp1760_register_628 isp1760_register 1-2 628 NULL
88534 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
88535 +lirc_write_20604 lirc_write 3 20604 NULL
88536 +sel_write_member_28800 sel_write_member 3 28800 NULL
88537 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
88538 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
88539 +cgroup_file_read_28804 cgroup_file_read 3 28804 NULL
88540 +sys_msgrcv_959 sys_msgrcv 3 959 NULL
88541 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL
88542 +pskb_network_may_pull_35336 pskb_network_may_pull 2 35336 NULL
88543 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
88544 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
88545 +setxattr_37006 setxattr 4 37006 NULL
88546 +add_child_45201 add_child 4 45201 NULL
88547 +seq_open_private_61589 seq_open_private 3 61589 NULL
88548 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
88549 +__get_vm_area_61599 __get_vm_area 1 61599 NULL
88550 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
88551 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
88552 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3 20646 NULL
88553 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
88554 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
88555 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
88556 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
88557 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
88558 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 NULL
88559 +ieee80211_rx_bss_info_61630 ieee80211_rx_bss_info 3 61630 NULL
88560 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
88561 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
88562 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
88563 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
88564 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
88565 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 4 20682 NULL
88566 +get_packet_pg_28023 get_packet_pg 4 28023 NULL
88567 +rtllib_auth_challenge_12493 rtllib_auth_challenge 3 12493 NULL
88568 +acpi_tb_parse_root_table_53455 acpi_tb_parse_root_table 1 53455 NULL
88569 +resize_stripes_61650 resize_stripes 2 61650 NULL
88570 +n2_run_53459 n2_run 3 53459 NULL
88571 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
88572 +parse_command_37079 parse_command 2 37079 NULL
88573 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
88574 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
88575 +ttm_page_pool_free_61661 ttm_page_pool_free 2 61661 NULL
88576 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
88577 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
88578 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
88579 +insert_one_name_61668 insert_one_name 7 61668 NULL
88580 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
88581 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
88582 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
88583 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
88584 +lock_loop_61681 lock_loop 1 61681 NULL
88585 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
88586 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
88587 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
88588 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
88589 +vring_add_indirect_20737 vring_add_indirect 3-4 20737 NULL
88590 +push_rx_28939 push_rx 3 28939 NULL
88591 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 3 4365 NULL
88592 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
88593 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
88594 +sys_setdomainname_4373 sys_setdomainname 2 4373 NULL
88595 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
88596 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
88597 +nouveau_dmaobj_create__61730 nouveau_dmaobj_create_ 6 61730 NULL
88598 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3 28963 NULL
88599 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
88600 +aac_srcv_ioremap_6659 aac_srcv_ioremap 2 6659 NULL
88601 +ubi_leb_change_10289 ubi_leb_change 4 10289 NULL
88602 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
88603 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
88604 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
88605 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
88606 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
88607 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL
88608 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
88609 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
88610 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 NULL
88611 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
88612 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
88613 +tstats_write_60432 tstats_write 3 60432 NULL nohasharray
88614 +kmalloc_60432 kmalloc 1 60432 &tstats_write_60432
88615 +bin_uuid_28999 bin_uuid 3 28999 NULL
88616 +sys_sendto_20809 sys_sendto 6 20809 NULL
88617 +alloc_page_cgroup_2919 alloc_page_cgroup 1 2919 NULL
88618 +set_registers_53582 set_registers 3 53582 NULL
88619 +fc_fcp_frame_alloc_12624 fc_fcp_frame_alloc 2 12624 NULL
88620 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
88621 +lane2_associate_req_45398 lane2_associate_req 4 45398 NULL
88622 +tcf_csum_ipv4_udp_30777 tcf_csum_ipv4_udp 4 30777 NULL
88623 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
88624 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2 37213 NULL
88625 +keymap_store_45406 keymap_store 4 45406 NULL
88626 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
88627 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
88628 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
88629 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
88630 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
88631 +xz_dec_init_29029 xz_dec_init 2 29029 NULL
88632 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
88633 +tcp_dma_try_early_copy_4457 tcp_dma_try_early_copy 3 4457 NULL
88634 +__do_replace_37227 __do_replace 5 37227 NULL
88635 +dn_alloc_send_pskb_4465 dn_alloc_send_pskb 2 4465 NULL
88636 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
88637 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
88638 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
88639 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
88640 +tso_fragment_29050 tso_fragment 3 29050 NULL
88641 +__alloc_pred_stack_26687 __alloc_pred_stack 2 26687 NULL
88642 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
88643 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
88644 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 NULL
88645 +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
88646 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
88647 +__iio_allocate_sw_ring_buffer_4843 __iio_allocate_sw_ring_buffer 3 4843 NULL
88648 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
88649 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
88650 +intel_render_ring_init_dri_45446 intel_render_ring_init_dri 2-3 45446 NULL
88651 +udp_sendmsg_4492 udp_sendmsg 4 4492 NULL
88652 +ieee80211_probereq_get_29069 ieee80211_probereq_get 4-6 29069 NULL
88653 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
88654 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
88655 +_alloc_cdb_cont_23609 _alloc_cdb_cont 2 23609 NULL
88656 +set_link_security_4502 set_link_security 4 4502 NULL
88657 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
88658 +l1oip_socket_parse_4507 l1oip_socket_parse 4 4507 NULL
88659 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
88660 +fs_path_prepare_for_add_61854 fs_path_prepare_for_add 2 61854 NULL
88661 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
88662 +srp_target_alloc_37288 srp_target_alloc 3 37288 NULL
88663 +mmio_read_40348 mmio_read 4 40348 NULL
88664 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
88665 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
88666 +compat_sys_readv_20911 compat_sys_readv 3 20911 NULL
88667 +ivtv_write_12721 ivtv_write 3 12721 NULL
88668 +fuse_fill_write_pages_53682 fuse_fill_write_pages 4 53682 NULL
88669 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
88670 +sys_llistxattr_4532 sys_llistxattr 3 4532 NULL
88671 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
88672 +da9052_group_write_4534 da9052_group_write 3 4534 NULL
88673 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
88674 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
88675 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
88676 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
88677 +videobuf_vmalloc_to_sg_4548 videobuf_vmalloc_to_sg 2 4548 NULL
88678 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
88679 +ieee80211_rtl_auth_challenge_61897 ieee80211_rtl_auth_challenge 3 61897 NULL
88680 +send_msg_37323 send_msg 4 37323 NULL
88681 +brcmf_sdbrcm_membytes_37324 brcmf_sdbrcm_membytes 3-5 37324 NULL
88682 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL
88683 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
88684 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
88685 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
88686 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
88687 +virtqueue_add_buf_59470 virtqueue_add_buf 3-4 59470 NULL
88688 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
88689 +dsp_buffer_alloc_11684 dsp_buffer_alloc 2 11684 NULL
88690 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
88691 +reshape_ring_29147 reshape_ring 2 29147 NULL
88692 +cgroup_read_u64_45532 cgroup_read_u64 5 45532 NULL
88693 +au0828_init_isoc_61917 au0828_init_isoc 3-2 61917 NULL
88694 +copy_macs_45534 copy_macs 4 45534 NULL
88695 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
88696 +listxattr_12769 listxattr 3 12769 NULL
88697 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
88698 +wdm_write_53735 wdm_write 3 53735 NULL
88699 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
88700 +send_bulk_static_data_61932 send_bulk_static_data 3 61932 NULL
88701 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
88702 +mempool_create_29437 mempool_create 1 29437 NULL
88703 +platform_create_bundle_12785 platform_create_bundle 4-6 12785 NULL
88704 +brcmf_tx_frame_20978 brcmf_tx_frame 3 20978 NULL
88705 +sock_alloc_send_pskb_21246 sock_alloc_send_pskb 2 21246 NULL
88706 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
88707 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
88708 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
88709 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
88710 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 NULL
88711 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
88712 +mgmt_event_12810 mgmt_event 4 12810 NULL
88713 +ntfs_rl_realloc_nofail_32173 ntfs_rl_realloc_nofail 3 32173 NULL
88714 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
88715 +ipath_create_cq_45586 ipath_create_cq 2 45586 NULL
88716 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL nohasharray
88717 +alloc_group_attrs_29203 alloc_group_attrs 3 29203 &wusb_prf_256_29203
88718 +comedi_alloc_subdevices_29207 comedi_alloc_subdevices 2 29207 NULL
88719 +rdma_set_ib_paths_45592 rdma_set_ib_paths 3 45592 NULL
88720 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
88721 +rds_iw_inc_copy_to_user_29214 rds_iw_inc_copy_to_user 3 29214 NULL
88722 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
88723 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
88724 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
88725 +virtnet_send_command_61993 virtnet_send_command 5-6 61993 NULL
88726 +sys_getxattr_37418 sys_getxattr 4 37418 NULL
88727 +regmap_raw_write_53803 regmap_raw_write 4 53803 NULL
88728 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
88729 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
88730 +t4vf_pktgl_to_skb_39005 t4vf_pktgl_to_skb 2 39005 NULL
88731 +audit_log_n_hex_45617 audit_log_n_hex 3 45617 NULL
88732 +devm_ioremap_29235 devm_ioremap 2-3 29235 NULL
88733 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
88734 +recover_peb_29238 recover_peb 6-7 29238 NULL
88735 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
88736 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
88737 +i915_gem_execbuffer_relocate_slow_25355 i915_gem_execbuffer_relocate_slow 7 25355 NULL
88738 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
88739 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
88740 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
88741 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
88742 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
88743 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
88744 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
88745 +ppp_tx_cp_62044 ppp_tx_cp 5 62044 NULL
88746 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
88747 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
88748 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
88749 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
88750 +do_pselect_62061 do_pselect 1 62061 NULL
88751 +btmrvl_gpiogap_read_4718 btmrvl_gpiogap_read 3 4718 NULL
88752 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
88753 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
88754 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
88755 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
88756 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL
88757 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
88758 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
88759 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
88760 +sg_read_25799 sg_read 3 25799 NULL
88761 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
88762 +ci_ll_init_12930 ci_ll_init 3 12930 NULL
88763 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 NULL
88764 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
88765 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
88766 +vmalloc_32_user_37519 vmalloc_32_user 1 37519 NULL
88767 +fd_do_writev_29329 fd_do_writev 3 29329 NULL
88768 +hugetlb_cgroup_read_49259 hugetlb_cgroup_read 5 49259 NULL
88769 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
88770 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
88771 +dvb_ca_en50221_init_45718 dvb_ca_en50221_init 4 45718 NULL
88772 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
88773 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
88774 +new_skb_21148 new_skb 1 21148 NULL
88775 +ath6kl_mgmt_tx_21153 ath6kl_mgmt_tx 9 21153 NULL
88776 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
88777 +bm_status_write_12964 bm_status_write 3 12964 NULL
88778 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
88779 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
88780 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
88781 +ip6_ufo_append_data_4780 ip6_ufo_append_data 5-6-7 4780 NULL
88782 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL nohasharray
88783 +nf_nat_mangle_tcp_packet_37551 nf_nat_mangle_tcp_packet 6-8 37551 &sep_create_dcb_dmatables_context_37551
88784 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
88785 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3 45748 NULL nohasharray
88786 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
88787 +qib_diag_write_62133 qib_diag_write 3 62133 NULL
88788 +gnttab_expand_15817 gnttab_expand 1 15817 NULL
88789 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
88790 +sctp_make_chunk_12986 sctp_make_chunk 4 12986 NULL
88791 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
88792 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
88793 +mthca_setup_cmd_doorbells_53954 mthca_setup_cmd_doorbells 2 53954 NULL
88794 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
88795 +video_usercopy_62151 video_usercopy 2 62151 NULL
88796 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
88797 +repair_io_failure_4815 repair_io_failure 4 4815 NULL
88798 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
88799 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
88800 +bnx2i_send_nl_mesg_53353 bnx2i_send_nl_mesg 4 53353 NULL
88801 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
88802 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
88803 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
88804 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 NULL
88805 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
88806 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
88807 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
88808 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
88809 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
88810 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
88811 +input_ff_create_21240 input_ff_create 2 21240 NULL
88812 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
88813 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
88814 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL
88815 +amthi_read_45831 amthi_read 4 45831 NULL
88816 +cmpk_message_handle_tx_54024 cmpk_message_handle_tx 4 54024 NULL
88817 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
88818 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
88819 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
88820 +sys_ipc_4889 sys_ipc 3 4889 NULL
88821 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
88822 +smp_build_cmd_45853 smp_build_cmd 3 45853 NULL
88823 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
88824 +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
88825 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
88826 +do_register_entry_29478 do_register_entry 4 29478 NULL
88827 +isdn_write_45863 isdn_write 3 45863 NULL
88828 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
88829 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
88830 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
88831 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
88832 +vmw_gmr2_bind_21305 vmw_gmr2_bind 3 21305 NULL
88833 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
88834 +_malloc_54077 _malloc 1 54077 NULL
88835 +add_res_range_21310 add_res_range 4 21310 NULL
88836 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
88837 +sys_process_vm_writev_4928 sys_process_vm_writev 3-5 4928 NULL
88838 +ntfs_rl_insert_4931 ntfs_rl_insert 2-4 4931 NULL
88839 +ip_make_skb_13129 ip_make_skb 5-6 13129 NULL
88840 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
88841 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
88842 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
88843 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL
88844 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
88845 +create_xattr_54106 create_xattr 5 54106 NULL
88846 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
88847 +ep_write_59008 ep_write 3 59008 NULL
88848 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
88849 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
88850 +devm_kzalloc_4966 devm_kzalloc 2 4966 NULL
88851 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
88852 +udf_sb_alloc_partition_maps_62313 udf_sb_alloc_partition_maps 2 62313 NULL
88853 +alloc_mr_45935 alloc_mr 1 45935 NULL
88854 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
88855 +isku_receive_54130 isku_receive 4 54130 NULL
88856 +hfcpci_empty_bfifo_62323 hfcpci_empty_bfifo 4 62323 NULL
88857 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
88858 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
88859 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
88860 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
88861 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
88862 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
88863 +i915_max_freq_write_11350 i915_max_freq_write 3 11350 NULL
88864 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
88865 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
88866 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
88867 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
88868 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
88869 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
88870 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
88871 +alloc_ldt_21972 alloc_ldt 2 21972 NULL
88872 +ipath_resize_cq_712 ipath_resize_cq 2 712 NULL
88873 +comedi_read_13199 comedi_read 3 13199 NULL
88874 +flash_write_62354 flash_write 3 62354 NULL
88875 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
88876 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
88877 +i2400m_zrealloc_2x_54166 i2400m_zrealloc_2x 3 54166 NULL nohasharray
88878 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 &i2400m_zrealloc_2x_54166
88879 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
88880 +proc_file_read_53905 proc_file_read 3 53905 NULL
88881 +mtd_device_parse_register_5024 mtd_device_parse_register 5 5024 NULL
88882 +acpi_tb_install_table_12988 acpi_tb_install_table 1 12988 NULL
88883 +set_wd_exp_mode_pfs_62372 set_wd_exp_mode_pfs 3 62372 NULL
88884 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
88885 +acpi_os_read_memory_54186 acpi_os_read_memory 1-3 54186 NULL
88886 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
88887 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
88888 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
88889 +cru_detect_11272 cru_detect 1 11272 NULL
88890 +altera_irscan_62396 altera_irscan 2 62396 NULL
88891 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
88892 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
88893 +fw_download_code_13249 fw_download_code 3 13249 NULL
88894 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
88895 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
88896 +set_ssp_62411 set_ssp 4 62411 NULL
88897 +nfc_hci_send_event_21452 nfc_hci_send_event 5 21452 NULL
88898 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
88899 +get_free_entries_46030 get_free_entries 1 46030 NULL
88900 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
88901 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL
88902 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
88903 +carl9170_rx_13272 carl9170_rx 3 13272 NULL
88904 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
88905 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 NULL
88906 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
88907 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3 5091 NULL
88908 +netdev_alloc_skb_62437 netdev_alloc_skb 2 62437 NULL
88909 +dma_memcpy_pg_to_iovec_1725 dma_memcpy_pg_to_iovec 6 1725 NULL
88910 +platform_device_add_resources_13289 platform_device_add_resources 3 13289 NULL
88911 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
88912 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
88913 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
88914 +e1000_check_copybreak_62448 e1000_check_copybreak 3 62448 NULL
88915 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
88916 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
88917 +wusb_prf_54261 wusb_prf 7 54261 NULL nohasharray
88918 +audio_write_54261 audio_write 4 54261 &wusb_prf_54261
88919 +sys_setxattr_37880 sys_setxattr 4 37880 NULL
88920 +dvb_net_sec_37884 dvb_net_sec 3 37884 NULL
88921 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
88922 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
88923 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
88924 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
88925 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL nohasharray
88926 +xz_dec_lzma2_create_36353 xz_dec_lzma2_create 2 36353 &v9fs_file_readn_36353
88927 +vfio_config_do_rw_46091 vfio_config_do_rw 3 46091 NULL
88928 +dma_skb_copy_datagram_iovec_21516 dma_skb_copy_datagram_iovec 3-5 21516 NULL
88929 +ata_host_alloc_46094 ata_host_alloc 2 46094 NULL
88930 +probes_write_29711 probes_write 3 29711 NULL
88931 +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
88932 +us122l_ctl_msg_13330 us122l_ctl_msg 8 13330 NULL
88933 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
88934 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
88935 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
88936 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
88937 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 NULL
88938 +tipc_link_send_sections_fast_37920 tipc_link_send_sections_fast 4 37920 NULL
88939 +mlx4_en_create_rx_ring_62498 mlx4_en_create_rx_ring 3 62498 NULL
88940 +emi62_writememory_29731 emi62_writememory 4 29731 NULL
88941 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
88942 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
88943 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 NULL
88944 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
88945 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
88946 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
88947 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
88948 +pn_raw_send_54330 pn_raw_send 2 54330 NULL
88949 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
88950 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
88951 +sfi_map_memory_5183 sfi_map_memory 1-2 5183 NULL
88952 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
88953 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
88954 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
88955 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
88956 +ddp_clear_map_46152 ddp_clear_map 4 46152 NULL
88957 +cxio_hal_init_resource_29771 cxio_hal_init_resource 2-6-7 29771 NULL nohasharray
88958 +ip_vs_conn_fill_param_sync_29771 ip_vs_conn_fill_param_sync 6 29771 &cxio_hal_init_resource_29771
88959 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
88960 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
88961 +_osd_realloc_seg_54352 _osd_realloc_seg 3 54352 NULL
88962 +pipe_set_size_5204 pipe_set_size 2 5204 NULL
88963 +tcf_hash_create_54360 tcf_hash_create 4 54360 NULL
88964 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
88965 +isdn_read_50021 isdn_read 3 50021 NULL
88966 +vfs_readlink_54368 vfs_readlink 3 54368 NULL
88967 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
88968 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
88969 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
88970 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
88971 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
88972 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
88973 +ssb_ioremap_5228 ssb_ioremap 2 5228 NULL
88974 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
88975 +xlog_do_recovery_pass_21618 xlog_do_recovery_pass 3 21618 NULL
88976 +isdn_ppp_skb_push_5236 isdn_ppp_skb_push 2 5236 NULL
88977 +get_subdir_62581 get_subdir 3 62581 NULL
88978 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
88979 +sctp_abort_pkt_new_5241 sctp_abort_pkt_new 6 5241 NULL
88980 +vfs_readv_38011 vfs_readv 3 38011 NULL
88981 +keyring_read_13438 keyring_read 3 13438 NULL
88982 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL nohasharray
88983 +set_tap_pwup_pfs_13440 set_tap_pwup_pfs 3 13440 &sctp_setsockopt_peer_primary_addr_13440
88984 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
88985 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
88986 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
88987 +packet_alloc_skb_62602 packet_alloc_skb 2-5-4 62602 NULL
88988 +prism2_send_mgmt_62605 prism2_send_mgmt 4 62605 NULL nohasharray
88989 +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 &prism2_send_mgmt_62605
88990 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
88991 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
88992 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
88993 +ftrace_write_29551 ftrace_write 3 29551 NULL
88994 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL
88995 +iscsi_post_host_event_13473 iscsi_post_host_event 4 13473 NULL
88996 +ems_pcmcia_add_card_62627 ems_pcmcia_add_card 2 62627 NULL
88997 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
88998 +dev_write_7708 dev_write 3 7708 NULL
88999 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
89000 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
89001 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
89002 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
89003 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
89004 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
89005 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
89006 +nf_nat_ftp_46265 nf_nat_ftp 6 46265 NULL
89007 +nfc_targets_found_29886 nfc_targets_found 3 29886 NULL
89008 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
89009 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
89010 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
89011 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
89012 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
89013 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
89014 +bm_init_13529 bm_init 2 13529 NULL
89015 +check586_29914 check586 2 29914 NULL
89016 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
89017 +pep_alloc_skb_46303 pep_alloc_skb 3 46303 NULL
89018 +reiserfs_allocate_list_bitmaps_21732 reiserfs_allocate_list_bitmaps 3 21732 NULL
89019 +ioremap_wc_62695 ioremap_wc 1-2 62695 NULL
89020 +pg_read_17276 pg_read 3 17276 NULL
89021 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
89022 +ep0_read_38095 ep0_read 3 38095 NULL
89023 +batadv_iv_ogm_queue_add_46319 batadv_iv_ogm_queue_add 3 46319 NULL
89024 +__nf_nat_mangle_tcp_packet_21744 __nf_nat_mangle_tcp_packet 8-6 21744 NULL
89025 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
89026 +cgroup_write_X64_54514 cgroup_write_X64 5 54514 NULL
89027 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
89028 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
89029 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
89030 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
89031 +l2down_create_21755 l2down_create 4 21755 NULL
89032 +alloc_tio_13564 alloc_tio 3 13564 NULL
89033 +viacam_read_54526 viacam_read 3 54526 NULL
89034 +btrfs_mksubvol_58240 btrfs_mksubvol 3 58240 NULL
89035 +tunables_read_36385 tunables_read 3 36385 NULL
89036 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
89037 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
89038 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
89039 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 3-4 38153 NULL
89040 +setsockopt_54539 setsockopt 5 54539 NULL
89041 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
89042 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
89043 +tty_register_device_4544 tty_register_device 2 4544 NULL
89044 +cache_write_13589 cache_write 3 13589 NULL
89045 +mpt_lan_receive_post_turbo_13592 mpt_lan_receive_post_turbo 2 13592 NULL
89046 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
89047 +key_replays_read_62746 key_replays_read 3 62746 NULL
89048 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
89049 +aac_sa_ioremap_13596 aac_sa_ioremap 2 13596 NULL nohasharray
89050 +irias_new_octseq_value_13596 irias_new_octseq_value 2 13596 &aac_sa_ioremap_13596
89051 +mwifiex_usb_submit_rx_urb_54558 mwifiex_usb_submit_rx_urb 2 54558 NULL
89052 +irias_add_octseq_attrib_29983 irias_add_octseq_attrib 4 29983 NULL
89053 +cdev_add_38176 cdev_add 2-3 38176 NULL
89054 +brcmf_sdcard_recv_buf_38179 brcmf_sdcard_recv_buf 6 38179 NULL
89055 +__ioremap_caller_21800 __ioremap_caller 1-2 21800 NULL
89056 +alloc_and_copy_ftrace_hash_29368 alloc_and_copy_ftrace_hash 1 29368 NULL
89057 +ubi_dump_flash_46381 ubi_dump_flash 4 46381 NULL
89058 +swap_cgroup_swapon_13614 swap_cgroup_swapon 2 13614 NULL
89059 +wm8994_bulk_write_13615 wm8994_bulk_write 3 13615 NULL
89060 +init_chip_wc_pat_62768 init_chip_wc_pat 2 62768 NULL
89061 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
89062 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
89063 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
89064 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
89065 +vmalloc_user_32308 vmalloc_user 1 32308 NULL
89066 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
89067 +ath6kl_wmi_startscan_cmd_33674 ath6kl_wmi_startscan_cmd 8 33674 NULL
89068 +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
89069 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 NULL
89070 +packet_snd_13634 packet_snd 3 13634 NULL
89071 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
89072 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
89073 +sfi_map_table_5462 sfi_map_table 1 5462 NULL
89074 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
89075 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 4 30040 NULL
89076 +fwSendNullPacket_54618 fwSendNullPacket 2 54618 NULL
89077 +drp_wmove_30043 drp_wmove 4 30043 NULL
89078 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
89079 +cache_downcall_13666 cache_downcall 3 13666 NULL
89080 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
89081 +ubi_leb_write_5478 ubi_leb_write 4-5 5478 NULL
89082 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
89083 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
89084 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
89085 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
89086 +tty_write_5494 tty_write 3 5494 NULL
89087 +iscsi_ping_comp_event_38263 iscsi_ping_comp_event 5 38263 NULL
89088 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL
89089 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
89090 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
89091 +teiup_create_43201 teiup_create 3 43201 NULL
89092 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
89093 +filldir64_46469 filldir64 3 46469 NULL
89094 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL nohasharray
89095 +set_dis_disc_pfs_28225 set_dis_disc_pfs 3 28225 &line6_alloc_sysex_buffer_28225
89096 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
89097 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
89098 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
89099 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
89100 +tg3_run_loopback_30093 tg3_run_loopback 2 30093 NULL
89101 +spidev_message_5518 spidev_message 3 5518 NULL
89102 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
89103 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
89104 +ezusb_writememory_45976 ezusb_writememory 4 45976 NULL
89105 +evm_read_key_54674 evm_read_key 3 54674 NULL
89106 +sctp_make_op_error_space_5528 sctp_make_op_error_space 3 5528 NULL
89107 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
89108 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
89109 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
89110 +em28xx_init_isoc_62883 em28xx_init_isoc 4 62883 NULL nohasharray
89111 +aoechr_write_62883 aoechr_write 3 62883 &em28xx_init_isoc_62883
89112 +resize_info_buffer_62889 resize_info_buffer 2 62889 NULL
89113 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
89114 +u32_array_read_2219 u32_array_read 3 2219 NULL
89115 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
89116 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
89117 +sys_add_key_61288 sys_add_key 4 61288 NULL
89118 +kmsg_read_46514 kmsg_read 3 46514 NULL
89119 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
89120 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
89121 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
89122 +recv_stream_30138 recv_stream 4 30138 NULL
89123 +u_memcpya_30139 u_memcpya 2-3 30139 NULL
89124 +getdqbuf_62908 getdqbuf 1 62908 NULL
89125 +bdx_rxdb_create_46525 bdx_rxdb_create 1 46525 NULL
89126 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
89127 +_add_sg_continuation_descriptor_54721 _add_sg_continuation_descriptor 3 54721 NULL
89128 +fc_frame_alloc_fill_59394 fc_frame_alloc_fill 2 59394 NULL
89129 +fir16_create_5574 fir16_create 3 5574 NULL
89130 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
89131 +pt_write_40159 pt_write 3 40159 NULL
89132 +bioset_create_5580 bioset_create 1 5580 NULL
89133 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
89134 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
89135 +oz_ep_alloc_5587 oz_ep_alloc 2 5587 NULL
89136 +kzalloc_54740 kzalloc 1 54740 NULL
89137 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
89138 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
89139 +do_msgrcv_5590 do_msgrcv 4 5590 NULL
89140 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
89141 +link_send_sections_long_46556 link_send_sections_long 4 46556 NULL
89142 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
89143 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
89144 +batadv_iv_ogm_aggregate_new_54761 batadv_iv_ogm_aggregate_new 2 54761 NULL
89145 +ldm_frag_add_5611 ldm_frag_add 2 5611 NULL
89146 +cx25821_video_ioctl_30188 cx25821_video_ioctl 2 30188 NULL
89147 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
89148 +rxpipe_descr_host_int_trig_rx_data_read_22001 rxpipe_descr_host_int_trig_rx_data_read 3 22001 NULL nohasharray
89149 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 3 22001 &rxpipe_descr_host_int_trig_rx_data_read_22001
89150 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
89151 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
89152 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
89153 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
89154 +hidp_output_raw_report_5629 hidp_output_raw_report 3 5629 NULL
89155 +nfs_idmap_request_key_30208 nfs_idmap_request_key 3 30208 NULL
89156 +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
89157 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
89158 +snd_ac97_pcm_assign_30218 snd_ac97_pcm_assign 2 30218 NULL
89159 +ti_recv_22027 ti_recv 4 22027 NULL
89160 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2 34135 NULL
89161 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
89162 +nfsd_write_54809 nfsd_write 6 54809 NULL
89163 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
89164 +pcnet32_realloc_tx_ring_38428 pcnet32_realloc_tx_ring 3 38428 NULL
89165 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
89166 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
89167 +get_skb_63008 get_skb 2 63008 NULL
89168 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
89169 +netlink_send_38434 netlink_send 5 38434 NULL
89170 +atalk_recvmsg_22053 atalk_recvmsg 4 22053 NULL
89171 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL nohasharray
89172 +alloc_trace_uprobe_13870 alloc_trace_uprobe 3 13870 &compat_ip_setsockopt_13870
89173 +aircable_process_packet_46639 aircable_process_packet 5 46639 NULL
89174 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
89175 +write_rio_54837 write_rio 3 54837 NULL
89176 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 NULL
89177 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
89178 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
89179 +get_arg_5694 get_arg 3 5694 NULL
89180 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
89181 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
89182 +compat_readv_30273 compat_readv 3 30273 NULL
89183 +printer_read_54851 printer_read 3 54851 NULL
89184 +mem_rw_22085 mem_rw 3 22085 NULL
89185 +i915_min_freq_read_38470 i915_min_freq_read 3 38470 NULL
89186 +alloc_ep_req_54860 alloc_ep_req 2 54860 NULL
89187 +lowpan_fragment_xmit_22095 lowpan_fragment_xmit 3-4 22095 NULL
89188 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
89189 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
89190 +unlink1_63059 unlink1 3 63059 NULL
89191 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 NULL
89192 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
89193 +__do_krealloc_54389 __do_krealloc 2 54389 NULL
89194 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
89195 +tcf_csum_ipv6_tcp_54877 tcf_csum_ipv6_tcp 4 54877 NULL
89196 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
89197 +replay_log_leb_18704 replay_log_leb 3 18704 NULL
89198 +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
89199 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
89200 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
89201 +dev_names_read_38509 dev_names_read 3 38509 NULL
89202 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
89203 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5-2-3 63087 NULL
89204 +get_packet_5747 get_packet 3 5747 NULL
89205 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL
89206 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
89207 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
89208 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
89209 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
89210 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
89211 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
89212 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
89213 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
89214 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL
89215 +_l2_alloc_skb_11883 _l2_alloc_skb 1 11883 NULL
89216 +resource_from_user_30341 resource_from_user 3 30341 NULL
89217 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
89218 +sound_write_5102 sound_write 3 5102 NULL
89219 +pn533_dep_link_up_22154 pn533_dep_link_up 5 22154 NULL
89220 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
89221 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
89222 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
89223 +__vmalloc_node_flags_30352 __vmalloc_node_flags 1 30352 NULL
89224 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
89225 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
89226 +com90xx_found_13974 com90xx_found 3 13974 NULL
89227 +compat_sys_writev_5784 compat_sys_writev 3 5784 NULL
89228 +qcam_read_13977 qcam_read 3 13977 NULL
89229 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
89230 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
89231 +virtblk_add_buf_wait_54943 virtblk_add_buf_wait 3-4 54943 NULL
89232 +wl12xx_cmd_build_probe_req_54946 wl12xx_cmd_build_probe_req 6-8 54946 NULL
89233 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
89234 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
89235 +generic_readlink_32654 generic_readlink 3 32654 NULL
89236 +ieee80211_bss_info_update_13991 ieee80211_bss_info_update 4 13991 NULL
89237 +sys_get_mempolicy_30379 sys_get_mempolicy 3 30379 NULL
89238 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
89239 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
89240 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
89241 +trace_options_core_read_47390 trace_options_core_read 3 47390 NULL
89242 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
89243 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
89244 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
89245 +__proc_file_read_54978 __proc_file_read 3 54978 NULL
89246 +concat_writev_21451 concat_writev 3 21451 NULL
89247 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
89248 +_queue_data_54983 _queue_data 4 54983 NULL
89249 +_sys_packet_req_46793 _sys_packet_req 4 46793 NULL
89250 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
89251 +extend_netdev_table_21453 extend_netdev_table 2 21453 NULL
89252 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
89253 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
89254 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
89255 +ixgb_check_copybreak_5847 ixgb_check_copybreak 3 5847 NULL
89256 +setup_req_5848 setup_req 3 5848 NULL
89257 +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
89258 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
89259 +rds_ib_inc_copy_to_user_55007 rds_ib_inc_copy_to_user 3 55007 NULL
89260 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
89261 +rbd_create_rw_ops_55297 rbd_create_rw_ops 1 55297 NULL
89262 +compat_sys_move_pages_5861 compat_sys_move_pages 2 5861 NULL
89263 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
89264 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
89265 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
89266 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
89267 +cma_create_area_38642 cma_create_area 2 38642 NULL
89268 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
89269 +sriov_enable_59689 sriov_enable 2 59689 NULL
89270 +enable_write_30456 enable_write 3 30456 NULL
89271 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
89272 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
89273 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
89274 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
89275 +tcp_manip_pkt_16563 tcp_manip_pkt 4 16563 NULL
89276 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
89277 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
89278 +ieee80211_mgmt_tx_46860 ieee80211_mgmt_tx 9 46860 NULL
89279 +port_show_regs_5904 port_show_regs 3 5904 NULL
89280 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
89281 +ptp_read_63251 ptp_read 4 63251 NULL
89282 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
89283 +compat_sys_pselect6_14105 compat_sys_pselect6 1 14105 NULL
89284 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
89285 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL
89286 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
89287 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
89288 +ttm_bo_kmap_ttm_5922 ttm_bo_kmap_ttm 3 5922 NULL
89289 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
89290 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
89291 +iscsi_iser_recv_41948 iscsi_iser_recv 4 41948 NULL
89292 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
89293 +em28xx_alloc_isoc_46892 em28xx_alloc_isoc 4 46892 NULL
89294 +read_dma_55086 read_dma 3 55086 NULL
89295 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
89296 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
89297 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
89298 +ntfs_rl_replace_14136 ntfs_rl_replace 2-4 14136 NULL
89299 +ip_send_unicast_reply_38714 ip_send_unicast_reply 6 38714 NULL
89300 +tcp_collapse_63294 tcp_collapse 6-5 63294 NULL
89301 +alloc_trace_probe_38720 alloc_trace_probe 6 38720 NULL
89302 +isdn_ppp_ccp_xmit_reset_63297 isdn_ppp_ccp_xmit_reset 6 63297 NULL
89303 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
89304 +tipc_subseq_alloc_5957 tipc_subseq_alloc 1 5957 NULL
89305 +em_canid_change_14150 em_canid_change 3 14150 NULL
89306 +tracing_ctrl_read_46922 tracing_ctrl_read 3 46922 NULL
89307 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
89308 +fb_write_46924 fb_write 3 46924 NULL
89309 +btmrvl_curpsmode_read_46939 btmrvl_curpsmode_read 3 46939 NULL
89310 +wlcore_alloc_hw_22365 wlcore_alloc_hw 1 22365 NULL
89311 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
89312 +br_send_bpdu_29669 br_send_bpdu 3 29669 NULL
89313 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
89314 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
89315 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
89316 +udf_readpages_38761 udf_readpages 4 38761 NULL
89317 +reada_add_block_54247 reada_add_block 2 54247 NULL
89318 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
89319 +proc_info_read_63344 proc_info_read 3 63344 NULL
89320 +pep_indicate_38611 pep_indicate 5 38611 NULL
89321 +set_le_30581 set_le 4 30581 NULL
89322 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
89323 +btmrvl_psmode_read_22395 btmrvl_psmode_read 3 22395 NULL
89324 +alloc_private_22399 alloc_private 2 22399 NULL
89325 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
89326 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
89327 +zoran_write_22404 zoran_write 3 22404 NULL
89328 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 NULL
89329 +idmouse_read_63374 idmouse_read 3 63374 NULL
89330 +queue_reply_22416 queue_reply 3 22416 NULL
89331 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
89332 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
89333 +ntfs_rl_append_6037 ntfs_rl_append 2-4 6037 NULL
89334 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
89335 +ttm_bo_io_47000 ttm_bo_io 5 47000 NULL
89336 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
89337 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
89338 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 NULL
89339 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
89340 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
89341 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4-2 14244 NULL
89342 +snd_soc_hw_bulk_write_raw_14245 snd_soc_hw_bulk_write_raw 4 14245 NULL
89343 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL nohasharray
89344 +isdn_net_ciscohdlck_alloc_skb_55209 isdn_net_ciscohdlck_alloc_skb 2 55209 &ht40allow_map_read_55209
89345 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
89346 +sys_select_38827 sys_select 1 38827 NULL
89347 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
89348 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
89349 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2 47024 NULL
89350 +direct_entry_38836 direct_entry 3 38836 NULL
89351 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
89352 +gntdev_alloc_map_35145 gntdev_alloc_map 2 35145 NULL
89353 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
89354 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
89355 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
89356 +write_head_30481 write_head 4 30481 NULL
89357 +mem_cgroup_read_22461 mem_cgroup_read 5 22461 NULL
89358 +set_dis_bypass_pfs_47038 set_dis_bypass_pfs 3 47038 NULL
89359 +add_numbered_child_14273 add_numbered_child 5 14273 NULL
89360 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
89361 +OS_mem_token_alloc_14276 OS_mem_token_alloc 1 14276 NULL
89362 +sep_prepare_input_output_dma_table_63429 sep_prepare_input_output_dma_table 2-4-3 63429 NULL
89363 +register_unifi_sdio_55239 register_unifi_sdio 2 55239 NULL
89364 +ath6kl_wmi_get_new_buf_52304 ath6kl_wmi_get_new_buf 1 52304 NULL
89365 +agp_remap_30665 agp_remap 2 30665 NULL
89366 +interfaces_38859 interfaces 2 38859 NULL
89367 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
89368 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
89369 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
89370 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
89371 +qc_capture_19298 qc_capture 3 19298 NULL
89372 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
89373 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
89374 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
89375 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
89376 +rtl_port_map_2385 rtl_port_map 1-2 2385 NULL
89377 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
89378 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
89379 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
89380 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
89381 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
89382 +process_bulk_data_command_38906 process_bulk_data_command 4 38906 NULL
89383 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
89384 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
89385 +read_kcore_63488 read_kcore 3 63488 NULL
89386 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
89387 +__skb_cow_39254 __skb_cow 2 39254 NULL
89388 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
89389 +__get_vm_area_node_55305 __get_vm_area_node 1 55305 NULL
89390 +ffs_epfile_read_18775 ffs_epfile_read 3 18775 NULL
89391 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
89392 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
89393 +pskb_may_pull_22546 pskb_may_pull 2 22546 NULL
89394 +mousedev_read_47123 mousedev_read 3 47123 NULL
89395 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
89396 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
89397 +vdma_mem_alloc_6171 vdma_mem_alloc 1 6171 NULL
89398 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
89399 +ses_recv_diag_47143 ses_recv_diag 4 47143 NULL nohasharray
89400 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 &ses_recv_diag_47143
89401 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
89402 +vme_user_read_55338 vme_user_read 3 55338 NULL
89403 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 NULL
89404 +cxio_init_resource_fifo_random_47151 cxio_init_resource_fifo_random 3 47151 NULL
89405 +persistent_ram_iomap_47156 persistent_ram_iomap 1-2 47156 NULL
89406 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
89407 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
89408 +__hidp_send_ctrl_message_28303 __hidp_send_ctrl_message 4 28303 NULL
89409 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
89410 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
89411 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
89412 +acpi_system_read_event_55362 acpi_system_read_event 3 55362 NULL
89413 +dbg_leb_write_63555 dbg_leb_write 4-5 63555 NULL nohasharray
89414 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 &dbg_leb_write_63555
89415 +snapshot_read_22601 snapshot_read 3 22601 NULL
89416 +OSDSetBlock_38986 OSDSetBlock 4-2 38986 NULL
89417 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
89418 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
89419 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
89420 +ioremap_cache_47189 ioremap_cache 1-2 47189 NULL
89421 +__send_to_port_55383 __send_to_port 3 55383 NULL
89422 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
89423 +nf_nat_ipv4_manip_pkt_55387 nf_nat_ipv4_manip_pkt 2 55387 NULL
89424 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
89425 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
89426 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
89427 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
89428 +get_nodes_39012 get_nodes 3 39012 NULL
89429 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
89430 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
89431 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
89432 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
89433 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
89434 +create_subvol_30836 create_subvol 4 30836 NULL
89435 +mthca_map_reg_5664 mthca_map_reg 2-3 5664 NULL
89436 +ci13xxx_add_device_14456 ci13xxx_add_device 3 14456 NULL
89437 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
89438 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
89439 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
89440 +read_oldmem_55658 read_oldmem 3 55658 NULL
89441 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
89442 +xenbus_file_write_6282 xenbus_file_write 3 6282 NULL
89443 +options_write_47243 options_write 3 47243 NULL
89444 +module_alloc_63630 module_alloc 1 63630 NULL
89445 +alloc_skb_55439 alloc_skb 1 55439 NULL
89446 +nf_nat_ipv6_manip_pkt_6289 nf_nat_ipv6_manip_pkt 2 6289 NULL
89447 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
89448 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
89449 +ubifs_leb_write_22679 ubifs_leb_write 4-5 22679 NULL
89450 +nf_nat_sack_adjust_6297 nf_nat_sack_adjust 2 6297 NULL
89451 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
89452 +mid_get_vbt_data_r10_6308 mid_get_vbt_data_r10 2 6308 NULL
89453 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
89454 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
89455 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
89456 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
89457 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
89458 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
89459 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
89460 +tty_audit_log_47280 tty_audit_log 8 47280 NULL
89461 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
89462 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
89463 +fc_host_post_vendor_event_30903 fc_host_post_vendor_event 3 30903 NULL
89464 +vbi_read_63673 vbi_read 3 63673 NULL
89465 +tun_get_user_39099 tun_get_user 4 39099 NULL
89466 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
89467 +alloc_tty_driver_63681 alloc_tty_driver 1 63681 NULL
89468 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
89469 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
89470 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
89471 +nfc_hci_hcp_message_tx_14534 nfc_hci_hcp_message_tx 6 14534 NULL
89472 +iommu_map_mmio_space_30919 iommu_map_mmio_space 1 30919 NULL
89473 +ep0_write_14536 ep0_write 3 14536 NULL nohasharray
89474 +dataflash_read_user_otp_14536 dataflash_read_user_otp 2-3 14536 &ep0_write_14536
89475 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
89476 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4 22735 NULL
89477 +ax25_output_22736 ax25_output 2 22736 NULL
89478 +__kfifo_to_user_r_39123 __kfifo_to_user_r 3 39123 NULL
89479 +l2cap_send_cmd_14548 l2cap_send_cmd 4 14548 NULL
89480 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
89481 +drm_vmalloc_dma_14550 drm_vmalloc_dma 1 14550 NULL
89482 +cfpkt_pad_trail_55511 cfpkt_pad_trail 2 55511 NULL nohasharray
89483 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 &cfpkt_pad_trail_55511
89484 +cmtp_add_msgpart_9252 cmtp_add_msgpart 4 9252 NULL
89485 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
89486 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
89487 +hid_input_report_32458 hid_input_report 4 32458 NULL
89488 +_proc_do_string_6376 _proc_do_string 2 6376 NULL
89489 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
89490 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
89491 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
89492 +alloc_ring_39151 alloc_ring 2-4 39151 NULL
89493 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
89494 +create_bounce_buffer_39155 create_bounce_buffer 3 39155 NULL
89495 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
89496 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
89497 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
89498 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
89499 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
89500 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
89501 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
89502 +bt_skb_alloc_6404 bt_skb_alloc 1 6404 NULL
89503 +get_info_55681 get_info 3 55681 NULL
89504 +setkey_14987 setkey 3 14987 NULL
89505 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
89506 +init_list_set_39188 init_list_set 2-3 39188 NULL
89507 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
89508 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
89509 +l2up_create_6430 l2up_create 3 6430 NULL
89510 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
89511 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
89512 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
89513 +add_partition_55588 add_partition 2 55588 NULL
89514 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
89515 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
89516 +depth_read_31112 depth_read 3 31112 NULL
89517 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
89518 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
89519 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
89520 +profile_replace_14652 profile_replace 3 14652 NULL
89521 +vzalloc_47421 vzalloc 1 47421 NULL
89522 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
89523 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
89524 +sys_writev_28384 sys_writev 3 28384 NULL
89525 +batadv_tt_response_fill_table_39236 batadv_tt_response_fill_table 1 39236 NULL
89526 +read_file_rcstat_22854 read_file_rcstat 3 22854 NULL
89527 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4 44769 NULL
89528 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
89529 +pktgen_if_write_55628 pktgen_if_write 3 55628 NULL
89530 +create_attr_set_22861 create_attr_set 1 22861 NULL
89531 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
89532 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
89533 +compat_sys_mq_timedsend_31060 compat_sys_mq_timedsend 3 31060 NULL
89534 +sel_write_load_63830 sel_write_load 3 63830 NULL
89535 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
89536 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
89537 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
89538 +dvb_dmxdev_set_buffer_size_55643 dvb_dmxdev_set_buffer_size 2 55643 NULL
89539 +tsi148_master_set_14685 tsi148_master_set 4 14685 NULL
89540 +ath6kl_wmi_set_appie_cmd_39266 ath6kl_wmi_set_appie_cmd 5 39266 NULL
89541 +probe_bios_17467 probe_bios 1 17467 NULL
89542 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
89543 +ttm_bo_ioremap_31082 ttm_bo_ioremap 2-3 31082 NULL
89544 +mei_read_6507 mei_read 3 6507 NULL
89545 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
89546 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
89547 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
89548 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
89549 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
89550 +SetArea_50835 SetArea 4 50835 NULL
89551 +tpm_read_50344 tpm_read 3 50344 NULL
89552 +newpart_47485 newpart 6 47485 NULL
89553 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
89554 +compat_sys_get_mempolicy_31109 compat_sys_get_mempolicy 3 31109 NULL
89555 +core_sys_select_47494 core_sys_select 1 47494 NULL
89556 +read_file_disable_ani_6536 read_file_disable_ani 3 6536 NULL
89557 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
89558 +__vmalloc_node_39308 __vmalloc_node 1 39308 NULL
89559 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
89560 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
89561 +unlink_simple_47506 unlink_simple 3 47506 NULL
89562 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
89563 +wdm_read_6549 wdm_read 3 6549 NULL
89564 +init_map_ipmac_63896 init_map_ipmac 4-3 63896 NULL
89565 +tipc_multicast_49144 tipc_multicast 5 49144 NULL
89566 +nfs4_realloc_slot_table_22859 nfs4_realloc_slot_table 2 22859 NULL
89567 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
89568 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
89569 +__videobuf_alloc_uncached_55711 __videobuf_alloc_uncached 1 55711 NULL
89570 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
89571 +nfc_hci_send_cmd_55714 nfc_hci_send_cmd 5 55714 NULL
89572 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
89573 +filter_read_61692 filter_read 3 61692 NULL
89574 +mtdswap_init_55719 mtdswap_init 2 55719 NULL
89575 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
89576 +debugfs_read_62535 debugfs_read 3 62535 NULL
89577 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
89578 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL
89579 +divas_write_63901 divas_write 3 63901 NULL
89580 +alloc_sglist_22960 alloc_sglist 1-2-3 22960 NULL
89581 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
89582 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
89583 +cfpkt_split_47541 cfpkt_split 2 47541 NULL
89584 +__copy_from_user_nocache_39351 __copy_from_user_nocache 3 39351 NULL
89585 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
89586 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 3-2 55738 NULL
89587 +ipw_write_59807 ipw_write 3 59807 NULL
89588 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
89589 +tipc_send2port_63935 tipc_send2port 5 63935 NULL
89590 +do_write_log_from_user_39362 do_write_log_from_user 3 39362 NULL
89591 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
89592 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
89593 +mwifiex_cfg80211_mgmt_tx_12022 mwifiex_cfg80211_mgmt_tx 9 12022 NULL
89594 +cycx_setup_47562 cycx_setup 4 47562 NULL
89595 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
89596 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
89597 +set_local_name_55757 set_local_name 4 55757 NULL
89598 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
89599 +btrfs_init_new_buffer_55761 btrfs_init_new_buffer 4 55761 NULL
89600 +read_ldt_47570 read_ldt 2 47570 NULL
89601 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
89602 +pci_iomap_47575 pci_iomap 3 47575 NULL
89603 +acpi_ex_system_memory_space_handler_31192 acpi_ex_system_memory_space_handler 2 31192 NULL
89604 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
89605 +module_alloc_update_bounds_rw_63233 module_alloc_update_bounds_rw 1 63233 NULL
89606 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
89607 +drm_ht_create_18853 drm_ht_create 2 18853 NULL
89608 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
89609 +qlcnic_alloc_msix_entries_46160 qlcnic_alloc_msix_entries 2 46160 NULL
89610 +ieee80211_authentication_req_63973 ieee80211_authentication_req 3 63973 NULL
89611 +dn_alloc_skb_6631 dn_alloc_skb 2 6631 NULL
89612 +conf_read_55786 conf_read 3 55786 NULL
89613 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
89614 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
89615 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
89616 +virtscsi_alloc_tgt_6643 virtscsi_alloc_tgt 2 6643 NULL
89617 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
89618 +user_power_read_39414 user_power_read 3 39414 NULL
89619 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
89620 +uea_request_47613 uea_request 4 47613 NULL
89621 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
89622 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
89623 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
89624 +btrfs_find_create_tree_block_55812 btrfs_find_create_tree_block 3 55812 NULL
89625 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
89626 +lcd_write_14857 lcd_write 3 14857 NULL nohasharray
89627 +__krealloc_14857 __krealloc 2 14857 &lcd_write_14857
89628 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
89629 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
89630 +kmemdup_64015 kmemdup 2 64015 NULL
89631 +compat_sys_select_16131 compat_sys_select 1 16131 NULL
89632 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
89633 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
89634 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
89635 +tcf_csum_skb_nextlayer_64025 tcf_csum_skb_nextlayer 3 64025 NULL
89636 +oz_events_read_47535 oz_events_read 3 47535 NULL
89637 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
89638 +resize_async_buffer_64031 resize_async_buffer 4 64031 NULL
89639 +sys_semop_39457 sys_semop 3 39457 NULL
89640 +vm_map_ram_23078 vm_map_ram 2 23078 NULL nohasharray
89641 +raw_sendmsg_23078 raw_sendmsg 4 23078 &vm_map_ram_23078
89642 +update_pmkid_2481 update_pmkid 4 2481 NULL
89643 +sriov_enable_migration_14889 sriov_enable_migration 2 14889 NULL
89644 +sep_lli_table_secure_dma_64042 sep_lli_table_secure_dma 2-3 64042 NULL
89645 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
89646 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
89647 +hysdn_rx_netpkt_16136 hysdn_rx_netpkt 3 16136 NULL
89648 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
89649 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
89650 +mpeg_read_6708 mpeg_read 3 6708 NULL
89651 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
89652 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
89653 +sky2_receive_13407 sky2_receive 2 13407 NULL
89654 +krealloc_14908 krealloc 2 14908 NULL
89655 +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
89656 +bt_skb_send_alloc_6581 bt_skb_send_alloc 2 6581 NULL
89657 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
89658 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
89659 +video_proc_write_6724 video_proc_write 3 6724 NULL
89660 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
89661 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
89662 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
89663 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
89664 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
89665 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
89666 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
89667 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL
89668 +command_file_write_31318 command_file_write 3 31318 NULL
89669 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
89670 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
89671 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
89672 +i915_cache_sharing_read_24775 i915_cache_sharing_read 3 24775 NULL
89673 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
89674 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
89675 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
89676 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
89677 +ca91cx42_master_set_23146 ca91cx42_master_set 4 23146 NULL
89678 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
89679 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
89680 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
89681 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
89682 +sfi_check_table_6772 sfi_check_table 1 6772 NULL
89683 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
89684 +int_proc_write_39542 int_proc_write 3 39542 NULL
89685 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
89686 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
89687 +read_file_ani_23161 read_file_ani 3 23161 NULL
89688 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
89689 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
89690 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
89691 +pp_write_39554 pp_write 3 39554 NULL
89692 +ioremap_23172 ioremap 1-2 23172 NULL
89693 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
89694 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
89695 +usblp_write_23178 usblp_write 3 23178 NULL
89696 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
89697 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
89698 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3 31374 NULL
89699 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
89700 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
89701 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
89702 +fix_unclean_leb_23188 fix_unclean_leb 3 23188 NULL
89703 +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
89704 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
89705 +vmalloc_32_1135 vmalloc_32 1 1135 NULL
89706 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
89707 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
89708 +__team_options_register_63941 __team_options_register 3 63941 NULL
89709 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
89710 +ip_ufo_append_data_12775 ip_ufo_append_data 6-7-8 12775 NULL
89711 +rvmalloc_46873 rvmalloc 1 46873 NULL
89712 +vmap_15025 vmap 2 15025 NULL
89713 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
89714 +mcs7830_set_reg_31413 mcs7830_set_reg 3 31413 NULL
89715 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
89716 +tty_buffer_request_room_23228 tty_buffer_request_room 2 23228 NULL
89717 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL
89718 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
89719 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
89720 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
89721 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
89722 +ttm_object_device_init_10321 ttm_object_device_init 2 10321 NULL
89723 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
89724 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
89725 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL
89726 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
89727 +ssb_bus_pcmciabus_register_56020 ssb_bus_pcmciabus_register 3 56020 NULL
89728 +fm_send_cmd_39639 fm_send_cmd 5 39639 NULL
89729 +ip6gre_err_19869 ip6gre_err 5 19869 NULL
89730 +nvme_alloc_iod_56027 nvme_alloc_iod 1 56027 NULL
89731 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
89732 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
89733 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5 15072 NULL
89734 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
89735 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
89736 +get_new_cssid_51665 get_new_cssid 2 51665 NULL
89737 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL
89738 +prism2_info_hostscanresults_39657 prism2_info_hostscanresults 3 39657 NULL
89739 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
89740 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
89741 +__videobuf_alloc_vb_5665 __videobuf_alloc_vb 1 5665 NULL
89742 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
89743 +redrat3_transmit_ir_64244 redrat3_transmit_ir 3 64244 NULL
89744 +__alloc_extent_buffer_15093 __alloc_extent_buffer 3 15093 NULL
89745 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
89746 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
89747 +alg_setkey_31485 alg_setkey 3 31485 NULL
89748 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
89749 +spi_show_regs_6911 spi_show_regs 3 6911 NULL nohasharray
89750 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 &spi_show_regs_6911
89751 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
89752 +vhci_read_47878 vhci_read 3 47878 NULL
89753 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
89754 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
89755 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
89756 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
89757 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
89758 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
89759 +event_id_read_64288 event_id_read 3 64288 NULL nohasharray
89760 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 &event_id_read_64288
89761 +osd_req_read_sg_47905 osd_req_read_sg 5 47905 NULL
89762 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
89763 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
89764 +timeout_read_47915 timeout_read 3 47915 NULL
89765 +hidraw_write_31536 hidraw_write 3 31536 NULL
89766 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
89767 +page_readlink_23346 page_readlink 3 23346 NULL
89768 +videobuf_dma_init_kernel_6963 videobuf_dma_init_kernel 3 6963 NULL
89769 +comedi_write_47926 comedi_write 3 47926 NULL
89770 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
89771 +dsp_write_46218 dsp_write 2 46218 NULL
89772 +kmem_zalloc_large_56128 kmem_zalloc_large 1 56128 NULL
89773 +usbvision_read_31555 usbvision_read 3 31555 NULL
89774 +pd_video_read_24510 pd_video_read 3 24510 NULL
89775 +crypto_authenc_esn_setkey_6985 crypto_authenc_esn_setkey 3 6985 NULL
89776 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
89777 +request_key_async_6990 request_key_async 4 6990 NULL
89778 +ts_write_64336 ts_write 3 64336 NULL
89779 +handle_response_55951 handle_response 5 55951 NULL
89780 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
89781 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
89782 +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
89783 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
89784 +osst_write_31581 osst_write 3 31581 NULL
89785 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
89786 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
89787 +wm8350_block_write_19727 wm8350_block_write 3 19727 NULL
89788 +diva_xdi_write_63975 diva_xdi_write 4 63975 NULL
89789 +llc_alloc_frame_64366 llc_alloc_frame 4 64366 NULL
89790 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 NULL nohasharray
89791 +mempool_resize_47983 mempool_resize 2 47983 &iwl_dbgfs_ucode_tracing_read_47983
89792 +mangle_packet_18920 mangle_packet 7-9 18920 NULL
89793 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
89794 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
89795 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
89796 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
89797 +ilo_write_64378 ilo_write 3 64378 NULL
89798 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
89799 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
89800 +vzalloc_node_23424 vzalloc_node 1 23424 NULL
89801 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL
89802 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
89803 +variax_alloc_sysex_buffer_15237 variax_alloc_sysex_buffer 3 15237 NULL
89804 +copy_from_user_17559 copy_from_user 3 17559 NULL
89805 +ffs_epfile_write_48014 ffs_epfile_write 3 48014 NULL
89806 +sys_migrate_pages_39825 sys_migrate_pages 2 39825 NULL
89807 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
89808 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
89809 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
89810 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
89811 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
89812 +beiscsi_process_async_pdu_39834 beiscsi_process_async_pdu 7 39834 NULL
89813 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
89814 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
89815 +snd_card_create_64418 snd_card_create 4 64418 NULL nohasharray
89816 +keyctl_get_security_64418 keyctl_get_security 3 64418 &snd_card_create_64418
89817 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
89818 +cp210x_get_config_56229 cp210x_get_config 4 56229 NULL
89819 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
89820 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
89821 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
89822 +dn_nsp_send_disc_23469 dn_nsp_send_disc 2 23469 NULL
89823 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
89824 +ping_sendmsg_3782 ping_sendmsg 4 3782 NULL
89825 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL
89826 +__lgread_31668 __lgread 4 31668 NULL
89827 +scrub_setup_recheck_block_56245 scrub_setup_recheck_block 4-3 56245 NULL
89828 +fd_copyin_56247 fd_copyin 3 56247 NULL
89829 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
89830 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
89831 +sys_connect_15291 sys_connect 3 15291 NULL nohasharray
89832 +xlate_dev_mem_ptr_15291 xlate_dev_mem_ptr 1 15291 &sys_connect_15291
89833 +linear_conf_23485 linear_conf 2 23485 NULL nohasharray
89834 +divasa_remap_pci_bar_23485 divasa_remap_pci_bar 3-4 23485 &linear_conf_23485
89835 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
89836 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
89837 +_usb_writeN_sync_31682 _usb_writeN_sync 4 31682 NULL
89838 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
89839 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
89840 +event_filter_read_23494 event_filter_read 3 23494 NULL
89841 +tpm_tis_init_15304 tpm_tis_init 2-3 15304 NULL
89842 +fcoe_ctlr_send_keep_alive_15308 fcoe_ctlr_send_keep_alive 3 15308 NULL
89843 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
89844 +sys_setsockopt_35320 sys_setsockopt 5 35320 NULL
89845 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
89846 +pkt_add_39897 pkt_add 3 39897 NULL
89847 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
89848 +send_mpa_reject_7135 send_mpa_reject 3 7135 NULL
89849 +sctp_make_op_error_7057 sctp_make_op_error 5-6 7057 NULL
89850 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
89851 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
89852 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
89853 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
89854 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
89855 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
89856 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
89857 +sctp_make_asconf_ack_31726 sctp_make_asconf_ack 3 31726 NULL
89858 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
89859 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
89860 +alloc_ring_15345 alloc_ring 2-4 15345 NULL
89861 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
89862 +remove_uuid_64505 remove_uuid 4 64505 NULL
89863 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3 31741 NULL
89864 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 NULL
89865 +create_table_16213 create_table 2 16213 NULL
89866 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
89867 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
89868 +dbg_leb_change_23555 dbg_leb_change 4 23555 NULL
89869 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
89870 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
89871 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
89872 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
89873 +set_discoverable_48141 set_discoverable 4 48141 NULL
89874 +compat_sys_process_vm_readv_15374 compat_sys_process_vm_readv 3-5 15374 NULL
89875 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
89876 +tcp_match_skb_to_sack_23568 tcp_match_skb_to_sack 4 23568 NULL
89877 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
89878 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
89879 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3 39955 NULL
89880 +__tcp_push_pending_frames_48148 __tcp_push_pending_frames 2 48148 NULL
89881 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
89882 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
89883 +ipv6_recv_error_56347 ipv6_recv_error 3 56347 NULL
89884 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
89885 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
89886 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
89887 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
89888 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
89889 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
89890 +cfpkt_create_pfx_23594 cfpkt_create_pfx 1-2 23594 NULL
89891 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
89892 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4 56368 NULL
89893 +dev_read_56369 dev_read 3 56369 NULL
89894 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
89895 +alloc_dummy_extent_buffer_56374 alloc_dummy_extent_buffer 2 56374 NULL
89896 +diva_os_alloc_message_buffer_64568 diva_os_alloc_message_buffer 1 64568 NULL
89897 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
89898 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
89899 +init_ipath_48187 init_ipath 1 48187 NULL
89900 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
89901 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4 15423 NULL
89902 +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
89903 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
89904 +sys32_ipc_7238 sys32_ipc 3 7238 NULL
89905 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
89906 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1-2 21687 NULL
89907 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
89908 +ddp_ppod_write_idata_25610 ddp_ppod_write_idata 5 25610 NULL
89909 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
89910 +nf_nat_icmpv6_reply_translation_40023 nf_nat_icmpv6_reply_translation 5 40023 NULL nohasharray
89911 +ivtvfb_write_40023 ivtvfb_write 3 40023 &nf_nat_icmpv6_reply_translation_40023
89912 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
89913 +tcp_write_xmit_64602 tcp_write_xmit 2 64602 NULL
89914 +use_pool_64607 use_pool 2 64607 NULL
89915 +__get_vm_area_caller_56416 __get_vm_area_caller 1 56416 NULL nohasharray
89916 +acpi_os_write_memory_56416 acpi_os_write_memory 1-3 56416 &__get_vm_area_caller_56416
89917 +store_msg_56417 store_msg 3 56417 NULL
89918 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
89919 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
89920 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
89921 +read_file_recv_48232 read_file_recv 3 48232 NULL
89922 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
89923 +set_tpl_pfs_27490 set_tpl_pfs 3 27490 NULL
89924 +fanotify_write_64623 fanotify_write 3 64623 NULL
89925 +batadv_add_packet_12136 batadv_add_packet 3 12136 NULL
89926 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
89927 +fl_create_56435 fl_create 5 56435 NULL
89928 +gnttab_map_56439 gnttab_map 2 56439 NULL
89929 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
89930 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
89931 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
89932 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2 56453 NULL
89933 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
89934 +set_connectable_56458 set_connectable 4 56458 NULL
89935 +a2mp_chan_alloc_skb_cb_27159 a2mp_chan_alloc_skb_cb 2 27159 NULL
89936 +nfc_hci_send_response_56462 nfc_hci_send_response 5 56462 NULL
89937 +add_port_54941 add_port 2 54941 NULL
89938 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
89939 +cx18_read_23699 cx18_read 3 23699 NULL
89940 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 NULL
89941 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
89942 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
89943 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
89944 +ddb_output_write_31902 ddb_output_write 3 31902 NULL
89945 +send_set_info_48288 send_set_info 7 48288 NULL
89946 +sock_alloc_send_skb_23720 sock_alloc_send_skb 2 23720 NULL
89947 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
89948 +set_disc_pwup_pfs_48300 set_disc_pwup_pfs 3 48300 NULL
89949 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
89950 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
89951 +new_dir_31919 new_dir 3 31919 NULL
89952 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
89953 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
89954 +sec_bulk_write_64691 sec_bulk_write 3 64691 NULL
89955 +mgmt_control_7349 mgmt_control 3 7349 NULL
89956 +hash_setkey_48310 hash_setkey 3 48310 NULL
89957 +ql_process_mac_rx_page_15543 ql_process_mac_rx_page 4 15543 NULL
89958 +hfcpci_empty_fifo_2427 hfcpci_empty_fifo 4 2427 NULL
89959 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
89960 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
89961 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
89962 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
89963 +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4 31942 NULL
89964 +ql_process_mac_rx_skb_6689 ql_process_mac_rx_skb 4 6689 NULL
89965 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
89966 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
89967 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
89968 +vb2_write_31948 vb2_write 3 31948 NULL
89969 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
89970 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
89971 +l1oip_socket_recv_56537 l1oip_socket_recv 6 56537 NULL
89972 +ip_options_get_56538 ip_options_get 4 56538 NULL
89973 +write_62671 write 3 62671 NULL
89974 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
89975 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
89976 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
89977 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
89978 +ceph_copy_page_vector_to_user_31270 ceph_copy_page_vector_to_user 3-4 31270 NULL
89979 +allocate_cnodes_5329 allocate_cnodes 1 5329 NULL
89980 +skb_add_data_48363 skb_add_data 3 48363 NULL
89981 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
89982 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
89983 +iscsi_complete_pdu_48372 iscsi_complete_pdu 4 48372 NULL
89984 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
89985 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
89986 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
89987 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL
89988 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
89989 +set_dis_tap_pfs_15621 set_dis_tap_pfs 3 15621 NULL
89990 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
89991 +dsp_cmx_send_member_15625 dsp_cmx_send_member 2 15625 NULL
89992 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
89993 +system_enable_read_25815 system_enable_read 3 25815 NULL
89994 +allocate_probes_40204 allocate_probes 1 40204 NULL
89995 +sd_alloc_ctl_entry_29708 sd_alloc_ctl_entry 1 29708 NULL
89996 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
89997 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
89998 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
89999 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
90000 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
90001 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
90002 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
90003 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642
90004 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
90005 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
90006 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
90007 +fs_path_add_15648 fs_path_add 3 15648 NULL
90008 +event_filter_write_56609 event_filter_write 3 56609 NULL
90009 +xfs_buf_read_map_40226 xfs_buf_read_map 3 40226 NULL
90010 +ms_rw_multi_sector_7459 ms_rw_multi_sector 3-4 7459 NULL
90011 +xsd_read_15653 xsd_read 3 15653 NULL
90012 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
90013 +p54_init_common_23850 p54_init_common 1 23850 NULL
90014 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
90015 +vmw_cursor_update_dmabuf_32045 vmw_cursor_update_dmabuf 3-4 32045 NULL
90016 +sys_sched_setaffinity_32046 sys_sched_setaffinity 2 32046 NULL
90017 +garp_request_join_7471 garp_request_join 4 7471 NULL
90018 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
90019 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
90020 +unifi_read_14899 unifi_read 3 14899 NULL
90021 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
90022 +compat_sys_msgrcv_7482 compat_sys_msgrcv 2 7482 NULL
90023 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
90024 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
90025 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
90026 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
90027 +ipv6_recv_rxpmtu_7142 ipv6_recv_rxpmtu 3 7142 NULL
90028 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
90029 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
90030 +ieee80211_if_read_channel_type_23884 ieee80211_if_read_channel_type 3 23884 NULL
90031 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
90032 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
90033 +uf_sme_queue_message_15697 uf_sme_queue_message 3 15697 NULL
90034 +gdth_search_isa_58595 gdth_search_isa 1 58595 NULL
90035 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 NULL
90036 +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
90037 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
90038 +iwch_reject_cr_23901 iwch_reject_cr 3 23901 NULL
90039 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
90040 +bio_alloc_32095 bio_alloc 2 32095 NULL
90041 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
90042 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
90043 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
90044 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL
90045 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
90046 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
90047 +ubi_io_write_data_40305 ubi_io_write_data 4-5 40305 NULL
90048 +send_control_msg_48498 send_control_msg 6 48498 NULL
90049 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
90050 +mlx4_en_create_tx_ring_48501 mlx4_en_create_tx_ring 4 48501 NULL
90051 +ffs_epfile_io_64886 ffs_epfile_io 3 64886 NULL
90052 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
90053 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
90054 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3 56702 NULL
90055 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
90056 +batadv_tt_changes_fill_buff_40323 batadv_tt_changes_fill_buff 4 40323 NULL
90057 +__alloc_skb_23940 __alloc_skb 1 23940 NULL
90058 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
90059 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
90060 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
90061 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
90062 +alloc_tx_32143 alloc_tx 2 32143 NULL
90063 +wiimote_hid_send_48528 wiimote_hid_send 3 48528 NULL
90064 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
90065 +hsc_write_55875 hsc_write 3 55875 NULL
90066 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
90067 +do_test_15766 do_test 1 15766 NULL
90068 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
90069 +ip_recv_error_23109 ip_recv_error 3 23109 NULL
90070 +named_distribute_48544 named_distribute 4 48544 NULL
90071 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
90072 +venus_link_32165 venus_link 5 32165 NULL
90073 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
90074 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
90075 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
90076 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
90077 +set_std_nic_pfs_15792 set_std_nic_pfs 3 15792 NULL
90078 +ubifs_wbuf_write_nolock_64946 ubifs_wbuf_write_nolock 3 64946 NULL
90079 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
90080 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
90081 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
90082 +fwnet_incoming_packet_40380 fwnet_incoming_packet 3 40380 NULL
90083 +groups_alloc_7614 groups_alloc 1 7614 NULL
90084 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
90085 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
90086 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
90087 +ext_sd_execute_read_data_48589 ext_sd_execute_read_data 9 48589 NULL
90088 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
90089 +__carl9170_rx_56784 __carl9170_rx 3 56784 NULL
90090 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL
90091 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
90092 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
90093 +tcf_csum_ipv4_tcp_39713 tcf_csum_ipv4_tcp 4 39713 NULL
90094 +snapshot_write_28351 snapshot_write 3 28351 NULL
90095 +event_enable_read_7074 event_enable_read 3 7074 NULL
90096 +brcmf_sdbrcm_died_dump_15841 brcmf_sdbrcm_died_dump 3 15841 NULL
90097 +do_syslog_56807 do_syslog 3 56807 NULL
90098 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
90099 +pskb_pull_65005 pskb_pull 2 65005 NULL
90100 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
90101 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
90102 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
90103 +unifi_write_65012 unifi_write 3 65012 NULL
90104 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 NULL
90105 +nfs_readdata_alloc_65015 nfs_readdata_alloc 2 65015 NULL
90106 +ubi_io_write_15870 ubi_io_write 5-4 15870 NULL nohasharray
90107 +media_entity_init_15870 media_entity_init 2-4 15870 &ubi_io_write_15870
90108 +mtdchar_write_56831 mtdchar_write 3 56831 NULL nohasharray
90109 +ntfs_rl_realloc_56831 ntfs_rl_realloc 3 56831 &mtdchar_write_56831
90110 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
90111 +mid_get_vbt_data_r1_26170 mid_get_vbt_data_r1 2 26170 NULL
90112 +skb_copy_expand_7685 skb_copy_expand 2-3 7685 NULL nohasharray
90113 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 &skb_copy_expand_7685
90114 +if_write_51756 if_write 3 51756 NULL
90115 +insert_dent_65034 insert_dent 7 65034 NULL
90116 +blkcipher_copy_iv_24075 blkcipher_copy_iv 3 24075 NULL
90117 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4 56847 NULL
90118 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
90119 +brcmf_sdcard_rwdata_65041 brcmf_sdcard_rwdata 5 65041 NULL
90120 +nfs_map_group_to_gid_15892 nfs_map_group_to_gid 3 15892 NULL
90121 +lc_create_48662 lc_create 3 48662 NULL
90122 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
90123 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL nohasharray
90124 +sys_setgroups_48668 sys_setgroups 1 48668 &sm501_create_subdev_48668
90125 +ath9k_multi_regread_65056 ath9k_multi_regread 4 65056 NULL
90126 +brcmf_sdcard_send_buf_7713 brcmf_sdcard_send_buf 6 7713 NULL
90127 +l2cap_build_cmd_48676 l2cap_build_cmd 4 48676 NULL
90128 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
90129 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
90130 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
90131 +bnx2fc_process_l2_frame_compl_65072 bnx2fc_process_l2_frame_compl 3 65072 NULL
90132 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
90133 +persistent_ram_new_40501 persistent_ram_new 1-2 40501 NULL
90134 +ieee80211_send_auth_24121 ieee80211_send_auth 5 24121 NULL
90135 +altera_drscan_48698 altera_drscan 2 48698 NULL
90136 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
90137 +set_bypass_pwup_pfs_7742 set_bypass_pwup_pfs 3 7742 NULL
90138 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
90139 +power_read_15939 power_read 3 15939 NULL
90140 +recv_msg_48709 recv_msg 4 48709 NULL
90141 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL
90142 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
90143 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
90144 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
90145 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
90146 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
90147 +process_vm_rw_pages_15954 process_vm_rw_pages 6-5 15954 NULL
90148 +revalidate_19043 revalidate 2 19043 NULL
90149 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
90150 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 NULL
90151 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
90152 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
90153 +check_header_56930 check_header 2 56930 NULL
90154 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
90155 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
90156 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
90157 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
90158 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL
90159 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
90160 +frame_alloc_15981 frame_alloc 4 15981 NULL
90161 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
90162 +nf_nat_seq_adjust_44989 nf_nat_seq_adjust 4 44989 NULL
90163 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL
90164 +adu_read_24177 adu_read 3 24177 NULL
90165 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
90166 +send_mpa_reply_32372 send_mpa_reply 3 32372 NULL
90167 +alloc_vm_area_15989 alloc_vm_area 1 15989 NULL
90168 +variax_set_raw2_32374 variax_set_raw2 4 32374 NULL
90169 +vfd_write_14717 vfd_write 3 14717 NULL
90170 +carl9170_rx_copy_data_21656 carl9170_rx_copy_data 2 21656 NULL
90171 +usbtmc_read_32377 usbtmc_read 3 32377 NULL
90172 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
90173 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
90174 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
90175 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
90176 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
90177 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
90178 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
90179 +__cxio_init_resource_fifo_23447 __cxio_init_resource_fifo 3 23447 NULL
90180 +skge_rx_get_40598 skge_rx_get 3 40598 NULL
90181 +nouveau_device_create__56984 nouveau_device_create_ 6 56984 NULL
90182 +register_device_60015 register_device 2-3 60015 NULL
90183 +got_frame_16028 got_frame 2 16028 NULL
90184 +ssb_bus_register_65183 ssb_bus_register 3 65183 NULL
90185 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 1-2-3 24224 NULL
90186 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
90187 +scsi_register_49094 scsi_register 2 49094 NULL
90188 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
90189 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
90190 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
90191 +batadv_check_unicast_packet_10866 batadv_check_unicast_packet 2 10866 NULL
90192 +tcp_push_one_48816 tcp_push_one 2 48816 NULL
90193 +nfulnl_alloc_skb_65207 nfulnl_alloc_skb 2 65207 NULL
90194 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
90195 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
90196 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
90197 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
90198 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
90199 +svc_pool_map_alloc_arrays_47181 svc_pool_map_alloc_arrays 2 47181 NULL
90200 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
90201 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
90202 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
90203 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
90204 +compat_sys_preadv64_24283 compat_sys_preadv64 3 24283 NULL
90205 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
90206 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 NULL
90207 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
90208 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
90209 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
90210 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
90211 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
90212 +mid_get_vbt_data_r0_10876 mid_get_vbt_data_r0 2 10876 NULL
90213 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
90214 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
90215 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 NULL nohasharray
90216 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 &dma_tx_requested_read_16110
90217 +sys_setgroups16_48882 sys_setgroups16 1 48882 NULL
90218 +kmem_zalloc_greedy_65268 kmem_zalloc_greedy 3-2 65268 NULL
90219 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
90220 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
90221 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
90222 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
90223 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
90224 +mac_drv_rx_init_48898 mac_drv_rx_init 2 48898 NULL
90225 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
90226 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
90227 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
90228 +fsm_init_16134 fsm_init 2 16134 NULL
90229 +ext_sd_execute_write_data_8175 ext_sd_execute_write_data 9 8175 NULL
90230 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
90231 +disconnect_32521 disconnect 4 32521 NULL
90232 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
90233 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
90234 +ath6kl_wmi_add_wow_pattern_cmd_12842 ath6kl_wmi_add_wow_pattern_cmd 4 12842 NULL
90235 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
90236 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
90237 +ilo_read_32531 ilo_read 3 32531 NULL
90238 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
90239 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
90240 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
90241 +sysfs_write_file_57116 sysfs_write_file 3 57116 NULL
90242 +gdth_isa_probe_one_48925 gdth_isa_probe_one 1 48925 NULL
90243 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
90244 +nfc_hci_execute_cmd_async_65314 nfc_hci_execute_cmd_async 5 65314 NULL
90245 +msnd_fifo_alloc_23179 msnd_fifo_alloc 2 23179 NULL
90246 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
90247 +nfcwilink_skb_alloc_16167 nfcwilink_skb_alloc 1 16167 NULL
90248 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
90249 +remap_pci_mem_15966 remap_pci_mem 1-2 15966 NULL
90250 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
90251 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
90252 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
90253 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
90254 +card_send_command_40757 card_send_command 3 40757 NULL
90255 +sys_mbind_7990 sys_mbind 5 7990 NULL
90256 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
90257 +pg_write_40766 pg_write 3 40766 NULL
90258 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
90259 +uea_idma_write_64139 uea_idma_write 3 64139 NULL
90260 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
90261 +carl9170_rx_stream_1334 carl9170_rx_stream 3 1334 NULL
90262 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
90263 +ath_descdma_setup_12257 ath_descdma_setup 5 12257 NULL
90264 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
90265 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
90266 +batadv_orig_hash_del_if_48972 batadv_orig_hash_del_if 2 48972 NULL
90267 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
90268 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 NULL nohasharray
90269 +getxattr_24398 getxattr 4 24398 &pvr2_v4l2_ioctl_24398
90270 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
90271 +vcs_read_8017 vcs_read 3 8017 NULL
90272 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
90273 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
90274 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
90275 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
90276 +_alloc_set_attr_list_48991 _alloc_set_attr_list 4 48991 NULL
90277 +sys_set_mempolicy_32608 sys_set_mempolicy 3 32608 NULL
90278 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
90279 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
90280 +copy_and_check_19089 copy_and_check 3 19089 NULL
90281 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
90282 +netdev_alloc_skb_ip_align_40811 netdev_alloc_skb_ip_align 2 40811 NULL
90283 +i915_wedged_read_35474 i915_wedged_read 3 35474 NULL
90284 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
90285 +iser_rcv_completion_8048 iser_rcv_completion 2 8048 NULL
90286 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
90287 +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
90288 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
90289 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
90290 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
90291 +smk_user_access_24440 smk_user_access 3 24440 NULL
90292 +xd_rw_49020 xd_rw 3-4 49020 NULL
90293 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
90294 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
90295 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
90296 +kvmalloc_32646 kvmalloc 1 32646 NULL
90297 +alloc_targets_8074 alloc_targets 2 8074 NULL nohasharray
90298 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 &alloc_targets_8074
90299 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
90300 +drm_calloc_large_65421 drm_calloc_large 1-2 65421 NULL
90301 +set_disc_pfs_16270 set_disc_pfs 3 16270 NULL
90302 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
90303 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
90304 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL
90305 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 NULL nohasharray
90306 +nand_bch_init_16280 nand_bch_init 3-2 16280 &drbd_setsockopt_16280
90307 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
90308 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
90309 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
90310 +pn533_init_target_frame_65438 pn533_init_target_frame 3 65438 NULL
90311 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
90312 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
90313 +i915_wedged_write_47771 i915_wedged_write 3 47771 NULL
90314 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
90315 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
90316 +l2cap_bredr_sig_cmd_49065 l2cap_bredr_sig_cmd 3 49065 NULL
90317 +tipc_buf_acquire_60437 tipc_buf_acquire 1 60437 NULL
90318 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
90319 +venus_lookup_8121 venus_lookup 4 8121 NULL
90320 +compat_writev_60063 compat_writev 3 60063 NULL
90321 +io_mapping_create_wc_1354 io_mapping_create_wc 1-2 1354 NULL
90322 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
90323 +read_file_queue_40895 read_file_queue 3 40895 NULL
90324 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
90325 +waiters_read_40902 waiters_read 3 40902 NULL
90326 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
90327 +vmalloc_node_58700 vmalloc_node 1 58700 NULL
90328 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
90329 +ath_rx_edma_init_65483 ath_rx_edma_init 2 65483 NULL
90330 +vmw_cursor_update_image_16332 vmw_cursor_update_image 3-4 16332 NULL
90331 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
90332 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
90333 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
90334 +named_prepare_buf_24532 named_prepare_buf 2 24532 NULL
90335 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
90336 +alloc_dr_65495 alloc_dr 2 65495 NULL
90337 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
90338 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
90339 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
90340 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
90341 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
90342 +rbd_add_16366 rbd_add 3 16366 NULL
90343 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
90344 +pt_read_49136 pt_read 3 49136 NULL
90345 +tsi148_alloc_resource_24563 tsi148_alloc_resource 2 24563 NULL
90346 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
90347 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
90348 +check_mirror_57342 check_mirror 1-2 57342 NULL nohasharray
90349 +usblp_read_57342 usblp_read 3 57342 &check_mirror_57342
90350 +atyfb_setup_generic_49151 atyfb_setup_generic 3 49151 NULL
90351 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
90352 new file mode 100644
90353 index 0000000..d52f2ee
90354 --- /dev/null
90355 +++ b/tools/gcc/size_overflow_plugin.c
90356 @@ -0,0 +1,1941 @@
90357 +/*
90358 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
90359 + * Licensed under the GPL v2, or (at your option) v3
90360 + *
90361 + * Homepage:
90362 + * http://www.grsecurity.net/~ephox/overflow_plugin/
90363 + *
90364 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
90365 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
90366 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
90367 + *
90368 + * Usage:
90369 + * $ 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
90370 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
90371 + */
90372 +
90373 +#include "gcc-plugin.h"
90374 +#include "config.h"
90375 +#include "system.h"
90376 +#include "coretypes.h"
90377 +#include "tree.h"
90378 +#include "tree-pass.h"
90379 +#include "intl.h"
90380 +#include "plugin-version.h"
90381 +#include "tm.h"
90382 +#include "toplev.h"
90383 +#include "function.h"
90384 +#include "tree-flow.h"
90385 +#include "plugin.h"
90386 +#include "gimple.h"
90387 +#include "c-common.h"
90388 +#include "diagnostic.h"
90389 +#include "cfgloop.h"
90390 +
90391 +#if BUILDING_GCC_VERSION >= 4007
90392 +#include "c-tree.h"
90393 +#else
90394 +#define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2 (EXP)
90395 +#endif
90396 +
90397 +#if BUILDING_GCC_VERSION >= 4008
90398 +#define TODO_dump_func 0
90399 +#endif
90400 +
90401 +struct size_overflow_hash {
90402 + const struct size_overflow_hash * const next;
90403 + const char * const name;
90404 + const unsigned int param;
90405 +};
90406 +
90407 +#include "size_overflow_hash.h"
90408 +
90409 +enum marked {
90410 + MARKED_NO, MARKED_YES, MARKED_NOT_INTENTIONAL
90411 +};
90412 +
90413 +static unsigned int call_count = 0;
90414 +
90415 +#define __unused __attribute__((__unused__))
90416 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
90417 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
90418 +#define BEFORE_STMT true
90419 +#define AFTER_STMT false
90420 +#define CREATE_NEW_VAR NULL_TREE
90421 +#define CODES_LIMIT 32
90422 +#define MAX_PARAM 32
90423 +#define MY_STMT GF_PLF_1
90424 +#define NO_CAST_CHECK GF_PLF_2
90425 +
90426 +#if BUILDING_GCC_VERSION == 4005
90427 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
90428 +#endif
90429 +
90430 +int plugin_is_GPL_compatible;
90431 +void debug_gimple_stmt(gimple gs);
90432 +
90433 +static tree expand(struct pointer_set_t *visited, tree lhs);
90434 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs);
90435 +static tree report_size_overflow_decl;
90436 +static const_tree const_char_ptr_type_node;
90437 +static unsigned int handle_function(void);
90438 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
90439 +static tree get_size_overflow_type(gimple stmt, const_tree node);
90440 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
90441 +
90442 +static struct plugin_info size_overflow_plugin_info = {
90443 + .version = "20130109beta",
90444 + .help = "no-size-overflow\tturn off size overflow checking\n",
90445 +};
90446 +
90447 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
90448 +{
90449 + unsigned int arg_count;
90450 + enum tree_code code = TREE_CODE(*node);
90451 +
90452 + switch (code) {
90453 + case FUNCTION_DECL:
90454 + arg_count = type_num_arguments(TREE_TYPE(*node));
90455 + break;
90456 + case FUNCTION_TYPE:
90457 + case METHOD_TYPE:
90458 + arg_count = type_num_arguments(*node);
90459 + break;
90460 + default:
90461 + *no_add_attrs = true;
90462 + error("%s: %qE attribute only applies to functions", __func__, name);
90463 + return NULL_TREE;
90464 + }
90465 +
90466 + for (; args; args = TREE_CHAIN(args)) {
90467 + tree position = TREE_VALUE(args);
90468 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
90469 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
90470 + *no_add_attrs = true;
90471 + }
90472 + }
90473 + return NULL_TREE;
90474 +}
90475 +
90476 +static const char* get_asm_name(tree node)
90477 +{
90478 + return IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(node));
90479 +}
90480 +
90481 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
90482 +{
90483 + unsigned int arg_count, arg_num;
90484 + enum tree_code code = TREE_CODE(*node);
90485 +
90486 + switch (code) {
90487 + case FUNCTION_DECL:
90488 + arg_count = type_num_arguments(TREE_TYPE(*node));
90489 + break;
90490 + case FUNCTION_TYPE:
90491 + case METHOD_TYPE:
90492 + arg_count = type_num_arguments(*node);
90493 + break;
90494 + case FIELD_DECL:
90495 + arg_num = TREE_INT_CST_LOW(TREE_VALUE(args));
90496 + if (arg_num != 0) {
90497 + *no_add_attrs = true;
90498 + error("%s: %qE attribute parameter can only be 0 in structure fields", __func__, name);
90499 + }
90500 + return NULL_TREE;
90501 + default:
90502 + *no_add_attrs = true;
90503 + error("%qE attribute only applies to functions", name);
90504 + return NULL_TREE;
90505 + }
90506 +
90507 + for (; args; args = TREE_CHAIN(args)) {
90508 + tree position = TREE_VALUE(args);
90509 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) > arg_count ) {
90510 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
90511 + *no_add_attrs = true;
90512 + }
90513 + }
90514 + return NULL_TREE;
90515 +}
90516 +
90517 +static struct attribute_spec size_overflow_attr = {
90518 + .name = "size_overflow",
90519 + .min_length = 1,
90520 + .max_length = -1,
90521 + .decl_required = true,
90522 + .type_required = false,
90523 + .function_type_required = false,
90524 + .handler = handle_size_overflow_attribute,
90525 +#if BUILDING_GCC_VERSION >= 4007
90526 + .affects_type_identity = false
90527 +#endif
90528 +};
90529 +
90530 +static struct attribute_spec intentional_overflow_attr = {
90531 + .name = "intentional_overflow",
90532 + .min_length = 1,
90533 + .max_length = -1,
90534 + .decl_required = true,
90535 + .type_required = false,
90536 + .function_type_required = false,
90537 + .handler = handle_intentional_overflow_attribute,
90538 +#if BUILDING_GCC_VERSION >= 4007
90539 + .affects_type_identity = false
90540 +#endif
90541 +};
90542 +
90543 +static void register_attributes(void __unused *event_data, void __unused *data)
90544 +{
90545 + register_attribute(&size_overflow_attr);
90546 + register_attribute(&intentional_overflow_attr);
90547 +}
90548 +
90549 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
90550 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
90551 +{
90552 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
90553 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
90554 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
90555 +
90556 + unsigned int m = 0x57559429;
90557 + unsigned int n = 0x5052acdb;
90558 + const unsigned int *key4 = (const unsigned int *)key;
90559 + unsigned int h = len;
90560 + unsigned int k = len + seed + n;
90561 + unsigned long long p;
90562 +
90563 + while (len >= 8) {
90564 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
90565 + len -= 8;
90566 + }
90567 + if (len >= 4) {
90568 + cwmixb(key4[0]) key4 += 1;
90569 + len -= 4;
90570 + }
90571 + if (len)
90572 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
90573 + cwmixb(h ^ (k + n));
90574 + return k ^ h;
90575 +
90576 +#undef cwfold
90577 +#undef cwmixa
90578 +#undef cwmixb
90579 +}
90580 +
90581 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
90582 +{
90583 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
90584 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
90585 + return fn ^ codes;
90586 +}
90587 +
90588 +static inline tree get_original_function_decl(tree fndecl)
90589 +{
90590 + if (DECL_ABSTRACT_ORIGIN(fndecl))
90591 + return DECL_ABSTRACT_ORIGIN(fndecl);
90592 + return fndecl;
90593 +}
90594 +
90595 +static inline gimple get_def_stmt(const_tree node)
90596 +{
90597 + gcc_assert(node != NULL_TREE);
90598 + gcc_assert(TREE_CODE(node) == SSA_NAME);
90599 + return SSA_NAME_DEF_STMT(node);
90600 +}
90601 +
90602 +static unsigned char get_tree_code(const_tree type)
90603 +{
90604 + switch (TREE_CODE(type)) {
90605 + case ARRAY_TYPE:
90606 + return 0;
90607 + case BOOLEAN_TYPE:
90608 + return 1;
90609 + case ENUMERAL_TYPE:
90610 + return 2;
90611 + case FUNCTION_TYPE:
90612 + return 3;
90613 + case INTEGER_TYPE:
90614 + return 4;
90615 + case POINTER_TYPE:
90616 + return 5;
90617 + case RECORD_TYPE:
90618 + return 6;
90619 + case UNION_TYPE:
90620 + return 7;
90621 + case VOID_TYPE:
90622 + return 8;
90623 + case REAL_TYPE:
90624 + return 9;
90625 + case VECTOR_TYPE:
90626 + return 10;
90627 + case REFERENCE_TYPE:
90628 + return 11;
90629 + case OFFSET_TYPE:
90630 + return 12;
90631 + case COMPLEX_TYPE:
90632 + return 13;
90633 + default:
90634 + debug_tree((tree)type);
90635 + gcc_unreachable();
90636 + }
90637 +}
90638 +
90639 +static size_t add_type_codes(const_tree type, unsigned char *tree_codes, size_t len)
90640 +{
90641 + gcc_assert(type != NULL_TREE);
90642 +
90643 + while (type && len < CODES_LIMIT) {
90644 + tree_codes[len] = get_tree_code(type);
90645 + len++;
90646 + type = TREE_TYPE(type);
90647 + }
90648 + return len;
90649 +}
90650 +
90651 +static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
90652 +{
90653 + const_tree arg, result, arg_field, type = TREE_TYPE(fndecl);
90654 + enum tree_code code = TREE_CODE(type);
90655 + size_t len = 0;
90656 +
90657 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
90658 +
90659 + arg = TYPE_ARG_TYPES(type);
90660 + // skip builtins __builtin_constant_p
90661 + if (!arg && DECL_BUILT_IN(fndecl))
90662 + return 0;
90663 +
90664 + if (TREE_CODE_CLASS(code) == tcc_type)
90665 + result = type;
90666 + else
90667 + result = DECL_RESULT(fndecl);
90668 +
90669 + gcc_assert(result != NULL_TREE);
90670 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
90671 +
90672 + if (arg == NULL_TREE) {
90673 + gcc_assert(CODE_CONTAINS_STRUCT(TREE_CODE(fndecl), TS_DECL_NON_COMMON));
90674 + arg_field = DECL_ARGUMENT_FLD(fndecl);
90675 + if (arg_field == NULL_TREE)
90676 + return 0;
90677 + arg = TREE_TYPE(arg_field);
90678 + len = add_type_codes(arg, tree_codes, len);
90679 + gcc_assert(len != 0);
90680 + return len;
90681 + }
90682 +
90683 + gcc_assert(arg != NULL_TREE && TREE_CODE(arg) == TREE_LIST);
90684 + while (arg && len < CODES_LIMIT) {
90685 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
90686 + arg = TREE_CHAIN(arg);
90687 + }
90688 +
90689 + gcc_assert(len != 0);
90690 + return len;
90691 +}
90692 +
90693 +static const struct size_overflow_hash *get_function_hash(tree fndecl)
90694 +{
90695 + unsigned int hash;
90696 + const struct size_overflow_hash *entry;
90697 + unsigned char tree_codes[CODES_LIMIT];
90698 + size_t len;
90699 + const char *func_name = get_asm_name(fndecl);
90700 +
90701 + len = get_function_decl(fndecl, tree_codes);
90702 + if (len == 0)
90703 + return NULL;
90704 +
90705 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
90706 +
90707 + entry = size_overflow_hash[hash];
90708 + while (entry) {
90709 + if (!strcmp(entry->name, func_name))
90710 + return entry;
90711 + entry = entry->next;
90712 + }
90713 +
90714 + return NULL;
90715 +}
90716 +
90717 +static void check_arg_type(const_tree arg)
90718 +{
90719 + const_tree type = TREE_TYPE(arg);
90720 + enum tree_code code = TREE_CODE(type);
90721 +
90722 + if (code == BOOLEAN_TYPE)
90723 + return;
90724 +
90725 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
90726 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
90727 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
90728 +}
90729 +
90730 +static unsigned int find_arg_number(const_tree arg, tree func)
90731 +{
90732 + tree var;
90733 + unsigned int argnum = 1;
90734 +
90735 + if (TREE_CODE(arg) == SSA_NAME)
90736 + arg = SSA_NAME_VAR(arg);
90737 +
90738 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
90739 + if (strcmp(NAME(arg), NAME(var))) {
90740 + argnum++;
90741 + continue;
90742 + }
90743 + check_arg_type(var);
90744 + return argnum;
90745 + }
90746 + gcc_unreachable();
90747 +}
90748 +
90749 +static tree create_new_var(tree type)
90750 +{
90751 + tree new_var = create_tmp_var(type, "cicus");
90752 +
90753 +#if BUILDING_GCC_VERSION <= 4007
90754 + add_referenced_var(new_var);
90755 + mark_sym_for_renaming(new_var);
90756 +#endif
90757 + return new_var;
90758 +}
90759 +
90760 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
90761 +{
90762 + gimple assign;
90763 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
90764 + tree type = TREE_TYPE(rhs1);
90765 + tree lhs = create_new_var(type);
90766 +
90767 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
90768 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
90769 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
90770 +
90771 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
90772 + update_stmt(assign);
90773 + gimple_set_plf(assign, MY_STMT, true);
90774 + return assign;
90775 +}
90776 +
90777 +static bool is_bool(const_tree node)
90778 +{
90779 + const_tree type;
90780 +
90781 + if (node == NULL_TREE)
90782 + return false;
90783 +
90784 + type = TREE_TYPE(node);
90785 + if (!INTEGRAL_TYPE_P(type))
90786 + return false;
90787 + if (TREE_CODE(type) == BOOLEAN_TYPE)
90788 + return true;
90789 + if (TYPE_PRECISION(type) == 1)
90790 + return true;
90791 + return false;
90792 +}
90793 +
90794 +static tree cast_a_tree(tree type, tree var)
90795 +{
90796 + gcc_assert(type != NULL_TREE);
90797 + gcc_assert(var != NULL_TREE);
90798 + gcc_assert(fold_convertible_p(type, var));
90799 +
90800 + return fold_convert(type, var);
90801 +}
90802 +
90803 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
90804 +{
90805 + gimple assign;
90806 +
90807 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
90808 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
90809 + gcc_unreachable();
90810 +
90811 + if (lhs == CREATE_NEW_VAR)
90812 + lhs = create_new_var(dst_type);
90813 +
90814 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
90815 +
90816 + if (!gsi_end_p(*gsi)) {
90817 + location_t loc = gimple_location(gsi_stmt(*gsi));
90818 + gimple_set_location(assign, loc);
90819 + }
90820 +
90821 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
90822 +
90823 + if (before)
90824 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
90825 + else
90826 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
90827 + update_stmt(assign);
90828 + gimple_set_plf(assign, MY_STMT, true);
90829 +
90830 + return assign;
90831 +}
90832 +
90833 +static tree cast_to_new_size_overflow_type(gimple stmt, tree rhs, tree size_overflow_type, bool before)
90834 +{
90835 + gimple assign;
90836 + gimple_stmt_iterator gsi;
90837 +
90838 + if (rhs == NULL_TREE)
90839 + return NULL_TREE;
90840 +
90841 + if (types_compatible_p(TREE_TYPE(rhs), size_overflow_type) && gimple_plf(stmt, MY_STMT))
90842 + return rhs;
90843 +
90844 + gsi = gsi_for_stmt(stmt);
90845 + assign = build_cast_stmt(size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before);
90846 + gimple_set_plf(assign, MY_STMT, true);
90847 + return gimple_get_lhs(assign);
90848 +}
90849 +
90850 +static tree cast_to_TI_type(gimple stmt, tree node)
90851 +{
90852 + gimple_stmt_iterator gsi;
90853 + gimple cast_stmt;
90854 + tree type = TREE_TYPE(node);
90855 +
90856 + if (types_compatible_p(type, intTI_type_node))
90857 + return node;
90858 +
90859 + gsi = gsi_for_stmt(stmt);
90860 + cast_stmt = build_cast_stmt(intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
90861 + gimple_set_plf(cast_stmt, MY_STMT, true);
90862 + return gimple_get_lhs(cast_stmt);
90863 +}
90864 +
90865 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
90866 +{
90867 + tree lhs;
90868 + gimple_stmt_iterator gsi;
90869 +
90870 + if (rhs1 == NULL_TREE) {
90871 + debug_gimple_stmt(oldstmt);
90872 + error("%s: rhs1 is NULL_TREE", __func__);
90873 + gcc_unreachable();
90874 + }
90875 +
90876 + switch (gimple_code(oldstmt)) {
90877 + case GIMPLE_ASM:
90878 + lhs = rhs1;
90879 + break;
90880 + case GIMPLE_CALL:
90881 + lhs = gimple_call_lhs(oldstmt);
90882 + break;
90883 + case GIMPLE_ASSIGN:
90884 + lhs = gimple_get_lhs(oldstmt);
90885 + break;
90886 + default:
90887 + debug_gimple_stmt(oldstmt);
90888 + gcc_unreachable();
90889 + }
90890 +
90891 + gsi = gsi_for_stmt(oldstmt);
90892 + pointer_set_insert(visited, oldstmt);
90893 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
90894 + basic_block next_bb, cur_bb;
90895 + const_edge e;
90896 +
90897 + gcc_assert(before == false);
90898 + gcc_assert(stmt_can_throw_internal(oldstmt));
90899 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
90900 + gcc_assert(!gsi_end_p(gsi));
90901 +
90902 + cur_bb = gimple_bb(oldstmt);
90903 + next_bb = cur_bb->next_bb;
90904 + e = find_edge(cur_bb, next_bb);
90905 + gcc_assert(e != NULL);
90906 + gcc_assert(e->flags & EDGE_FALLTHRU);
90907 +
90908 + gsi = gsi_after_labels(next_bb);
90909 + gcc_assert(!gsi_end_p(gsi));
90910 +
90911 + before = true;
90912 + oldstmt = gsi_stmt(gsi);
90913 + }
90914 +
90915 + return cast_to_new_size_overflow_type(oldstmt, rhs1, get_size_overflow_type(oldstmt, lhs), before);
90916 +}
90917 +
90918 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
90919 +{
90920 + gimple stmt;
90921 + gimple_stmt_iterator gsi;
90922 + tree size_overflow_type, new_var, lhs = gimple_get_lhs(oldstmt);
90923 +
90924 + if (gimple_plf(oldstmt, MY_STMT))
90925 + return lhs;
90926 +
90927 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
90928 + rhs1 = gimple_assign_rhs1(oldstmt);
90929 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
90930 + }
90931 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
90932 + rhs2 = gimple_assign_rhs2(oldstmt);
90933 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
90934 + }
90935 +
90936 + stmt = gimple_copy(oldstmt);
90937 + gimple_set_location(stmt, gimple_location(oldstmt));
90938 + gimple_set_plf(stmt, MY_STMT, true);
90939 +
90940 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
90941 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
90942 +
90943 + size_overflow_type = get_size_overflow_type(oldstmt, node);
90944 +
90945 + if (is_bool(lhs))
90946 + new_var = SSA_NAME_VAR(lhs);
90947 + else
90948 + new_var = create_new_var(size_overflow_type);
90949 + new_var = make_ssa_name(new_var, stmt);
90950 + gimple_set_lhs(stmt, new_var);
90951 +
90952 + if (rhs1 != NULL_TREE)
90953 + gimple_assign_set_rhs1(stmt, rhs1);
90954 +
90955 + if (rhs2 != NULL_TREE)
90956 + gimple_assign_set_rhs2(stmt, rhs2);
90957 +#if BUILDING_GCC_VERSION >= 4007
90958 + if (rhs3 != NULL_TREE)
90959 + gimple_assign_set_rhs3(stmt, rhs3);
90960 +#endif
90961 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
90962 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
90963 +
90964 + gsi = gsi_for_stmt(oldstmt);
90965 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
90966 + update_stmt(stmt);
90967 + pointer_set_insert(visited, oldstmt);
90968 + return gimple_get_lhs(stmt);
90969 +}
90970 +
90971 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
90972 +{
90973 + basic_block bb;
90974 + gimple phi;
90975 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
90976 + gimple_seq seq;
90977 +
90978 + bb = gsi_bb(gsi);
90979 +
90980 + phi = create_phi_node(result, bb);
90981 + seq = phi_nodes(bb);
90982 + gsi = gsi_last(seq);
90983 + gsi_remove(&gsi, false);
90984 +
90985 + gsi = gsi_for_stmt(oldstmt);
90986 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
90987 + gimple_set_bb(phi, bb);
90988 + gimple_set_plf(phi, MY_STMT, true);
90989 + return phi;
90990 +}
90991 +
90992 +static basic_block create_a_first_bb(void)
90993 +{
90994 + basic_block first_bb;
90995 +
90996 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
90997 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
90998 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
90999 + return first_bb;
91000 +}
91001 +
91002 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
91003 +{
91004 + basic_block bb;
91005 + const_gimple newstmt;
91006 + gimple_stmt_iterator gsi;
91007 + bool before = BEFORE_STMT;
91008 +
91009 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
91010 + gsi = gsi_for_stmt(get_def_stmt(arg));
91011 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
91012 + return gimple_get_lhs(newstmt);
91013 + }
91014 +
91015 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
91016 + gsi = gsi_after_labels(bb);
91017 + if (bb->index == 0) {
91018 + bb = create_a_first_bb();
91019 + gsi = gsi_start_bb(bb);
91020 + }
91021 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
91022 + return gimple_get_lhs(newstmt);
91023 +}
91024 +
91025 +static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
91026 +{
91027 + gimple newstmt;
91028 + gimple_stmt_iterator gsi;
91029 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
91030 + gimple def_newstmt = get_def_stmt(new_rhs);
91031 +
91032 + gsi_insert = gsi_insert_after;
91033 + gsi = gsi_for_stmt(def_newstmt);
91034 +
91035 + switch (gimple_code(get_def_stmt(arg))) {
91036 + case GIMPLE_PHI:
91037 + newstmt = gimple_build_assign(new_var, new_rhs);
91038 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
91039 + gsi_insert = gsi_insert_before;
91040 + break;
91041 + case GIMPLE_ASM:
91042 + case GIMPLE_CALL:
91043 + newstmt = gimple_build_assign(new_var, new_rhs);
91044 + break;
91045 + case GIMPLE_ASSIGN:
91046 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
91047 + break;
91048 + default:
91049 + /* unknown gimple_code (handle_build_new_phi_arg) */
91050 + gcc_unreachable();
91051 + }
91052 +
91053 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
91054 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
91055 + gimple_set_plf(newstmt, MY_STMT, true);
91056 + update_stmt(newstmt);
91057 + return newstmt;
91058 +}
91059 +
91060 +static tree build_new_phi_arg(struct pointer_set_t *visited, tree size_overflow_type, tree arg, tree new_var)
91061 +{
91062 + const_gimple newstmt;
91063 + gimple def_stmt;
91064 + tree new_rhs;
91065 +
91066 + new_rhs = expand(visited, arg);
91067 + if (new_rhs == NULL_TREE)
91068 + return NULL_TREE;
91069 +
91070 + def_stmt = get_def_stmt(new_rhs);
91071 + if (gimple_code(def_stmt) == GIMPLE_NOP)
91072 + return NULL_TREE;
91073 + new_rhs = cast_to_new_size_overflow_type(def_stmt, new_rhs, size_overflow_type, AFTER_STMT);
91074 +
91075 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
91076 + return gimple_get_lhs(newstmt);
91077 +}
91078 +
91079 +static tree build_new_phi(struct pointer_set_t *visited, tree orig_result)
91080 +{
91081 + gimple phi, oldstmt = get_def_stmt(orig_result);
91082 + tree new_result, size_overflow_type;
91083 + unsigned int i;
91084 + unsigned int n = gimple_phi_num_args(oldstmt);
91085 +
91086 + size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
91087 +
91088 + new_result = create_new_var(size_overflow_type);
91089 +
91090 + pointer_set_insert(visited, oldstmt);
91091 + phi = overflow_create_phi_node(oldstmt, new_result);
91092 + for (i = 0; i < n; i++) {
91093 + tree arg, lhs;
91094 +
91095 + arg = gimple_phi_arg_def(oldstmt, i);
91096 + if (is_gimple_constant(arg))
91097 + arg = cast_a_tree(size_overflow_type, arg);
91098 + lhs = build_new_phi_arg(visited, size_overflow_type, arg, new_result);
91099 + if (lhs == NULL_TREE)
91100 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
91101 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
91102 + }
91103 +
91104 + update_stmt(phi);
91105 + return gimple_phi_result(phi);
91106 +}
91107 +
91108 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
91109 +{
91110 + const_gimple assign;
91111 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
91112 + tree origtype = TREE_TYPE(orig_rhs);
91113 +
91114 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
91115 +
91116 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
91117 + return gimple_get_lhs(assign);
91118 +}
91119 +
91120 +static void change_rhs1(gimple stmt, tree new_rhs1)
91121 +{
91122 + tree assign_rhs;
91123 + const_tree rhs = gimple_assign_rhs1(stmt);
91124 +
91125 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
91126 + gimple_assign_set_rhs1(stmt, assign_rhs);
91127 + update_stmt(stmt);
91128 +}
91129 +
91130 +static bool check_mode_type(const_gimple stmt)
91131 +{
91132 + const_tree lhs = gimple_get_lhs(stmt);
91133 + const_tree lhs_type = TREE_TYPE(lhs);
91134 + const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
91135 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
91136 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
91137 +
91138 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
91139 + return false;
91140 +
91141 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
91142 + return false;
91143 +
91144 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast
91145 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
91146 + return false;
91147 +
91148 + return true;
91149 +}
91150 +
91151 +static bool check_undefined_integer_operation(const_gimple stmt)
91152 +{
91153 + const_gimple def_stmt;
91154 + const_tree lhs = gimple_get_lhs(stmt);
91155 + const_tree rhs1 = gimple_assign_rhs1(stmt);
91156 + const_tree rhs1_type = TREE_TYPE(rhs1);
91157 + const_tree lhs_type = TREE_TYPE(lhs);
91158 +
91159 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
91160 + return false;
91161 +
91162 + def_stmt = get_def_stmt(rhs1);
91163 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
91164 + return false;
91165 +
91166 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
91167 + return false;
91168 + return true;
91169 +}
91170 +
91171 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
91172 +{
91173 + const_tree rhs1, lhs, rhs1_type, lhs_type;
91174 + enum machine_mode lhs_mode, rhs_mode;
91175 + gimple def_stmt = get_def_stmt(no_const_rhs);
91176 +
91177 + if (!gimple_assign_cast_p(def_stmt))
91178 + return false;
91179 +
91180 + rhs1 = gimple_assign_rhs1(def_stmt);
91181 + lhs = gimple_get_lhs(def_stmt);
91182 + rhs1_type = TREE_TYPE(rhs1);
91183 + lhs_type = TREE_TYPE(lhs);
91184 + rhs_mode = TYPE_MODE(rhs1_type);
91185 + lhs_mode = TYPE_MODE(lhs_type);
91186 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
91187 + return false;
91188 +
91189 + return true;
91190 +}
91191 +
91192 +static tree create_cast_assign(struct pointer_set_t *visited, gimple stmt)
91193 +{
91194 + tree rhs1 = gimple_assign_rhs1(stmt);
91195 + tree lhs = gimple_get_lhs(stmt);
91196 + const_tree rhs1_type = TREE_TYPE(rhs1);
91197 + const_tree lhs_type = TREE_TYPE(lhs);
91198 +
91199 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
91200 + return create_assign(visited, stmt, lhs, AFTER_STMT);
91201 +
91202 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
91203 +}
91204 +
91205 +static tree handle_unary_rhs(struct pointer_set_t *visited, gimple stmt)
91206 +{
91207 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
91208 + tree new_rhs1 = NULL_TREE;
91209 + tree rhs1 = gimple_assign_rhs1(stmt);
91210 + const_tree rhs1_type = TREE_TYPE(rhs1);
91211 + const_tree lhs_type = TREE_TYPE(lhs);
91212 +
91213 + if (gimple_plf(stmt, MY_STMT))
91214 + return lhs;
91215 +
91216 + if (TREE_CODE(rhs1_type) == POINTER_TYPE)
91217 + return create_assign(visited, stmt, lhs, AFTER_STMT);
91218 +
91219 + new_rhs1 = expand(visited, rhs1);
91220 +
91221 + if (new_rhs1 == NULL_TREE)
91222 + return create_cast_assign(visited, stmt);
91223 +
91224 + if (gimple_plf(stmt, NO_CAST_CHECK))
91225 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
91226 +
91227 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
91228 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
91229 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
91230 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
91231 + return create_assign(visited, stmt, lhs, AFTER_STMT);
91232 + }
91233 +
91234 + if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
91235 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
91236 +
91237 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type))
91238 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
91239 +
91240 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
91241 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
91242 +
91243 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
91244 +
91245 + change_rhs1(stmt, new_rhs1);
91246 +
91247 + if (!check_mode_type(stmt))
91248 + return create_assign(visited, stmt, lhs, AFTER_STMT);
91249 +
91250 + size_overflow_type = get_size_overflow_type(stmt, lhs);
91251 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
91252 +
91253 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, BEFORE_STMT);
91254 +
91255 + return create_assign(visited, stmt, lhs, AFTER_STMT);
91256 +}
91257 +
91258 +static tree handle_unary_ops(struct pointer_set_t *visited, gimple stmt)
91259 +{
91260 + tree rhs1, lhs = gimple_get_lhs(stmt);
91261 + gimple def_stmt = get_def_stmt(lhs);
91262 +
91263 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
91264 + rhs1 = gimple_assign_rhs1(def_stmt);
91265 +
91266 + if (is_gimple_constant(rhs1))
91267 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
91268 +
91269 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
91270 + switch (TREE_CODE(rhs1)) {
91271 + case SSA_NAME:
91272 + return handle_unary_rhs(visited, def_stmt);
91273 + case ARRAY_REF:
91274 + case BIT_FIELD_REF:
91275 + case ADDR_EXPR:
91276 + case COMPONENT_REF:
91277 + case INDIRECT_REF:
91278 +#if BUILDING_GCC_VERSION >= 4006
91279 + case MEM_REF:
91280 +#endif
91281 + case TARGET_MEM_REF:
91282 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
91283 + case PARM_DECL:
91284 + case VAR_DECL:
91285 + return create_assign(visited, stmt, lhs, AFTER_STMT);
91286 +
91287 + default:
91288 + debug_gimple_stmt(def_stmt);
91289 + debug_tree(rhs1);
91290 + gcc_unreachable();
91291 + }
91292 +}
91293 +
91294 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
91295 +{
91296 + gimple cond_stmt;
91297 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
91298 +
91299 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
91300 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
91301 + update_stmt(cond_stmt);
91302 +}
91303 +
91304 +static tree create_string_param(tree string)
91305 +{
91306 + tree i_type, a_type;
91307 + const int length = TREE_STRING_LENGTH(string);
91308 +
91309 + gcc_assert(length > 0);
91310 +
91311 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
91312 + a_type = build_array_type(char_type_node, i_type);
91313 +
91314 + TREE_TYPE(string) = a_type;
91315 + TREE_CONSTANT(string) = 1;
91316 + TREE_READONLY(string) = 1;
91317 +
91318 + return build1(ADDR_EXPR, ptr_type_node, string);
91319 +}
91320 +
91321 +static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
91322 +{
91323 + gimple func_stmt;
91324 + const_gimple def_stmt;
91325 + const_tree loc_line;
91326 + tree loc_file, ssa_name, current_func;
91327 + expanded_location xloc;
91328 + char *ssa_name_buf;
91329 + int len;
91330 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
91331 +
91332 + def_stmt = get_def_stmt(arg);
91333 + xloc = expand_location(gimple_location(def_stmt));
91334 +
91335 + if (!gimple_has_location(def_stmt)) {
91336 + xloc = expand_location(gimple_location(stmt));
91337 + if (!gimple_has_location(stmt))
91338 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
91339 + }
91340 +
91341 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
91342 +
91343 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
91344 + loc_file = create_string_param(loc_file);
91345 +
91346 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
91347 + current_func = create_string_param(current_func);
91348 +
91349 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
91350 + call_count++;
91351 + 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);
91352 + gcc_assert(len > 0);
91353 + ssa_name = build_string(len + 1, ssa_name_buf);
91354 + free(ssa_name_buf);
91355 + ssa_name = create_string_param(ssa_name);
91356 +
91357 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
91358 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
91359 +
91360 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
91361 +}
91362 +
91363 +static void __unused print_the_code_insertions(const_gimple stmt)
91364 +{
91365 + location_t loc = gimple_location(stmt);
91366 +
91367 + inform(loc, "Integer size_overflow check applied here.");
91368 +}
91369 +
91370 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
91371 +{
91372 + basic_block cond_bb, join_bb, bb_true;
91373 + edge e;
91374 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
91375 +
91376 + cond_bb = gimple_bb(stmt);
91377 + if (before)
91378 + gsi_prev(&gsi);
91379 + if (gsi_end_p(gsi))
91380 + e = split_block_after_labels(cond_bb);
91381 + else
91382 + e = split_block(cond_bb, gsi_stmt(gsi));
91383 + cond_bb = e->src;
91384 + join_bb = e->dest;
91385 + e->flags = EDGE_FALSE_VALUE;
91386 + e->probability = REG_BR_PROB_BASE;
91387 +
91388 + bb_true = create_empty_bb(cond_bb);
91389 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
91390 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
91391 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
91392 +
91393 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
91394 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
91395 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
91396 +
91397 + if (current_loops != NULL) {
91398 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
91399 + add_bb_to_loop(bb_true, cond_bb->loop_father);
91400 + }
91401 +
91402 + insert_cond(cond_bb, arg, cond_code, type_value);
91403 + insert_cond_result(bb_true, stmt, arg, min);
91404 +
91405 +// print_the_code_insertions(stmt);
91406 +}
91407 +
91408 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
91409 +{
91410 + const_tree rhs_type = TREE_TYPE(rhs);
91411 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
91412 +
91413 + gcc_assert(rhs_type != NULL_TREE);
91414 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
91415 + return;
91416 +
91417 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
91418 +
91419 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
91420 + // typemax (-1) < typemin (0)
91421 + if (TREE_OVERFLOW(type_max))
91422 + return;
91423 +
91424 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
91425 +
91426 + cast_rhs_type = TREE_TYPE(cast_rhs);
91427 + type_max_type = TREE_TYPE(type_max);
91428 + type_min_type = TREE_TYPE(type_min);
91429 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
91430 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
91431 +
91432 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
91433 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
91434 +}
91435 +
91436 +static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
91437 +{
91438 + gimple change_rhs_def_stmt;
91439 + tree lhs = gimple_get_lhs(def_stmt);
91440 + tree lhs_type = TREE_TYPE(lhs);
91441 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
91442 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
91443 +
91444 + if (change_rhs == NULL_TREE)
91445 + return get_size_overflow_type(def_stmt, lhs);
91446 +
91447 + change_rhs_def_stmt = get_def_stmt(change_rhs);
91448 +
91449 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
91450 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
91451 +
91452 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
91453 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
91454 +
91455 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
91456 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
91457 +
91458 + if (!types_compatible_p(lhs_type, rhs1_type) || !types_compatible_p(rhs1_type, rhs2_type)) {
91459 + debug_gimple_stmt(def_stmt);
91460 + gcc_unreachable();
91461 + }
91462 +
91463 + return get_size_overflow_type(def_stmt, lhs);
91464 +}
91465 +
91466 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
91467 +{
91468 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
91469 + return false;
91470 + if (!is_gimple_constant(rhs))
91471 + return false;
91472 + return true;
91473 +}
91474 +
91475 +static bool is_subtraction_special(const_gimple stmt)
91476 +{
91477 + gimple rhs1_def_stmt, rhs2_def_stmt;
91478 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
91479 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
91480 + const_tree rhs1 = gimple_assign_rhs1(stmt);
91481 + const_tree rhs2 = gimple_assign_rhs2(stmt);
91482 +
91483 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
91484 + return false;
91485 +
91486 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
91487 +
91488 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
91489 + return false;
91490 +
91491 + rhs1_def_stmt = get_def_stmt(rhs1);
91492 + rhs2_def_stmt = get_def_stmt(rhs2);
91493 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
91494 + return false;
91495 +
91496 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
91497 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
91498 + rhs1_def_stmt_lhs = gimple_get_lhs(rhs1_def_stmt);
91499 + rhs2_def_stmt_lhs = gimple_get_lhs(rhs2_def_stmt);
91500 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
91501 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
91502 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
91503 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
91504 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
91505 + return false;
91506 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
91507 + return false;
91508 +
91509 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
91510 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
91511 + return true;
91512 +}
91513 +
91514 +static tree get_def_stmt_rhs(const_tree var)
91515 +{
91516 + tree rhs1, def_stmt_rhs1;
91517 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
91518 +
91519 + def_stmt = get_def_stmt(var);
91520 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && gimple_plf(def_stmt, MY_STMT) && gimple_assign_cast_p(def_stmt));
91521 +
91522 + rhs1 = gimple_assign_rhs1(def_stmt);
91523 + rhs1_def_stmt = get_def_stmt(rhs1);
91524 + if (!gimple_assign_cast_p(rhs1_def_stmt))
91525 + return rhs1;
91526 +
91527 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
91528 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
91529 +
91530 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
91531 + case GIMPLE_CALL:
91532 + case GIMPLE_NOP:
91533 + case GIMPLE_ASM:
91534 + return def_stmt_rhs1;
91535 + case GIMPLE_ASSIGN:
91536 + return rhs1;
91537 + default:
91538 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
91539 + gcc_unreachable();
91540 + }
91541 +}
91542 +
91543 +static tree handle_integer_truncation(struct pointer_set_t *visited, const_tree lhs)
91544 +{
91545 + tree new_rhs1, new_rhs2;
91546 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
91547 + gimple assign, stmt = get_def_stmt(lhs);
91548 + tree rhs1 = gimple_assign_rhs1(stmt);
91549 + tree rhs2 = gimple_assign_rhs2(stmt);
91550 +
91551 + if (!is_subtraction_special(stmt))
91552 + return NULL_TREE;
91553 +
91554 + new_rhs1 = expand(visited, rhs1);
91555 + new_rhs2 = expand(visited, rhs2);
91556 +
91557 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs1);
91558 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs2);
91559 +
91560 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
91561 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs1_def_stmt_rhs1);
91562 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs2_def_stmt_rhs1);
91563 + }
91564 +
91565 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
91566 + new_lhs = gimple_get_lhs(assign);
91567 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
91568 +
91569 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
91570 +}
91571 +
91572 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
91573 +{
91574 + const_gimple def_stmt;
91575 +
91576 + if (TREE_CODE(rhs) != SSA_NAME)
91577 + return false;
91578 +
91579 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
91580 + return false;
91581 +
91582 + def_stmt = get_def_stmt(rhs);
91583 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
91584 + return false;
91585 +
91586 + return true;
91587 +}
91588 +
91589 +static tree handle_intentional_overflow(struct pointer_set_t *visited, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
91590 +{
91591 + tree new_rhs, size_overflow_type, orig_rhs;
91592 + void (*gimple_assign_set_rhs)(gimple, tree);
91593 + tree rhs1 = gimple_assign_rhs1(stmt);
91594 + tree rhs2 = gimple_assign_rhs2(stmt);
91595 + tree lhs = gimple_get_lhs(stmt);
91596 +
91597 + if (change_rhs == NULL_TREE)
91598 + return create_assign(visited, stmt, lhs, AFTER_STMT);
91599 +
91600 + if (new_rhs2 == NULL_TREE) {
91601 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
91602 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
91603 + orig_rhs = rhs1;
91604 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
91605 + } else {
91606 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
91607 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
91608 + orig_rhs = rhs2;
91609 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
91610 + }
91611 +
91612 + change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
91613 +
91614 + if (check_overflow)
91615 + check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, BEFORE_STMT);
91616 +
91617 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
91618 + gimple_assign_set_rhs(stmt, new_rhs);
91619 + update_stmt(stmt);
91620 +
91621 + return create_assign(visited, stmt, lhs, AFTER_STMT);
91622 +}
91623 +
91624 +static tree handle_binary_ops(struct pointer_set_t *visited, tree lhs)
91625 +{
91626 + tree rhs1, rhs2, new_lhs;
91627 + gimple def_stmt = get_def_stmt(lhs);
91628 + tree new_rhs1 = NULL_TREE;
91629 + tree new_rhs2 = NULL_TREE;
91630 +
91631 + rhs1 = gimple_assign_rhs1(def_stmt);
91632 + rhs2 = gimple_assign_rhs2(def_stmt);
91633 +
91634 + /* no DImode/TImode division in the 32/64 bit kernel */
91635 + switch (gimple_assign_rhs_code(def_stmt)) {
91636 + case RDIV_EXPR:
91637 + case TRUNC_DIV_EXPR:
91638 + case CEIL_DIV_EXPR:
91639 + case FLOOR_DIV_EXPR:
91640 + case ROUND_DIV_EXPR:
91641 + case TRUNC_MOD_EXPR:
91642 + case CEIL_MOD_EXPR:
91643 + case FLOOR_MOD_EXPR:
91644 + case ROUND_MOD_EXPR:
91645 + case EXACT_DIV_EXPR:
91646 + case POINTER_PLUS_EXPR:
91647 + case BIT_AND_EXPR:
91648 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
91649 + default:
91650 + break;
91651 + }
91652 +
91653 + new_lhs = handle_integer_truncation(visited, lhs);
91654 + if (new_lhs != NULL_TREE)
91655 + return new_lhs;
91656 +
91657 + if (TREE_CODE(rhs1) == SSA_NAME)
91658 + new_rhs1 = expand(visited, rhs1);
91659 + if (TREE_CODE(rhs2) == SSA_NAME)
91660 + new_rhs2 = expand(visited, rhs2);
91661 +
91662 + if (is_a_neg_overflow(def_stmt, rhs2))
91663 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
91664 + if (is_a_neg_overflow(def_stmt, rhs1))
91665 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
91666 +
91667 + if (is_a_constant_overflow(def_stmt, rhs2))
91668 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
91669 + if (is_a_constant_overflow(def_stmt, rhs1))
91670 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
91671 +
91672 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
91673 +}
91674 +
91675 +#if BUILDING_GCC_VERSION >= 4007
91676 +static tree get_new_rhs(struct pointer_set_t *visited, tree size_overflow_type, tree rhs)
91677 +{
91678 + if (is_gimple_constant(rhs))
91679 + return cast_a_tree(size_overflow_type, rhs);
91680 + if (TREE_CODE(rhs) != SSA_NAME)
91681 + return NULL_TREE;
91682 + return expand(visited, rhs);
91683 +}
91684 +
91685 +static tree handle_ternary_ops(struct pointer_set_t *visited, tree lhs)
91686 +{
91687 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
91688 + gimple def_stmt = get_def_stmt(lhs);
91689 +
91690 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
91691 +
91692 + rhs1 = gimple_assign_rhs1(def_stmt);
91693 + rhs2 = gimple_assign_rhs2(def_stmt);
91694 + rhs3 = gimple_assign_rhs3(def_stmt);
91695 + new_rhs1 = get_new_rhs(visited, size_overflow_type, rhs1);
91696 + new_rhs2 = get_new_rhs(visited, size_overflow_type, rhs2);
91697 + new_rhs3 = get_new_rhs(visited, size_overflow_type, rhs3);
91698 +
91699 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
91700 +}
91701 +#endif
91702 +
91703 +static tree get_size_overflow_type(gimple stmt, const_tree node)
91704 +{
91705 + const_tree type;
91706 + tree new_type;
91707 +
91708 + gcc_assert(node != NULL_TREE);
91709 +
91710 + type = TREE_TYPE(node);
91711 +
91712 + if (gimple_plf(stmt, MY_STMT))
91713 + return TREE_TYPE(node);
91714 +
91715 + switch (TYPE_MODE(type)) {
91716 + case QImode:
91717 + new_type = intHI_type_node;
91718 + break;
91719 + case HImode:
91720 + new_type = intSI_type_node;
91721 + break;
91722 + case SImode:
91723 + new_type = intDI_type_node;
91724 + break;
91725 + case DImode:
91726 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
91727 + new_type = intDI_type_node;
91728 + else
91729 + new_type = intTI_type_node;
91730 + break;
91731 + default:
91732 + debug_tree((tree)node);
91733 + error("%s: unsupported gcc configuration.", __func__);
91734 + gcc_unreachable();
91735 + }
91736 +
91737 + if (TYPE_QUALS(type) != 0)
91738 + return build_qualified_type(new_type, TYPE_QUALS(type));
91739 + return new_type;
91740 +}
91741 +
91742 +static tree expand_visited(gimple def_stmt)
91743 +{
91744 + const_gimple next_stmt;
91745 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
91746 +
91747 + gsi_next(&gsi);
91748 + next_stmt = gsi_stmt(gsi);
91749 +
91750 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
91751 +
91752 + switch (gimple_code(next_stmt)) {
91753 + case GIMPLE_ASSIGN:
91754 + return gimple_get_lhs(next_stmt);
91755 + case GIMPLE_PHI:
91756 + return gimple_phi_result(next_stmt);
91757 + case GIMPLE_CALL:
91758 + return gimple_call_lhs(next_stmt);
91759 + default:
91760 + return NULL_TREE;
91761 + }
91762 +}
91763 +
91764 +static tree expand(struct pointer_set_t *visited, tree lhs)
91765 +{
91766 + gimple def_stmt;
91767 + enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
91768 +
91769 + if (is_gimple_constant(lhs))
91770 + return NULL_TREE;
91771 +
91772 + if (TREE_CODE(lhs) == ADDR_EXPR)
91773 + return NULL_TREE;
91774 +
91775 + if (code == REAL_TYPE)
91776 + return NULL_TREE;
91777 +
91778 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
91779 +
91780 + def_stmt = get_def_stmt(lhs);
91781 +
91782 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
91783 + return NULL_TREE;
91784 +
91785 + if (gimple_plf(def_stmt, MY_STMT))
91786 + return lhs;
91787 +
91788 + if (pointer_set_contains(visited, def_stmt))
91789 + return expand_visited(def_stmt);
91790 +
91791 + switch (gimple_code(def_stmt)) {
91792 + case GIMPLE_PHI:
91793 + return build_new_phi(visited, lhs);
91794 + case GIMPLE_CALL:
91795 + case GIMPLE_ASM:
91796 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
91797 + case GIMPLE_ASSIGN:
91798 + switch (gimple_num_ops(def_stmt)) {
91799 + case 2:
91800 + return handle_unary_ops(visited, def_stmt);
91801 + case 3:
91802 + return handle_binary_ops(visited, lhs);
91803 +#if BUILDING_GCC_VERSION >= 4007
91804 + case 4:
91805 + return handle_ternary_ops(visited, lhs);
91806 +#endif
91807 + }
91808 + default:
91809 + debug_gimple_stmt(def_stmt);
91810 + error("%s: unknown gimple code", __func__);
91811 + gcc_unreachable();
91812 + }
91813 +}
91814 +
91815 +static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
91816 +{
91817 + const_gimple assign;
91818 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
91819 + tree origtype = TREE_TYPE(origarg);
91820 +
91821 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
91822 +
91823 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
91824 +
91825 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
91826 + update_stmt(stmt);
91827 +}
91828 +
91829 +static bool get_function_arg(unsigned int* argnum, const_tree fndecl)
91830 +{
91831 + const char *origid;
91832 + tree arg;
91833 + const_tree origarg;
91834 +
91835 + if (!DECL_ABSTRACT_ORIGIN(fndecl))
91836 + return true;
91837 +
91838 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
91839 + while (origarg && *argnum) {
91840 + (*argnum)--;
91841 + origarg = TREE_CHAIN(origarg);
91842 + }
91843 +
91844 + gcc_assert(*argnum == 0);
91845 +
91846 + gcc_assert(origarg != NULL_TREE);
91847 + origid = NAME(origarg);
91848 + *argnum = 0;
91849 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
91850 + if (!strcmp(origid, NAME(arg)))
91851 + return true;
91852 + (*argnum)++;
91853 + }
91854 + return false;
91855 +}
91856 +
91857 +static bool skip_types(const_tree var)
91858 +{
91859 + const_tree type;
91860 +
91861 + switch (TREE_CODE(var)) {
91862 + case ADDR_EXPR:
91863 +#if BUILDING_GCC_VERSION >= 4006
91864 + case MEM_REF:
91865 +#endif
91866 + case ARRAY_REF:
91867 + case BIT_FIELD_REF:
91868 + case INDIRECT_REF:
91869 + case TARGET_MEM_REF:
91870 + case VAR_DECL:
91871 + return true;
91872 + default:
91873 + break;
91874 + }
91875 +
91876 + type = TREE_TYPE(TREE_TYPE(var));
91877 + if (!type)
91878 + return false;
91879 + switch (TREE_CODE(type)) {
91880 + case RECORD_TYPE:
91881 + return true;
91882 + default:
91883 + break;
91884 + }
91885 +
91886 + return false;
91887 +}
91888 +
91889 +static bool walk_phi(struct pointer_set_t *visited, const_tree result)
91890 +{
91891 + gimple phi = get_def_stmt(result);
91892 + unsigned int i, n = gimple_phi_num_args(phi);
91893 +
91894 + if (!phi)
91895 + return false;
91896 +
91897 + pointer_set_insert(visited, phi);
91898 + for (i = 0; i < n; i++) {
91899 + const_tree arg = gimple_phi_arg_def(phi, i);
91900 + if (pre_expand(visited, arg))
91901 + return true;
91902 + }
91903 + return false;
91904 +}
91905 +
91906 +static bool walk_unary_ops(struct pointer_set_t *visited, const_tree lhs)
91907 +{
91908 + gimple def_stmt = get_def_stmt(lhs);
91909 + const_tree rhs;
91910 +
91911 + if (!def_stmt)
91912 + return false;
91913 +
91914 + rhs = gimple_assign_rhs1(def_stmt);
91915 + if (pre_expand(visited, rhs))
91916 + return true;
91917 + return false;
91918 +}
91919 +
91920 +static bool walk_binary_ops(struct pointer_set_t *visited, const_tree lhs)
91921 +{
91922 + bool rhs1_found, rhs2_found;
91923 + gimple def_stmt = get_def_stmt(lhs);
91924 + const_tree rhs1, rhs2;
91925 +
91926 + if (!def_stmt)
91927 + return false;
91928 +
91929 + rhs1 = gimple_assign_rhs1(def_stmt);
91930 + rhs2 = gimple_assign_rhs2(def_stmt);
91931 + rhs1_found = pre_expand(visited, rhs1);
91932 + rhs2_found = pre_expand(visited, rhs2);
91933 +
91934 + return rhs1_found || rhs2_found;
91935 +}
91936 +
91937 +static const_tree search_field_decl(const_tree comp_ref)
91938 +{
91939 + const_tree field = NULL_TREE;
91940 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
91941 +
91942 + for (i = 0; i < len; i++) {
91943 + field = TREE_OPERAND(comp_ref, i);
91944 + if (TREE_CODE(field) == FIELD_DECL)
91945 + break;
91946 + }
91947 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
91948 + return field;
91949 +}
91950 +
91951 +static enum marked mark_status(const_tree fndecl, unsigned int argnum)
91952 +{
91953 + const_tree attr, p;
91954 +
91955 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(fndecl));
91956 + if (!attr || !TREE_VALUE(attr))
91957 + return MARKED_NO;
91958 +
91959 + p = TREE_VALUE(attr);
91960 + if (!TREE_INT_CST_LOW(TREE_VALUE(p)))
91961 + return MARKED_NOT_INTENTIONAL;
91962 +
91963 + do {
91964 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(p)))
91965 + return MARKED_YES;
91966 + p = TREE_CHAIN(p);
91967 + } while (p);
91968 +
91969 + return MARKED_NO;
91970 +}
91971 +
91972 +static void print_missing_msg(tree func, unsigned int argnum)
91973 +{
91974 + unsigned int new_hash;
91975 + size_t len;
91976 + unsigned char tree_codes[CODES_LIMIT];
91977 + location_t loc = DECL_SOURCE_LOCATION(func);
91978 + const char *curfunc = get_asm_name(func);
91979 +
91980 + len = get_function_decl(func, tree_codes);
91981 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
91982 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, new_hash);
91983 +}
91984 +
91985 +static unsigned int search_missing_attribute(const_tree arg)
91986 +{
91987 + const_tree type = TREE_TYPE(arg);
91988 + tree func = get_original_function_decl(current_function_decl);
91989 + unsigned int argnum;
91990 + const struct size_overflow_hash *hash;
91991 +
91992 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
91993 +
91994 + if (TREE_CODE(type) == POINTER_TYPE)
91995 + return 0;
91996 +
91997 + argnum = find_arg_number(arg, func);
91998 + if (argnum == 0)
91999 + return 0;
92000 +
92001 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
92002 + return argnum;
92003 +
92004 + hash = get_function_hash(func);
92005 + if (!hash || !(hash->param & (1U << argnum))) {
92006 + print_missing_msg(func, argnum);
92007 + return 0;
92008 + }
92009 + return argnum;
92010 +}
92011 +
92012 +static bool is_already_marked(const_tree lhs)
92013 +{
92014 + unsigned int argnum;
92015 + const_tree fndecl;
92016 +
92017 + argnum = search_missing_attribute(lhs);
92018 + fndecl = get_original_function_decl(current_function_decl);
92019 + if (argnum && mark_status(fndecl, argnum) == MARKED_YES)
92020 + return true;
92021 + return false;
92022 +}
92023 +
92024 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs)
92025 +{
92026 + const_gimple def_stmt;
92027 +
92028 + if (is_gimple_constant(lhs))
92029 + return false;
92030 +
92031 + if (skip_types(lhs))
92032 + return false;
92033 +
92034 + // skip char type (FIXME: only kernel)
92035 + if (TYPE_MODE(TREE_TYPE(lhs)) == QImode)
92036 + return false;
92037 +
92038 + if (TREE_CODE(lhs) == PARM_DECL)
92039 + return is_already_marked(lhs);
92040 +
92041 + if (TREE_CODE(lhs) == COMPONENT_REF) {
92042 + const_tree field, attr;
92043 +
92044 + field = search_field_decl(lhs);
92045 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(field));
92046 + if (!attr || !TREE_VALUE(attr))
92047 + return false;
92048 + return true;
92049 + }
92050 +
92051 + def_stmt = get_def_stmt(lhs);
92052 +
92053 + if (!def_stmt)
92054 + return false;
92055 +
92056 + if (pointer_set_contains(visited, def_stmt))
92057 + return false;
92058 +
92059 + switch (gimple_code(def_stmt)) {
92060 + case GIMPLE_NOP:
92061 + if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
92062 + return is_already_marked(lhs);
92063 + return false;
92064 + case GIMPLE_PHI:
92065 + return walk_phi(visited, lhs);
92066 + case GIMPLE_CALL:
92067 + case GIMPLE_ASM:
92068 + return false;
92069 + case GIMPLE_ASSIGN:
92070 + switch (gimple_num_ops(def_stmt)) {
92071 + case 2:
92072 + return walk_unary_ops(visited, lhs);
92073 + case 3:
92074 + return walk_binary_ops(visited, lhs);
92075 + }
92076 + default:
92077 + debug_gimple_stmt((gimple)def_stmt);
92078 + error("%s: unknown gimple code", __func__);
92079 + gcc_unreachable();
92080 + }
92081 +}
92082 +
92083 +static bool search_attributes(tree fndecl, const_tree arg, unsigned int argnum)
92084 +{
92085 + struct pointer_set_t *visited;
92086 + bool is_found;
92087 + enum marked is_marked;
92088 + location_t loc;
92089 +
92090 + visited = pointer_set_create();
92091 + is_found = pre_expand(visited, arg);
92092 + pointer_set_destroy(visited);
92093 +
92094 + is_marked = mark_status(fndecl, argnum + 1);
92095 + if ((is_found && is_marked == MARKED_YES) || is_marked == MARKED_NOT_INTENTIONAL)
92096 + return true;
92097 +
92098 + if (is_found) {
92099 + loc = DECL_SOURCE_LOCATION(fndecl);
92100 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", get_asm_name(fndecl), argnum + 1);
92101 + return true;
92102 + }
92103 + return false;
92104 +}
92105 +
92106 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
92107 +{
92108 + struct pointer_set_t *visited;
92109 + tree arg, newarg;
92110 + bool match;
92111 +
92112 + match = get_function_arg(&argnum, fndecl);
92113 + if (!match)
92114 + return;
92115 + gcc_assert(gimple_call_num_args(stmt) > argnum);
92116 + arg = gimple_call_arg(stmt, argnum);
92117 + if (arg == NULL_TREE)
92118 + return;
92119 +
92120 + if (is_gimple_constant(arg))
92121 + return;
92122 +
92123 + if (search_attributes(fndecl, arg, argnum))
92124 + return;
92125 +
92126 + if (TREE_CODE(arg) != SSA_NAME)
92127 + return;
92128 +
92129 + check_arg_type(arg);
92130 +
92131 + visited = pointer_set_create();
92132 + newarg = expand(visited, arg);
92133 + pointer_set_destroy(visited);
92134 +
92135 + if (newarg == NULL_TREE)
92136 + return;
92137 +
92138 + change_function_arg(stmt, arg, argnum, newarg);
92139 +
92140 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, BEFORE_STMT);
92141 +}
92142 +
92143 +static void handle_function_by_attribute(gimple stmt, const_tree attr, tree fndecl)
92144 +{
92145 + tree p = TREE_VALUE(attr);
92146 + do {
92147 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
92148 + p = TREE_CHAIN(p);
92149 + } while (p);
92150 +}
92151 +
92152 +static void handle_function_by_hash(gimple stmt, tree fndecl)
92153 +{
92154 + tree orig_fndecl;
92155 + unsigned int num;
92156 + const struct size_overflow_hash *hash;
92157 +
92158 + orig_fndecl = get_original_function_decl(fndecl);
92159 + if (C_DECL_IMPLICIT(orig_fndecl))
92160 + return;
92161 + hash = get_function_hash(orig_fndecl);
92162 + if (!hash)
92163 + return;
92164 +
92165 + for (num = 1; num <= MAX_PARAM; num++)
92166 + if (hash->param & (1U << num))
92167 + handle_function_arg(stmt, fndecl, num - 1);
92168 +}
92169 +
92170 +static void set_plf_false(void)
92171 +{
92172 + basic_block bb;
92173 +
92174 + FOR_ALL_BB(bb) {
92175 + gimple_stmt_iterator si;
92176 +
92177 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
92178 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
92179 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
92180 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
92181 + }
92182 +}
92183 +
92184 +static unsigned int handle_function(void)
92185 +{
92186 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
92187 +
92188 + set_plf_false();
92189 +
92190 + do {
92191 + gimple_stmt_iterator gsi;
92192 + next = bb->next_bb;
92193 +
92194 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
92195 + tree fndecl, attr;
92196 + gimple stmt = gsi_stmt(gsi);
92197 +
92198 + if (!(is_gimple_call(stmt)))
92199 + continue;
92200 + fndecl = gimple_call_fndecl(stmt);
92201 + if (fndecl == NULL_TREE)
92202 + continue;
92203 + if (gimple_call_num_args(stmt) == 0)
92204 + continue;
92205 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
92206 + if (!attr || !TREE_VALUE(attr))
92207 + handle_function_by_hash(stmt, fndecl);
92208 + else
92209 + handle_function_by_attribute(stmt, attr, fndecl);
92210 + gsi = gsi_for_stmt(stmt);
92211 + next = gimple_bb(stmt)->next_bb;
92212 + }
92213 + bb = next;
92214 + } while (bb);
92215 + return 0;
92216 +}
92217 +
92218 +static struct gimple_opt_pass size_overflow_pass = {
92219 + .pass = {
92220 + .type = GIMPLE_PASS,
92221 + .name = "size_overflow",
92222 +#if BUILDING_GCC_VERSION >= 4008
92223 + .optinfo_flags = OPTGROUP_NONE,
92224 +#endif
92225 + .gate = NULL,
92226 + .execute = handle_function,
92227 + .sub = NULL,
92228 + .next = NULL,
92229 + .static_pass_number = 0,
92230 + .tv_id = TV_NONE,
92231 + .properties_required = PROP_cfg,
92232 + .properties_provided = 0,
92233 + .properties_destroyed = 0,
92234 + .todo_flags_start = 0,
92235 + .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
92236 + }
92237 +};
92238 +
92239 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
92240 +{
92241 + tree fntype;
92242 +
92243 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
92244 +
92245 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
92246 + fntype = build_function_type_list(void_type_node,
92247 + const_char_ptr_type_node,
92248 + unsigned_type_node,
92249 + const_char_ptr_type_node,
92250 + const_char_ptr_type_node,
92251 + NULL_TREE);
92252 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
92253 +
92254 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
92255 + TREE_PUBLIC(report_size_overflow_decl) = 1;
92256 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
92257 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
92258 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
92259 +}
92260 +
92261 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
92262 +{
92263 + int i;
92264 + const char * const plugin_name = plugin_info->base_name;
92265 + const int argc = plugin_info->argc;
92266 + const struct plugin_argument * const argv = plugin_info->argv;
92267 + bool enable = true;
92268 +
92269 + struct register_pass_info size_overflow_pass_info = {
92270 + .pass = &size_overflow_pass.pass,
92271 + .reference_pass_name = "ssa",
92272 + .ref_pass_instance_number = 1,
92273 + .pos_op = PASS_POS_INSERT_AFTER
92274 + };
92275 +
92276 + if (!plugin_default_version_check(version, &gcc_version)) {
92277 + error(G_("incompatible gcc/plugin versions"));
92278 + return 1;
92279 + }
92280 +
92281 + for (i = 0; i < argc; ++i) {
92282 + if (!strcmp(argv[i].key, "no-size-overflow")) {
92283 + enable = false;
92284 + continue;
92285 + }
92286 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
92287 + }
92288 +
92289 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
92290 + if (enable) {
92291 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
92292 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
92293 + }
92294 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
92295 +
92296 + return 0;
92297 +}
92298 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
92299 new file mode 100644
92300 index 0000000..ac2901e
92301 --- /dev/null
92302 +++ b/tools/gcc/stackleak_plugin.c
92303 @@ -0,0 +1,327 @@
92304 +/*
92305 + * Copyright 2011-2013 by the PaX Team <pageexec@freemail.hu>
92306 + * Licensed under the GPL v2
92307 + *
92308 + * Note: the choice of the license means that the compilation process is
92309 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
92310 + * but for the kernel it doesn't matter since it doesn't link against
92311 + * any of the gcc libraries
92312 + *
92313 + * gcc plugin to help implement various PaX features
92314 + *
92315 + * - track lowest stack pointer
92316 + *
92317 + * TODO:
92318 + * - initialize all local variables
92319 + *
92320 + * BUGS:
92321 + * - none known
92322 + */
92323 +#include "gcc-plugin.h"
92324 +#include "config.h"
92325 +#include "system.h"
92326 +#include "coretypes.h"
92327 +#include "tree.h"
92328 +#include "tree-pass.h"
92329 +#include "flags.h"
92330 +#include "intl.h"
92331 +#include "toplev.h"
92332 +#include "plugin.h"
92333 +//#include "expr.h" where are you...
92334 +#include "diagnostic.h"
92335 +#include "plugin-version.h"
92336 +#include "tm.h"
92337 +#include "function.h"
92338 +#include "basic-block.h"
92339 +#include "gimple.h"
92340 +#include "rtl.h"
92341 +#include "emit-rtl.h"
92342 +
92343 +#if BUILDING_GCC_VERSION >= 4008
92344 +#define TODO_dump_func 0
92345 +#endif
92346 +
92347 +extern void print_gimple_stmt(FILE *, gimple, int, int);
92348 +
92349 +int plugin_is_GPL_compatible;
92350 +
92351 +static int track_frame_size = -1;
92352 +static const char track_function[] = "pax_track_stack";
92353 +static const char check_function[] = "pax_check_alloca";
92354 +static bool init_locals;
92355 +
92356 +static struct plugin_info stackleak_plugin_info = {
92357 + .version = "201302112000",
92358 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
92359 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
92360 +};
92361 +
92362 +static bool gate_stackleak_track_stack(void);
92363 +static unsigned int execute_stackleak_tree_instrument(void);
92364 +static unsigned int execute_stackleak_final(void);
92365 +
92366 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
92367 + .pass = {
92368 + .type = GIMPLE_PASS,
92369 + .name = "stackleak_tree_instrument",
92370 +#if BUILDING_GCC_VERSION >= 4008
92371 + .optinfo_flags = OPTGROUP_NONE,
92372 +#endif
92373 + .gate = gate_stackleak_track_stack,
92374 + .execute = execute_stackleak_tree_instrument,
92375 + .sub = NULL,
92376 + .next = NULL,
92377 + .static_pass_number = 0,
92378 + .tv_id = TV_NONE,
92379 + .properties_required = PROP_gimple_leh | PROP_cfg,
92380 + .properties_provided = 0,
92381 + .properties_destroyed = 0,
92382 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
92383 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
92384 + }
92385 +};
92386 +
92387 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
92388 + .pass = {
92389 + .type = RTL_PASS,
92390 + .name = "stackleak_final",
92391 +#if BUILDING_GCC_VERSION >= 4008
92392 + .optinfo_flags = OPTGROUP_NONE,
92393 +#endif
92394 + .gate = gate_stackleak_track_stack,
92395 + .execute = execute_stackleak_final,
92396 + .sub = NULL,
92397 + .next = NULL,
92398 + .static_pass_number = 0,
92399 + .tv_id = TV_NONE,
92400 + .properties_required = 0,
92401 + .properties_provided = 0,
92402 + .properties_destroyed = 0,
92403 + .todo_flags_start = 0,
92404 + .todo_flags_finish = TODO_dump_func
92405 + }
92406 +};
92407 +
92408 +static bool gate_stackleak_track_stack(void)
92409 +{
92410 + return track_frame_size >= 0;
92411 +}
92412 +
92413 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
92414 +{
92415 + gimple check_alloca;
92416 + tree fntype, fndecl, alloca_size;
92417 +
92418 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
92419 + fndecl = build_fn_decl(check_function, fntype);
92420 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
92421 +
92422 + // insert call to void pax_check_alloca(unsigned long size)
92423 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
92424 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
92425 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
92426 +}
92427 +
92428 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
92429 +{
92430 + gimple track_stack;
92431 + tree fntype, fndecl;
92432 +
92433 + fntype = build_function_type_list(void_type_node, NULL_TREE);
92434 + fndecl = build_fn_decl(track_function, fntype);
92435 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
92436 +
92437 + // insert call to void pax_track_stack(void)
92438 + track_stack = gimple_build_call(fndecl, 0);
92439 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
92440 +}
92441 +
92442 +#if BUILDING_GCC_VERSION == 4005
92443 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
92444 +{
92445 + tree fndecl;
92446 +
92447 + if (!is_gimple_call(stmt))
92448 + return false;
92449 + fndecl = gimple_call_fndecl(stmt);
92450 + if (!fndecl)
92451 + return false;
92452 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
92453 + return false;
92454 +// print_node(stderr, "pax", fndecl, 4);
92455 + return DECL_FUNCTION_CODE(fndecl) == code;
92456 +}
92457 +#endif
92458 +
92459 +static bool is_alloca(gimple stmt)
92460 +{
92461 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
92462 + return true;
92463 +
92464 +#if BUILDING_GCC_VERSION >= 4007
92465 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
92466 + return true;
92467 +#endif
92468 +
92469 + return false;
92470 +}
92471 +
92472 +static unsigned int execute_stackleak_tree_instrument(void)
92473 +{
92474 + basic_block bb, entry_bb;
92475 + bool prologue_instrumented = false, is_leaf = true;
92476 +
92477 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
92478 +
92479 + // 1. loop through BBs and GIMPLE statements
92480 + FOR_EACH_BB(bb) {
92481 + gimple_stmt_iterator gsi;
92482 +
92483 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
92484 + gimple stmt;
92485 +
92486 + stmt = gsi_stmt(gsi);
92487 +
92488 + if (is_gimple_call(stmt))
92489 + is_leaf = false;
92490 +
92491 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
92492 + if (!is_alloca(stmt))
92493 + continue;
92494 +
92495 + // 2. insert stack overflow check before each __builtin_alloca call
92496 + stackleak_check_alloca(&gsi);
92497 +
92498 + // 3. insert track call after each __builtin_alloca call
92499 + stackleak_add_instrumentation(&gsi);
92500 + if (bb == entry_bb)
92501 + prologue_instrumented = true;
92502 + }
92503 + }
92504 +
92505 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
92506 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
92507 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
92508 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
92509 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
92510 + return 0;
92511 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
92512 + return 0;
92513 +
92514 + // 4. insert track call at the beginning
92515 + if (!prologue_instrumented) {
92516 + gimple_stmt_iterator gsi;
92517 +
92518 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
92519 + if (dom_info_available_p(CDI_DOMINATORS))
92520 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
92521 + gsi = gsi_start_bb(bb);
92522 + stackleak_add_instrumentation(&gsi);
92523 + }
92524 +
92525 + return 0;
92526 +}
92527 +
92528 +static unsigned int execute_stackleak_final(void)
92529 +{
92530 + rtx insn, next;
92531 +
92532 + if (cfun->calls_alloca)
92533 + return 0;
92534 +
92535 + // keep calls only if function frame is big enough
92536 + if (get_frame_size() >= track_frame_size)
92537 + return 0;
92538 +
92539 + // 1. find pax_track_stack calls
92540 + for (insn = get_insns(); insn; insn = next) {
92541 + // 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))
92542 + rtx body;
92543 +
92544 + next = NEXT_INSN(insn);
92545 + if (!CALL_P(insn))
92546 + continue;
92547 + body = PATTERN(insn);
92548 + if (GET_CODE(body) != CALL)
92549 + continue;
92550 + body = XEXP(body, 0);
92551 + if (GET_CODE(body) != MEM)
92552 + continue;
92553 + body = XEXP(body, 0);
92554 + if (GET_CODE(body) != SYMBOL_REF)
92555 + continue;
92556 + if (strcmp(XSTR(body, 0), track_function))
92557 + continue;
92558 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
92559 + // 2. delete call
92560 + delete_insn_and_edges(insn);
92561 +#if BUILDING_GCC_VERSION >= 4007
92562 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
92563 + insn = next;
92564 + next = NEXT_INSN(insn);
92565 + delete_insn_and_edges(insn);
92566 + }
92567 +#endif
92568 + }
92569 +
92570 +// print_simple_rtl(stderr, get_insns());
92571 +// print_rtl(stderr, get_insns());
92572 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
92573 +
92574 + return 0;
92575 +}
92576 +
92577 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
92578 +{
92579 + const char * const plugin_name = plugin_info->base_name;
92580 + const int argc = plugin_info->argc;
92581 + const struct plugin_argument * const argv = plugin_info->argv;
92582 + int i;
92583 + struct register_pass_info stackleak_tree_instrument_pass_info = {
92584 + .pass = &stackleak_tree_instrument_pass.pass,
92585 +// .reference_pass_name = "tree_profile",
92586 + .reference_pass_name = "optimized",
92587 + .ref_pass_instance_number = 1,
92588 + .pos_op = PASS_POS_INSERT_BEFORE
92589 + };
92590 + struct register_pass_info stackleak_final_pass_info = {
92591 + .pass = &stackleak_final_rtl_opt_pass.pass,
92592 + .reference_pass_name = "final",
92593 + .ref_pass_instance_number = 1,
92594 + .pos_op = PASS_POS_INSERT_BEFORE
92595 + };
92596 +
92597 + if (!plugin_default_version_check(version, &gcc_version)) {
92598 + error(G_("incompatible gcc/plugin versions"));
92599 + return 1;
92600 + }
92601 +
92602 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
92603 +
92604 + for (i = 0; i < argc; ++i) {
92605 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
92606 + if (!argv[i].value) {
92607 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
92608 + continue;
92609 + }
92610 + track_frame_size = atoi(argv[i].value);
92611 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
92612 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
92613 + continue;
92614 + }
92615 + if (!strcmp(argv[i].key, "initialize-locals")) {
92616 + if (argv[i].value) {
92617 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
92618 + continue;
92619 + }
92620 + init_locals = true;
92621 + continue;
92622 + }
92623 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
92624 + }
92625 +
92626 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
92627 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
92628 +
92629 + return 0;
92630 +}
92631 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
92632 index 6789d78..4afd019e 100644
92633 --- a/tools/perf/util/include/asm/alternative-asm.h
92634 +++ b/tools/perf/util/include/asm/alternative-asm.h
92635 @@ -5,4 +5,7 @@
92636
92637 #define altinstruction_entry #
92638
92639 + .macro pax_force_retaddr rip=0, reload=0
92640 + .endm
92641 +
92642 #endif
92643 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
92644 index 6e8fa7e..37f02a5 100644
92645 --- a/virt/kvm/kvm_main.c
92646 +++ b/virt/kvm/kvm_main.c
92647 @@ -75,12 +75,17 @@ LIST_HEAD(vm_list);
92648
92649 static cpumask_var_t cpus_hardware_enabled;
92650 static int kvm_usage_count = 0;
92651 -static atomic_t hardware_enable_failed;
92652 +static atomic_unchecked_t hardware_enable_failed;
92653
92654 struct kmem_cache *kvm_vcpu_cache;
92655 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
92656
92657 -static __read_mostly struct preempt_ops kvm_preempt_ops;
92658 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
92659 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
92660 +static struct preempt_ops kvm_preempt_ops = {
92661 + .sched_in = kvm_sched_in,
92662 + .sched_out = kvm_sched_out,
92663 +};
92664
92665 struct dentry *kvm_debugfs_dir;
92666
92667 @@ -726,7 +731,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
92668 /* We can read the guest memory with __xxx_user() later on. */
92669 if (user_alloc &&
92670 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
92671 - !access_ok(VERIFY_WRITE,
92672 + !__access_ok(VERIFY_WRITE,
92673 (void __user *)(unsigned long)mem->userspace_addr,
92674 mem->memory_size)))
92675 goto out;
92676 @@ -2450,7 +2455,7 @@ static void hardware_enable_nolock(void *junk)
92677
92678 if (r) {
92679 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
92680 - atomic_inc(&hardware_enable_failed);
92681 + atomic_inc_unchecked(&hardware_enable_failed);
92682 printk(KERN_INFO "kvm: enabling virtualization on "
92683 "CPU%d failed\n", cpu);
92684 }
92685 @@ -2504,10 +2509,10 @@ static int hardware_enable_all(void)
92686
92687 kvm_usage_count++;
92688 if (kvm_usage_count == 1) {
92689 - atomic_set(&hardware_enable_failed, 0);
92690 + atomic_set_unchecked(&hardware_enable_failed, 0);
92691 on_each_cpu(hardware_enable_nolock, NULL, 1);
92692
92693 - if (atomic_read(&hardware_enable_failed)) {
92694 + if (atomic_read_unchecked(&hardware_enable_failed)) {
92695 hardware_disable_all_nolock();
92696 r = -EBUSY;
92697 }
92698 @@ -2865,7 +2870,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
92699 kvm_arch_vcpu_put(vcpu);
92700 }
92701
92702 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
92703 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
92704 struct module *module)
92705 {
92706 int r;
92707 @@ -2901,7 +2906,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
92708 if (!vcpu_align)
92709 vcpu_align = __alignof__(struct kvm_vcpu);
92710 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
92711 - 0, NULL);
92712 + SLAB_USERCOPY, NULL);
92713 if (!kvm_vcpu_cache) {
92714 r = -ENOMEM;
92715 goto out_free_3;
92716 @@ -2911,9 +2916,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
92717 if (r)
92718 goto out_free;
92719
92720 - kvm_chardev_ops.owner = module;
92721 - kvm_vm_fops.owner = module;
92722 - kvm_vcpu_fops.owner = module;
92723 + pax_open_kernel();
92724 + *(void **)&kvm_chardev_ops.owner = module;
92725 + *(void **)&kvm_vm_fops.owner = module;
92726 + *(void **)&kvm_vcpu_fops.owner = module;
92727 + pax_close_kernel();
92728
92729 r = misc_register(&kvm_dev);
92730 if (r) {
92731 @@ -2923,9 +2930,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
92732
92733 register_syscore_ops(&kvm_syscore_ops);
92734
92735 - kvm_preempt_ops.sched_in = kvm_sched_in;
92736 - kvm_preempt_ops.sched_out = kvm_sched_out;
92737 -
92738 r = kvm_init_debug();
92739 if (r) {
92740 printk(KERN_ERR "kvm: create debugfs files failed\n");